diff --git a/block/manager.go b/block/manager.go index afce8e161..baec63d82 100644 --- a/block/manager.go +++ b/block/manager.go @@ -114,21 +114,6 @@ func NewManager( return nil, err } - // TODO((#119): Probably should be validated and manage default on config init. - if conf.BlockBatchMaxSizeBytes == 0 { - logger.Info("WARNING: using default DA batch size bytes limit", "BlockBatchMaxSizeBytes", config.DefaultNodeConfig.BlockBatchMaxSizeBytes) - conf.BlockBatchMaxSizeBytes = config.DefaultNodeConfig.BlockBatchMaxSizeBytes - } - if conf.BatchSubmitMaxTime == 0 { - logger.Info("WARNING: using default DA batch submit max time", "BatchSubmitMaxTime", config.DefaultNodeConfig.BatchSubmitMaxTime) - conf.BatchSubmitMaxTime = config.DefaultNodeConfig.BatchSubmitMaxTime - - //TODO: validate it's larger than empty blocks time - } - if conf.BlockTime == 0 { - panic("Block production time must be a positive number") - } - exec, err := state.NewBlockExecutor(proposerAddress, conf.NamespaceID, genesis.ChainID, mempool, proxyApp, eventBus, logger) if err != nil { return nil, fmt.Errorf("failed to create block executor: %w", err) diff --git a/block/manager_test.go b/block/manager_test.go index 44250a92c..936b27b0a 100644 --- a/block/manager_test.go +++ b/block/manager_test.go @@ -581,9 +581,10 @@ func initSettlementLayerMock(settlementlc settlement.LayerI, proposer string, pu func getManagerConfig() config.BlockManagerConfig { return config.BlockManagerConfig{ - BlockTime: 100 * time.Millisecond, - BlockBatchSize: defaultBatchSize, - BatchSubmitMaxTime: 30 * time.Minute, - NamespaceID: "0102030405060708", + BlockTime: 100 * time.Millisecond, + BlockBatchSize: defaultBatchSize, + BlockBatchMaxSizeBytes: 1000, + BatchSubmitMaxTime: 30 * time.Minute, + NamespaceID: "0102030405060708", } } diff --git a/block/production_test.go b/block/production_test.go index 162c693e7..1f11d474b 100644 --- a/block/production_test.go +++ b/block/production_test.go @@ -177,10 +177,11 @@ func TestBatchSubmissionAfterTimeout(t *testing.T) { // Init manager with empty blocks feature enabled managerConfig := config.BlockManagerConfig{ - BlockTime: blockTime, - EmptyBlocksMaxTime: 0, - BatchSubmitMaxTime: submitTimeout, - BlockBatchSize: batchSize, + BlockTime: blockTime, + EmptyBlocksMaxTime: 0, + BatchSubmitMaxTime: submitTimeout, + BlockBatchSize: batchSize, + BlockBatchMaxSizeBytes: 1000, } manager, err := getManager(managerConfig, nil, nil, 1, 1, 0, proxyApp, nil) diff --git a/config/config.go b/config/config.go index dd7abd59f..a6d0155f2 100644 --- a/config/config.go +++ b/config/config.go @@ -1,11 +1,10 @@ package config import ( + "fmt" "path/filepath" "time" - tmcmd "github.com/tendermint/tendermint/cmd/cometbft/commands" - "github.com/dymensionxyz/dymint/settlement" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -18,31 +17,6 @@ const ( DefaultConfigFileName = "dymint.toml" ) -const ( - flagAggregator = "dymint.aggregator" - flagDALayer = "dymint.da_layer" - flagDAConfig = "dymint.da_config" - flagBlockTime = "dymint.block_time" - flagEmptyBlocksMaxTime = "dymint.empty_blocks_max_time" - flagBatchSubmitMaxTime = "dymint.batch_submit_max_time" - // TODO(omritoptix): Namespace ID should be part of the DA config - flagNamespaceID = "dymint.namespace_id" - flagBlockBatchSize = "dymint.block_batch_size" - flagBlockBatchMaxSizeBytes = "dymint.block_batch_max_size_bytes" -) - -const ( - flagSettlementLayer = "dymint.settlement_layer" - flagSLNodeAddress = "dymint.settlement_config.node_address" - flagSLKeyringBackend = "dymint.settlement_config.keyring_backend" - flagSLKeyringHomeDir = "dymint.settlement_config.keyring_home_dir" - flagSLDymAccountName = "dymint.settlement_config.dym_account_name" - flagSLGasLimit = "dymint.settlement_config.gas_limit" - flagSLGasPrices = "dymint.settlement_config.gas_prices" - flagSLGasFees = "dymint.settlement_config.gas_fees" - flagRollappID = "dymint.settlement_config.rollapp_id" -) - // NodeConfig stores Dymint node configuration. type NodeConfig struct { // parameters below are translated from existing config @@ -70,13 +44,11 @@ type BlockManagerConfig struct { NamespaceID string `mapstructure:"namespace_id"` // The size of the batch in blocks. Every batch we'll write to the DA and the settlement layer. BlockBatchSize uint64 `mapstructure:"block_batch_size"` - // The max size of the batch in Bytes. Every batch we'll write to the DA and the settlement layer. + // The size of the batch in Bytes. Every batch we'll write to the DA and the settlement layer. BlockBatchMaxSizeBytes uint64 `mapstructure:"block_batch_max_size_bytes"` } // GetViperConfig reads configuration parameters from Viper instance. -// -// This method is called in cosmos-sdk. func (nc *NodeConfig) GetViperConfig(cmd *cobra.Command, homeDir string) error { v := viper.GetViper() @@ -103,94 +75,59 @@ func (nc *NodeConfig) GetViperConfig(cmd *cobra.Command, homeDir string) error { return err } - return nil -} + err = nc.Validate() + if err != nil { + return err + } -// AddFlags adds Dymint specific configuration options to cobra Command. -// -// This function is called in cosmos-sdk. -func AddNodeFlags(cmd *cobra.Command) { - //Add tendermint default flags - tmcmd.AddNodeFlags(cmd) - - def := DefaultNodeConfig - - cmd.Flags().Bool(flagAggregator, false, "run node in aggregator mode") - cmd.Flags().String(flagDALayer, def.DALayer, "Data Availability Layer Client name (mock or grpc") - cmd.Flags().String(flagDAConfig, def.DAConfig, "Data Availability Layer Client config") - cmd.Flags().Duration(flagBlockTime, def.BlockTime, "block time (for aggregator mode)") - cmd.Flags().Duration(flagEmptyBlocksMaxTime, def.EmptyBlocksMaxTime, "max time for empty blocks (for aggregator mode)") - cmd.Flags().Duration(flagBatchSubmitMaxTime, def.BatchSubmitMaxTime, "max time for batch submit (for aggregator mode)") - cmd.Flags().String(flagNamespaceID, def.NamespaceID, "namespace identifies (8 bytes in hex)") - cmd.Flags().Uint64(flagBlockBatchSize, def.BlockBatchSize, "block batch size") - cmd.Flags().Uint64(flagBlockBatchMaxSizeBytes, def.BlockBatchMaxSizeBytes, "block batch max size in bytes") - - cmd.Flags().String(flagSettlementLayer, def.SettlementLayer, "Settlement Layer Client name") - cmd.Flags().String(flagSLNodeAddress, def.SettlementConfig.NodeAddress, "Settlement Layer RPC node address") - cmd.Flags().String(flagSLKeyringBackend, def.SettlementConfig.KeyringBackend, "Sequencer keyring backend") - cmd.Flags().String(flagSLKeyringHomeDir, def.SettlementConfig.KeyringHomeDir, "Sequencer keyring path") - cmd.Flags().String(flagSLDymAccountName, def.SettlementConfig.DymAccountName, "Sequencer account name in keyring") - cmd.Flags().String(flagSLGasFees, def.SettlementConfig.GasFees, "Settlement Layer gas fees") - cmd.Flags().String(flagSLGasPrices, def.SettlementConfig.GasPrices, "Settlement Layer gas prices") - cmd.Flags().Uint64(flagSLGasLimit, def.SettlementConfig.GasLimit, "Settlement Layer batch submit gas limit") - cmd.Flags().String(flagRollappID, def.SettlementConfig.RollappID, "The chainID of the rollapp") + return nil } -func BindDymintFlags(cmd *cobra.Command, v *viper.Viper) error { - if err := v.BindPFlag("aggregator", cmd.Flags().Lookup(flagAggregator)); err != nil { - return err - } - if err := v.BindPFlag("da_layer", cmd.Flags().Lookup(flagDALayer)); err != nil { - return err - } - if err := v.BindPFlag("da_config", cmd.Flags().Lookup(flagDAConfig)); err != nil { - return err - } - if err := v.BindPFlag("block_time", cmd.Flags().Lookup(flagBlockTime)); err != nil { - return err - } - if err := v.BindPFlag("empty_blocks_max_time", cmd.Flags().Lookup(flagEmptyBlocksMaxTime)); err != nil { - return err - } - if err := v.BindPFlag("batch_submit_max_time", cmd.Flags().Lookup(flagBatchSubmitMaxTime)); err != nil { - return err - } - if err := v.BindPFlag("namespace_id", cmd.Flags().Lookup(flagNamespaceID)); err != nil { - return err +// validate BlockManagerConfig +func (c BlockManagerConfig) Validate() error { + if c.BlockTime <= 0 { + return fmt.Errorf("block_time must be positive") } - if err := v.BindPFlag("block_batch_size", cmd.Flags().Lookup(flagBlockBatchSize)); err != nil { - return err - } - if err := v.BindPFlag("block_batch_max_size_bytes", cmd.Flags().Lookup(flagBlockBatchMaxSizeBytes)); err != nil { - return err - } - if err := v.BindPFlag("settlement_layer", cmd.Flags().Lookup(flagSettlementLayer)); err != nil { - return err - } - if err := v.BindPFlag("node_address", cmd.Flags().Lookup(flagSLNodeAddress)); err != nil { - return err + + if c.EmptyBlocksMaxTime < 0 { + return fmt.Errorf("empty_blocks_max_time must be positive or zero to disable") } - if err := v.BindPFlag("keyring_backend", cmd.Flags().Lookup(flagSLKeyringBackend)); err != nil { - return err + + if c.EmptyBlocksMaxTime <= c.BlockTime { + return fmt.Errorf("empty_blocks_max_time must be greater than block_time") } - if err := v.BindPFlag("keyring_home_dir", cmd.Flags().Lookup(flagSLKeyringHomeDir)); err != nil { - return err + + if c.BatchSubmitMaxTime <= 0 { + return fmt.Errorf("batch_submit_max_time must be positive") } - if err := v.BindPFlag("dym_account_name", cmd.Flags().Lookup(flagSLDymAccountName)); err != nil { - return err + + if c.BatchSubmitMaxTime <= c.EmptyBlocksMaxTime { + return fmt.Errorf("batch_submit_max_time must be greater than empty_blocks_max_time") } - if err := v.BindPFlag("gas_fees", cmd.Flags().Lookup(flagSLGasFees)); err != nil { - return err + + if c.BlockBatchSize <= 0 { + return fmt.Errorf("block_batch_size must be positive") } - if err := v.BindPFlag("gas_prices", cmd.Flags().Lookup(flagSLGasPrices)); err != nil { - return err + + if c.BlockBatchMaxSizeBytes <= 0 { + return fmt.Errorf("block_batch_size_bytes must be positive") } - if err := v.BindPFlag("gas_limit", cmd.Flags().Lookup(flagSLGasLimit)); err != nil { + + return nil +} + +func (c NodeConfig) Validate() error { + if err := c.BlockManagerConfig.Validate(); err != nil { return err } - if err := v.BindPFlag("rollapp_id", cmd.Flags().Lookup(flagRollappID)); err != nil { - return err + + if c.SettlementLayer != "mock" { + if err := c.SettlementConfig.Validate(); err != nil { + return err + } } + //TODO: validate DA config + return nil } diff --git a/config/config_test.go b/config/config_test.go index 29f0b2e70..cf063cc02 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -23,6 +23,8 @@ func TestViperAndCobra(t *testing.T) { assert.NoError(cmd.Flags().Set(flagDALayer, "foobar")) assert.NoError(cmd.Flags().Set(flagDAConfig, `{"json":true}`)) assert.NoError(cmd.Flags().Set(flagBlockTime, "1234s")) + assert.NoError(cmd.Flags().Set(flagEmptyBlocksMaxTime, "2000s")) + assert.NoError(cmd.Flags().Set(flagBatchSubmitMaxTime, "3000s")) assert.NoError(cmd.Flags().Set(flagNamespaceID, "0102030405060708")) assert.NoError(cmd.Flags().Set(flagBlockBatchSize, "10")) @@ -35,3 +37,5 @@ func TestViperAndCobra(t *testing.T) { assert.Equal("0102030405060708", nc.NamespaceID) assert.Equal(uint64(10), nc.BlockBatchSize) } + +//TODO: check invalid config diff --git a/config/flags.go b/config/flags.go new file mode 100644 index 000000000..1f62439d9 --- /dev/null +++ b/config/flags.go @@ -0,0 +1,120 @@ +package config + +import ( + "github.com/spf13/cobra" + "github.com/spf13/viper" + tmcmd "github.com/tendermint/tendermint/cmd/cometbft/commands" +) + +const ( + flagAggregator = "dymint.aggregator" + flagDALayer = "dymint.da_layer" + flagDAConfig = "dymint.da_config" + flagBlockTime = "dymint.block_time" + flagEmptyBlocksMaxTime = "dymint.empty_blocks_max_time" + flagBatchSubmitMaxTime = "dymint.batch_submit_max_time" + flagNamespaceID = "dymint.namespace_id" + flagBlockBatchSize = "dymint.block_batch_size" + flagBlockBatchMaxSizeBytes = "dymint.block_batch_max_size_bytes" +) + +const ( + flagSettlementLayer = "dymint.settlement_layer" + flagSLNodeAddress = "dymint.settlement_config.node_address" + flagSLKeyringBackend = "dymint.settlement_config.keyring_backend" + flagSLKeyringHomeDir = "dymint.settlement_config.keyring_home_dir" + flagSLDymAccountName = "dymint.settlement_config.dym_account_name" + flagSLGasLimit = "dymint.settlement_config.gas_limit" + flagSLGasPrices = "dymint.settlement_config.gas_prices" + flagSLGasFees = "dymint.settlement_config.gas_fees" + flagRollappID = "dymint.settlement_config.rollapp_id" +) + +// AddFlags adds Dymint specific configuration options to cobra Command. +// +// This function is called in cosmos-sdk. +func AddNodeFlags(cmd *cobra.Command) { + //Add tendermint default flags + tmcmd.AddNodeFlags(cmd) + + def := DefaultNodeConfig + + cmd.Flags().Bool(flagAggregator, false, "run node in aggregator mode") + cmd.Flags().String(flagDALayer, def.DALayer, "Data Availability Layer Client name (mock or grpc") + cmd.Flags().String(flagDAConfig, def.DAConfig, "Data Availability Layer Client config") + cmd.Flags().Duration(flagBlockTime, def.BlockTime, "block time (for aggregator mode)") + cmd.Flags().Duration(flagEmptyBlocksMaxTime, def.EmptyBlocksMaxTime, "max time for empty blocks (for aggregator mode)") + cmd.Flags().Duration(flagBatchSubmitMaxTime, def.BatchSubmitMaxTime, "max time for batch submit (for aggregator mode)") + cmd.Flags().String(flagNamespaceID, def.NamespaceID, "namespace identifies (8 bytes in hex)") + cmd.Flags().Uint64(flagBlockBatchSize, def.BlockBatchSize, "block batch size") + cmd.Flags().Uint64(flagBlockBatchMaxSizeBytes, def.BlockBatchMaxSizeBytes, "block batch size in bytes") + + cmd.Flags().String(flagSettlementLayer, def.SettlementLayer, "Settlement Layer Client name") + cmd.Flags().String(flagSLNodeAddress, def.SettlementConfig.NodeAddress, "Settlement Layer RPC node address") + cmd.Flags().String(flagSLKeyringBackend, def.SettlementConfig.KeyringBackend, "Sequencer keyring backend") + cmd.Flags().String(flagSLKeyringHomeDir, def.SettlementConfig.KeyringHomeDir, "Sequencer keyring path") + cmd.Flags().String(flagSLDymAccountName, def.SettlementConfig.DymAccountName, "Sequencer account name in keyring") + cmd.Flags().String(flagSLGasFees, def.SettlementConfig.GasFees, "Settlement Layer gas fees") + cmd.Flags().String(flagSLGasPrices, def.SettlementConfig.GasPrices, "Settlement Layer gas prices") + cmd.Flags().Uint64(flagSLGasLimit, def.SettlementConfig.GasLimit, "Settlement Layer batch submit gas limit") + cmd.Flags().String(flagRollappID, def.SettlementConfig.RollappID, "The chainID of the rollapp") +} + +func BindDymintFlags(cmd *cobra.Command, v *viper.Viper) error { + if err := v.BindPFlag("aggregator", cmd.Flags().Lookup(flagAggregator)); err != nil { + return err + } + if err := v.BindPFlag("da_layer", cmd.Flags().Lookup(flagDALayer)); err != nil { + return err + } + if err := v.BindPFlag("da_config", cmd.Flags().Lookup(flagDAConfig)); err != nil { + return err + } + if err := v.BindPFlag("block_time", cmd.Flags().Lookup(flagBlockTime)); err != nil { + return err + } + if err := v.BindPFlag("empty_blocks_max_time", cmd.Flags().Lookup(flagEmptyBlocksMaxTime)); err != nil { + return err + } + if err := v.BindPFlag("batch_submit_max_time", cmd.Flags().Lookup(flagBatchSubmitMaxTime)); err != nil { + return err + } + if err := v.BindPFlag("namespace_id", cmd.Flags().Lookup(flagNamespaceID)); err != nil { + return err + } + if err := v.BindPFlag("block_batch_size", cmd.Flags().Lookup(flagBlockBatchSize)); err != nil { + return err + } + if err := v.BindPFlag("block_batch_max_size_bytes", cmd.Flags().Lookup(flagBlockBatchMaxSizeBytes)); err != nil { + return err + } + if err := v.BindPFlag("settlement_layer", cmd.Flags().Lookup(flagSettlementLayer)); err != nil { + return err + } + if err := v.BindPFlag("node_address", cmd.Flags().Lookup(flagSLNodeAddress)); err != nil { + return err + } + if err := v.BindPFlag("keyring_backend", cmd.Flags().Lookup(flagSLKeyringBackend)); err != nil { + return err + } + if err := v.BindPFlag("keyring_home_dir", cmd.Flags().Lookup(flagSLKeyringHomeDir)); err != nil { + return err + } + if err := v.BindPFlag("dym_account_name", cmd.Flags().Lookup(flagSLDymAccountName)); err != nil { + return err + } + if err := v.BindPFlag("gas_fees", cmd.Flags().Lookup(flagSLGasFees)); err != nil { + return err + } + if err := v.BindPFlag("gas_prices", cmd.Flags().Lookup(flagSLGasPrices)); err != nil { + return err + } + if err := v.BindPFlag("gas_limit", cmd.Flags().Lookup(flagSLGasLimit)); err != nil { + return err + } + if err := v.BindPFlag("rollapp_id", cmd.Flags().Lookup(flagRollappID)); err != nil { + return err + } + + return nil +} diff --git a/node/integration_test.go b/node/integration_test.go index a1b477a1d..735275663 100644 --- a/node/integration_test.go +++ b/node/integration_test.go @@ -46,9 +46,11 @@ func TestAggregatorMode(t *testing.T) { anotherKey, _, _ := crypto.GenerateEd25519Key(rand.Reader) blockManagerConfig := config.BlockManagerConfig{ - BlockBatchSize: 1, - BlockTime: 1 * time.Second, - NamespaceID: "0102030405060708", + BlockBatchSize: 1, + BlockTime: 1 * time.Second, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, + NamespaceID: "0102030405060708", } nodeConfig := config.NodeConfig{ diff --git a/node/node_test.go b/node/node_test.go index 6bdb7ee7a..acae0dd75 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -59,16 +59,21 @@ func TestMempoolDirectly(t *testing.T) { anotherKey, _, _ := crypto.GenerateEd25519Key(rand.Reader) nodeConfig := config.NodeConfig{ - RootDir: "", - DBPath: "", - P2P: config.P2PConfig{}, - RPC: config.RPCConfig{}, - Aggregator: false, - BlockManagerConfig: config.BlockManagerConfig{BlockTime: 100 * time.Millisecond, BlockBatchSize: 2}, - DALayer: "mock", - DAConfig: "", - SettlementLayer: "mock", - SettlementConfig: settlement.Config{}, + RootDir: "", + DBPath: "", + P2P: config.P2PConfig{}, + RPC: config.RPCConfig{}, + Aggregator: false, + BlockManagerConfig: config.BlockManagerConfig{ + BlockTime: 100 * time.Millisecond, + BlockBatchSize: 2, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, + }, + DALayer: "mock", + DAConfig: "", + SettlementLayer: "mock", + SettlementConfig: settlement.Config{}, } node, err := NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger()) require.NoError(err) diff --git a/node/testutils.go b/node/testutils.go index d81fb678f..b9976e057 100644 --- a/node/testutils.go +++ b/node/testutils.go @@ -25,7 +25,12 @@ func CreateNode(isAggregator bool, blockManagerConfig *config.BlockManagerConfig nodeConfig := config.DefaultNodeConfig if blockManagerConfig == nil { - blockManagerConfig = &config.BlockManagerConfig{BlockBatchSize: 1, BlockTime: 100 * time.Millisecond} + blockManagerConfig = &config.BlockManagerConfig{ + BlockBatchSize: 1, + BlockTime: 100 * time.Millisecond, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, + } } nodeConfig.BlockManagerConfig = *blockManagerConfig nodeConfig.Aggregator = isAggregator diff --git a/rpc/client/client_test.go b/rpc/client/client_test.go index 89763e657..991a28034 100644 --- a/rpc/client/client_test.go +++ b/rpc/client/client_test.go @@ -94,16 +94,21 @@ func TestGenesisChunked(t *testing.T) { signingKey, _, _ := crypto.GenerateEd25519Key(crand.Reader) config := config.NodeConfig{ - RootDir: "", - DBPath: "", - P2P: config.P2PConfig{}, - RPC: config.RPCConfig{}, - Aggregator: false, - BlockManagerConfig: config.BlockManagerConfig{BlockTime: 100 * time.Millisecond, BlockBatchSize: 1}, - DALayer: "mock", - DAConfig: "", - SettlementLayer: "mock", - SettlementConfig: settlement.Config{}, + RootDir: "", + DBPath: "", + P2P: config.P2PConfig{}, + RPC: config.RPCConfig{}, + Aggregator: false, + BlockManagerConfig: config.BlockManagerConfig{ + BlockTime: 100 * time.Millisecond, + BlockBatchSize: 1, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, + }, + DALayer: "mock", + DAConfig: "", + SettlementLayer: "mock", + SettlementConfig: settlement.Config{}, } n, _ := node.NewNode(context.Background(), config, privKey, signingKey, proxy.NewLocalClientCreator(mockApp), genDoc, log.TestingLogger()) @@ -429,8 +434,10 @@ func TestTx(t *testing.T) { SettlementLayer: "mock", Aggregator: true, BlockManagerConfig: config.BlockManagerConfig{ - BlockBatchSize: 1, - BlockTime: 200 * time.Millisecond, + BlockBatchSize: 1, + BlockTime: 200 * time.Millisecond, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, }, SettlementConfig: settlement.Config{ProposerPubKey: hex.EncodeToString(pubKeybytes)}, }, @@ -690,11 +697,16 @@ func TestValidatorSetHandling(t *testing.T) { }) nodeConfig := config.NodeConfig{ - DALayer: "mock", - SettlementLayer: "mock", - Aggregator: true, - BlockManagerConfig: config.BlockManagerConfig{BlockTime: 10 * time.Millisecond, BlockBatchSize: 1}, - SettlementConfig: settlement.Config{ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes)}, + DALayer: "mock", + SettlementLayer: "mock", + Aggregator: true, + BlockManagerConfig: config.BlockManagerConfig{ + BlockTime: 10 * time.Millisecond, + BlockBatchSize: 1, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, + }, + SettlementConfig: settlement.Config{ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes)}, } node, err := node.NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger()) @@ -801,16 +813,21 @@ func getRPC(t *testing.T) (*mocks.Application, *Client) { require.NoError(err) config := config.NodeConfig{ - RootDir: "", - DBPath: "", - P2P: config.P2PConfig{}, - RPC: config.RPCConfig{}, - Aggregator: false, - BlockManagerConfig: config.BlockManagerConfig{BlockTime: 100 * time.Millisecond, BlockBatchSize: 1}, - DALayer: "mock", - DAConfig: "", - SettlementLayer: "mock", - SettlementConfig: settlement.Config{ProposerPubKey: proposerKey}, + RootDir: "", + DBPath: "", + P2P: config.P2PConfig{}, + RPC: config.RPCConfig{}, + Aggregator: false, + BlockManagerConfig: config.BlockManagerConfig{ + BlockTime: 100 * time.Millisecond, + BlockBatchSize: 1, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, + }, + DALayer: "mock", + DAConfig: "", + SettlementLayer: "mock", + 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) @@ -888,8 +905,10 @@ func TestMempool2Nodes(t *testing.T) { SettlementLayer: "mock", SettlementConfig: settlement.Config{ProposerPubKey: hex.EncodeToString(proposerPubKey1Bytes)}, BlockManagerConfig: config.BlockManagerConfig{ - BlockBatchSize: 1, - BlockTime: 100 * time.Millisecond, + BlockBatchSize: 1, + BlockTime: 100 * time.Millisecond, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, }, P2P: config.P2PConfig{ ListenAddress: "/ip4/127.0.0.1/tcp/9001", @@ -903,8 +922,10 @@ func TestMempool2Nodes(t *testing.T) { SettlementLayer: "mock", SettlementConfig: settlement.Config{ProposerPubKey: hex.EncodeToString(proposerPubKey2Bytes)}, BlockManagerConfig: config.BlockManagerConfig{ - BlockBatchSize: 1, - BlockTime: 100 * time.Millisecond, + BlockBatchSize: 1, + BlockTime: 100 * time.Millisecond, + BatchSubmitMaxTime: 60 * time.Second, + BlockBatchMaxSizeBytes: 1000, }, P2P: config.P2PConfig{ ListenAddress: "/ip4/127.0.0.1/tcp/9002", diff --git a/rpc/json/service_test.go b/rpc/json/service_test.go index 7a6e51f31..2b7b5e2bf 100644 --- a/rpc/json/service_test.go +++ b/rpc/json/service_test.go @@ -294,7 +294,18 @@ func getRPC(t *testing.T) (*mocks.Application, *client.Client) { signingKey, proposerPubKey, _ := crypto.GenerateEd25519Key(rand.Reader) proposerPubKeyBytes, err := proposerPubKey.Raw() require.NoError(err) - config := config.NodeConfig{Aggregator: true, DALayer: "mock", SettlementLayer: "mock", BlockManagerConfig: config.BlockManagerConfig{BlockTime: 1 * time.Second, BlockBatchSize: 1}, SettlementConfig: settlement.Config{ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes)}} + config := config.NodeConfig{Aggregator: true, DALayer: "mock", SettlementLayer: "mock", + BlockManagerConfig: config.BlockManagerConfig{ + BlockTime: 1 * time.Second, + EmptyBlocksMaxTime: 0, + BatchSubmitMaxTime: 30 * time.Minute, + NamespaceID: "0102030405060708", + BlockBatchSize: 10000, + BlockBatchMaxSizeBytes: 1000, + }, + SettlementConfig: settlement.Config{ + ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes)}, + } node, err := node.NewNode(context.Background(), config, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger()) require.NoError(err) require.NotNil(node) diff --git a/settlement/config.go b/settlement/config.go index ef7ce5b34..71d633148 100644 --- a/settlement/config.go +++ b/settlement/config.go @@ -1,5 +1,7 @@ package settlement +import "errors" + // Config for the DymensionLayerClient type Config struct { KeyringBackend string `mapstructure:"keyring_backend"` @@ -15,4 +17,18 @@ type Config struct { ProposerPubKey string `json:"proposer_pub_key"` } -// TODO: add default config to be used in default NodeConfig +func (c Config) Validate() error { + if c.GasPrices != "" && c.GasFees != "" { + return errors.New("cannot provide both fees and gas prices") + } + + if c.GasPrices == "" && c.GasFees == "" { + return errors.New("must provide either fees or gas prices") + } + + if c.RollappID == "" { + return errors.New("must provide rollapp id") + } + + return nil +} diff --git a/testutil/block.go b/testutil/block.go index a666408dc..e88caf01f 100644 --- a/testutil/block.go +++ b/testutil/block.go @@ -1,9 +1,6 @@ package testutil import ( - "crypto/rand" - "math/big" - "github.com/tendermint/tendermint/crypto/ed25519" tmtypes "github.com/tendermint/tendermint/types" @@ -31,18 +28,6 @@ func GetRandomBlock(height uint64, nTxs int) *types.Block { return block } -func GetRandomTx() types.Tx { - n, _ := rand.Int(rand.Reader, big.NewInt(100)) - size := int(n.Int64()) + 100 - return types.Tx(GetRandomBytes(size)) -} - -func GetRandomBytes(n int) []byte { - data := make([]byte, n) - _, _ = rand.Read(data) - return data -} - // TODO(tzdybal): extract to some common place func GetRandomValidatorSet() *tmtypes.ValidatorSet { pubKey := ed25519.GenPrivKey().PubKey() diff --git a/testutil/types.go b/testutil/types.go index c4b9a3578..003576e94 100644 --- a/testutil/types.go +++ b/testutil/types.go @@ -2,6 +2,7 @@ package testutil import ( "crypto/rand" + "math/big" "time" "github.com/libp2p/go-libp2p/core/crypto" @@ -38,6 +39,18 @@ func createRandomHashes() [][32]byte { return h } +func GetRandomTx() types.Tx { + n, _ := rand.Int(rand.Reader, big.NewInt(100)) + size := int(n.Int64()) + 100 + return types.Tx(GetRandomBytes(size)) +} + +func GetRandomBytes(n int) []byte { + data := make([]byte, n) + _, _ = rand.Read(data) + return data +} + // GenerateBlocks generates random blocks. func generateBlock(height uint64) *types.Block { h := createRandomHashes()