8000 Abci refactor by brennanjl · Pull Request #163 · trufnetwork/kwil-db · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Abci refactor #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

cmtCrypto "github.com/cometbft/cometbft/crypto"
cmtjson "github.com/cometbft/cometbft/libs/json"
"github.com/kwilteam/kwil-db/internal/entity"
)

type ValidatorsInfo struct {
Expand Down
33 changes: 6 additions & 27 deletions internal/app/kwild/cmd/server/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/kwilteam/kwil-db/internal/controller/grpc/healthsvc/v0"
"github.com/kwilteam/kwil-db/internal/controller/grpc/txsvc/v1"

"github.com/kwilteam/kwil-db/pkg/sql"

"google.golang.org/grpc/health/grpc_health_v1"

abci "github.com/cometbft/cometbft/abci/types"
Expand All @@ -41,10 +43,6 @@ import (
"github.com/kwilteam/kwil-db/internal/pkg/healthcheck"
simple_checker "github.com/kwilteam/kwil-db/internal/pkg/healthcheck/simple-checker"
grpcServer "github.com/kwilteam/kwil-db/pkg/grpc/server"

chainClient "github.com/kwilteam/kwil-db/pkg/chain/client"
ccService "github.com/kwilteam/kwil-db/pkg/chain/client/service" // shorthand for chain client service
chainTypes "github.com/kwilteam/kwil-db/pkg/chain/types"
)

func NewStartCmd() *cobra.Command {
Expand All @@ -62,19 +60,14 @@ var startCmd = &cobra.Command{
return err
}

fmt.Println("Chain client config: ", cfg.Deposits.ClientChainRPCURL)
logger := log.New(cfg.Log)
logger = *logger.Named("kwild")

ctx, cancel := context.WithCancel(ctx)
defer cancel()
fmt.Printf("Initializing kwil server")

srv, txSvc, err := initialize_kwil_server(ctx, cfg, logger)
if err != nil {
return nil
}
fmt.Println("Chain client config: ", cfg.Deposits.ClientChainRPCURL)
fmt.Printf("Starting kwil server")

app, err := kwildbapp.NewKwilDbApplication(srv, txSvc.GetExecutor())
if err != nil {
return nil
Expand Down Expand Up @@ -238,20 +231,6 @@ func newCometNode(app abci.Application, cfg *config.KwildConfig, txSvc *txsvc.Se
return node, nil
}

func buildChainClient(cfg *config.KwildConfig, logger log.Logger) (chainClient.ChainClient, error) {
fmt.Println("Building chain client", cfg.Deposits.ClientChainRPCURL, cfg.Deposits.ChainCode)
if cfg.WithoutChainSyncer {
return ccService.NewEmptyChainClient(), nil
}

return ccService.NewChainClient(cfg.Deposits.ClientChainRPCURL,
ccService.WithChainCode(chainTypes.ChainCode(cfg.Deposits.ChainCode)),
ccService.WithLogger(*logger.Named("chainClient")),
ccService.WithReconnectInterval(int64(cfg.Deposits.ReconnectionInterval)),
ccService.WithRequiredConfirmations(int64(cfg.Deposits.BlockConfirmations)),
)
}

func buildAccountRepository(ctx context.Context, logger log.Logger, cfg *config.KwildConfig) (AccountStore, error) {
return balances.NewAccountStore(ctx,
balances.WithLogger(*logger.Named("accountStore")),
Expand All @@ -264,9 +243,9 @@ func buildAccountRepository(ctx context.Context, logger log.Logger, cfg *config.
type AccountStore interface {
ApplyChangeset(changeset io.Reader) error
Close() error
CreateSession() (balances.Session, error)
CreateSession() (sql.Session, error)
GetAccount(ctx context.Context, address string) (*balances.Account, error)
Savepoint() (balances.Savepoint, error)
Savepoint() (sql.Savepoint, error)
Spend(ctx context.Context, spend *balances.Spend) error
}

Expand Down
2 changes: 1 addition & 1 deletion internal/app/kwild/cmd/validator/approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func approveCmd() *cobra.Command {
}
fmt.Println("Arg1: ", args[0], "Arg2: ", args[1])
fmt.Println(cfg, "BcRPCURL: ", cfg.BcRpcUrl, "GrpcListenAddress: ", cfg.GrpcListenAddress)
options := []client.ClientOpt{client.WithBcRpcUrl(args[2])}
options := []client.ClientOpt{client.WithCometBftUrl(args[2])}

clt, err := client.New(ctx, cfg.GrpcListenAddress, options...)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/app/kwild/cmd/validator/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func joinCmd() *cobra.Command {
if err != nil {
return err
}
options := []client.ClientOpt{client.WithBcRpcUrl(args[2])}
options := []client.ClientOpt{client.WithCometBftUrl(args[2])}

clt, err := client.New(ctx, cfg.GrpcListenAddress, options...)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/app/kwild/cmd/validator/leave.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func leaveCmd() *cobra.Command {
if err != nil {
return err
}
options := []client.ClientOpt{client.WithBcRpcUrl(args[1])}
options := []client.ClientOpt{client.WithCometBftUrl(args[1])}

clt, err := client.New(ctx, cfg.GrpcListenAddress, options...)
if err != nil {
Expand Down
100 changes: 14 additions & 86 deletions internal/app/kwild/config/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,17 @@ const (
)

type KwildConfig struct {
GrpcListenAddress string
HttpListenAddress string
PrivateKey *ecdsa.PrivateKey
Deposits DepositsConfig
ChainSyncer ChainSyncerConfig
WithoutChainSyncer bool
WithoutAccountStore bool
SqliteFilePath string
Log log.Config
ExtensionEndpoints []string
ArweaveConfig ArweaveConfig
BcRpcUrl string
BCPrivateKey *cmtCrypto.PrivKey
WithoutGasCosts bool
WithoutNonces bool
}

type DepositsConfig struct {
ReconnectionInterval int
BlockConfirmations int
ChainCode int
ClientChainRPCURL string
PoolAddress string
}

type ChainSyncerConfig struct {
ChunkSize int
GrpcListenAddress string
HttpListenAddress string
PrivateKey *ecdsa.PrivateKey
SqliteFilePath string
Log log.Config
ExtensionEndpoints []string
ArweaveConfig ArweaveConfig
BcRpcUrl string
BCPrivateKey cmtCrypto.PrivKey
WithoutGasCosts bool
WithoutNonces bool
}

type ArweaveConfig struct {
Expand All @@ -57,21 +41,13 @@ var (
RegisteredVariables = []config.CfgVar{
PrivateKey,
GrpcListenAddress,
DepositsReconnectionInterval,
DepositsBlockConfirmation,
DepositsChainCode,
DepositsClientChainRPCURL,
WithoutAccountStore,
WithoutChainSyncer,
DepositsPoolAddress,
ChainSyncerChunkSize,
SqliteFilePath,
LogLevel,
LogOutputPaths,
HttpListenAddress,
ExtensionEndpoints,
ArweaveBundlrURL,
BcRpcUrl,
CometBftRPCUrl,
WithoutGasCosts,
WithoutNonces,
}
Expand All @@ -96,8 +72,8 @@ var (
},
}

BcRpcUrl = config.CfgVar{
EnvName: "BC_RPC_URL",
CometBftRPCUrl = config.CfgVar{
EnvName: "COMETBFT_RPC_URL",
Field: "BcRpcUrl",
Default: "tcp://localhost:26657",
}
Expand All @@ -108,42 +84,6 @@ var (
Default: ":50051",
}

DepositsReconnectionInterval = config.CfgVar{
EnvName: "DEPOSITS_RECONNECTION_INTERVAL",
Field: "Deposits.ReconnectionInterval",
Default: 30,
}

DepositsBlockConfirmation = config.CfgVar{
EnvName: "DEPOSITS_BLOCK_CONFIRMATIONS",
Field: "Deposits.BlockConfirmations",
Default: 12,
}

DepositsChainCode = config.CfgVar{
EnvName: "DEPOSITS_CHAIN_CODE",
Field: "Deposits.ChainCode",
Default: 0,
}

DepositsClientChainRPCURL = config.CfgVar{
EnvName: "DEPOSITS_CLIENT_CHAIN_RPC_URL",
Field: "Deposits.ClientChainRPCURL",
Default: "http://localhost:8545",
}

DepositsPoolAddress = config.CfgVar{
EnvName: "DEPOSITS_POOL_ADDRESS",
Field: "Deposits.PoolAddress",
Default: "0x0000000000000000000000000000000000000000",
}

ChainSyncerChunkSize = config.CfgVar{
EnvName: "CHAIN_SYNCER_CHUNK_SIZE",
Field: "ChainSyncer.ChunkSize",
Default: 100000,
}

SqliteFilePath = config.CfgVar{
EnvName: "SQLITE_FILE_PATH",
Field: "SqliteFilePath",
Expand Down Expand Up @@ -212,18 +152,6 @@ var (
},
}

WithoutAccountStore = config.CfgVar{
EnvName: "WITHOUT_ACCOUNT_STORE",
Field: "WithoutAccountStore",
Default: false,
}

WithoutChainSyncer = config.CfgVar{
EnvName: "WITHOUT_CHAIN_SYNCER",
Field: "WithoutChainSyncer",
Default: false,
}

ArweaveBundlrURL = config.CfgVar{
EnvName: "ARWEAVE_BUNDLR_URL",
Field: "ArweaveConfig.BundlrURL",
Expand Down
Loading
0