From 5abf3ca9dece8132cc4dd2d17f6baef5afd4b7af Mon Sep 17 00:00:00 2001 From: Michael Tsitrin <114929630+mtsitrin@users.noreply.github.com> Date: Thu, 22 Jun 2023 19:47:58 +0300 Subject: [PATCH] feat: mock SL doesn't use keyring path from config. (#367) --- config/defaults.go | 12 +++++++----- node/integration_test.go | 8 ++++++-- node/node.go | 3 +++ rpc/client/client_test.go | 6 ++++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/config/defaults.go b/config/defaults.go index a2f03fa0d..e028c2665 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -1,6 +1,7 @@ package config import ( + "path/filepath" "time" "github.com/dymensionxyz/dymint/settlement" @@ -12,7 +13,7 @@ const ( // Version is a default dymint version for P2P client. Version = "0.2.2" - DefaultHomeDir = ".dymint" + DefaultHomeDir = "sequencer_keys" DefaultChainID = "dymint-testnet" ) @@ -28,8 +29,8 @@ func DefaultConfig(home, chainId string) *NodeConfig { Aggregator: true, BlockManagerConfig: BlockManagerConfig{ BlockTime: 200 * time.Millisecond, - EmptyBlocksMaxTime: 60 * time.Second, - BatchSubmitMaxTime: 600 * time.Second, + EmptyBlocksMaxTime: 3 * time.Second, + BatchSubmitMaxTime: 20 * time.Second, NamespaceID: "000000000000ffff", BlockBatchSize: 500, BlockBatchSizeBytes: 1500000}, @@ -38,8 +39,9 @@ func DefaultConfig(home, chainId string) *NodeConfig { } if home == "" { - home = DefaultHomeDir + home = "/tmp" } + keyringDir := filepath.Join(home, DefaultHomeDir) if chainId == "" { chainId = DefaultChainID } @@ -48,7 +50,7 @@ func DefaultConfig(home, chainId string) *NodeConfig { KeyringBackend: "test", NodeAddress: "http://127.0.0.1:36657", RollappID: chainId, - KeyringHomeDir: home, + KeyringHomeDir: keyringDir, DymAccountName: "sequencer", GasPrices: "0.025udym", } diff --git a/node/integration_test.go b/node/integration_test.go index a2b76e0a5..a1b477a1d 100644 --- a/node/integration_test.go +++ b/node/integration_test.go @@ -3,6 +3,7 @@ package node import ( "context" "crypto/rand" + "encoding/hex" mrand "math/rand" "testing" "time" @@ -38,7 +39,10 @@ func TestAggregatorMode(t *testing.T) { app.On("Info", mock.Anything).Return(abci.ResponseInfo{LastBlockHeight: 0, LastBlockAppHash: []byte{0}}) key, _, _ := crypto.GenerateEd25519Key(rand.Reader) - signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader) + signingKey, pubkey, _ := crypto.GenerateEd25519Key(rand.Reader) + pubkeyBytes, _ := pubkey.Raw() + proposerKey := hex.EncodeToString(pubkeyBytes) + anotherKey, _, _ := crypto.GenerateEd25519Key(rand.Reader) blockManagerConfig := config.BlockManagerConfig{ @@ -57,7 +61,7 @@ func TestAggregatorMode(t *testing.T) { DALayer: "mock", DAConfig: "", SettlementLayer: "mock", - SettlementConfig: settlement.Config{}, + SettlementConfig: settlement.Config{ProposerPubKey: proposerKey}, } node, err := NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger()) require.NoError(err) diff --git a/node/node.go b/node/node.go index 109dd5063..8da72c971 100644 --- a/node/node.go +++ b/node/node.go @@ -157,6 +157,9 @@ func NewNode(ctx context.Context, conf config.NodeConfig, p2pKey crypto.PrivKey, if settlementlc == nil { return nil, fmt.Errorf("couldn't get settlement client named '%s'", conf.SettlementLayer) } + if conf.SettlementLayer == "mock" { + conf.SettlementConfig.KeyringHomeDir = conf.RootDir + } err = settlementlc.Init(conf.SettlementConfig, pubsubServer, logger.With("module", "settlement_client")) if err != nil { return nil, fmt.Errorf("settlement layer client initialization error: %w", err) diff --git a/rpc/client/client_test.go b/rpc/client/client_test.go index 3d93f0277..89763e657 100644 --- a/rpc/client/client_test.go +++ b/rpc/client/client_test.go @@ -795,7 +795,9 @@ func getRPC(t *testing.T) (*mocks.Application, *Client) { app := &mocks.Application{} app.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{}) key, _, _ := crypto.GenerateEd25519Key(crand.Reader) - signingKey, _, err := crypto.GenerateEd25519Key(crand.Reader) + signingKey, pubkey, err := crypto.GenerateEd25519Key(crand.Reader) + pubkeyBytes, _ := pubkey.Raw() + proposerKey := hex.EncodeToString(pubkeyBytes) require.NoError(err) config := config.NodeConfig{ @@ -808,7 +810,7 @@ func getRPC(t *testing.T) (*mocks.Application, *Client) { DALayer: "mock", DAConfig: "", SettlementLayer: "mock", - SettlementConfig: settlement.Config{}, + SettlementConfig: settlement.Config{ProposerPubKey: proposerKey}, } node, err := node.NewNode(context.Background(), config, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger()) require.NoError(err)