From 6ae1dc10f0bf056ab15dc68a9cc5ceae6e4519e2 Mon Sep 17 00:00:00 2001 From: zale144 Date: Mon, 4 Nov 2024 18:34:13 +0100 Subject: [PATCH] feat: add GenesisChecksum to init chain (#1195) --- block/executor.go | 12 +- block/initchain.go | 2 +- block/manager.go | 32 ++-- block/manager_test.go | 6 +- cmd/dymint/commands/start.go | 38 +++++ go.mod | 2 +- go.sum | 4 +- .../dymint/block/mock_ExecutorI.go | 29 ++-- .../dymint/settlement/mock_ClientI.go | 114 +++++++------- .../dymensionxyz/dymint/store/mock_Store.go | 148 ++++++++++++++++-- node/node.go | 13 +- node/node_test.go | 5 +- rpc/client/client_test.go | 8 +- rpc/json/service_test.go | 2 + testutil/block.go | 10 +- testutil/node.go | 3 + 16 files changed, 302 insertions(+), 126 deletions(-) diff --git a/block/executor.go b/block/executor.go index 87f339278..6f6cfc71f 100644 --- a/block/executor.go +++ b/block/executor.go @@ -6,13 +6,14 @@ import ( proto2 "github.com/gogo/protobuf/proto" proto "github.com/gogo/protobuf/types" + "go.uber.org/multierr" + abci "github.com/tendermint/tendermint/abci/types" tmcrypto "github.com/tendermint/tendermint/crypto/encoding" tmstate "github.com/tendermint/tendermint/proto/tendermint/state" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/proxy" tmtypes "github.com/tendermint/tendermint/types" - "go.uber.org/multierr" "github.com/dymensionxyz/dymint/mempool" "github.com/dymensionxyz/dymint/types" @@ -22,7 +23,7 @@ import ( const minBlockMaxBytes = 10000 type ExecutorI interface { - InitChain(genesis *tmtypes.GenesisDoc, valset []*tmtypes.Validator) (*abci.ResponseInitChain, error) + InitChain(genesis *tmtypes.GenesisDoc, genesisChecksum string, valset []*tmtypes.Validator) (*abci.ResponseInitChain, error) CreateBlock(height uint64, lastCommit *types.Commit, lastHeaderHash, nextSeqHash [32]byte, state *types.State, maxBlockDataSizeBytes uint64) *types.Block Commit(state *types.State, block *types.Block, resp *tmstate.ABCIResponses) ([]byte, int64, error) GetAppInfo() (*abci.ResponseInfo, error) @@ -91,7 +92,7 @@ func (e *Executor) GetConsensusMsgs() []proto2.Message { } // InitChain calls InitChainSync using consensus connection to app. -func (e *Executor) InitChain(genesis *tmtypes.GenesisDoc, valset []*tmtypes.Validator) (*abci.ResponseInitChain, error) { +func (e *Executor) InitChain(genesis *tmtypes.GenesisDoc, genesisChecksum string, valset []*tmtypes.Validator) (*abci.ResponseInitChain, error) { valUpdates := abci.ValidatorUpdates{} // prepare the validator updates as expected by the ABCI app @@ -129,8 +130,9 @@ func (e *Executor) InitChain(genesis *tmtypes.GenesisDoc, valset []*tmtypes.Vali AppVersion: params.Version.AppVersion, }, }, Validators: valUpdates, - AppStateBytes: genesis.AppState, - InitialHeight: genesis.InitialHeight, + AppStateBytes: genesis.AppState, + InitialHeight: genesis.InitialHeight, + GenesisChecksum: genesisChecksum, }) } diff --git a/block/initchain.go b/block/initchain.go index 9e043ec01..f9c3659e2 100644 --- a/block/initchain.go +++ b/block/initchain.go @@ -18,7 +18,7 @@ func (m *Manager) RunInitChain(ctx context.Context) error { return errors.New("failed to get proposer") } tmProposer := proposer.TMValidator() - res, err := m.Executor.InitChain(m.Genesis, []*tmtypes.Validator{tmProposer}) + res, err := m.Executor.InitChain(m.Genesis, m.GenesisChecksum, []*tmtypes.Validator{tmProposer}) if err != nil { return err } diff --git a/block/manager.go b/block/manager.go index fdd9133a6..b4b2f455f 100644 --- a/block/manager.go +++ b/block/manager.go @@ -18,6 +18,7 @@ import ( "github.com/dymensionxyz/dymint/version" "github.com/libp2p/go-libp2p/core/crypto" + tmcrypto "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/pubsub" @@ -46,9 +47,10 @@ type Manager struct { logger types.Logger // Configuration - Conf config.BlockManagerConfig - Genesis *tmtypes.GenesisDoc - LocalKey crypto.PrivKey + Conf config.BlockManagerConfig + Genesis *tmtypes.GenesisDoc + GenesisChecksum string + LocalKey crypto.PrivKey // Store and execution Store store.Store @@ -118,6 +120,7 @@ func NewManager( localKey crypto.PrivKey, conf config.NodeConfig, genesis *tmtypes.GenesisDoc, + genesisChecksum string, store store.Store, mempool mempool.Mempool, proxyApp proxy.AppConns, @@ -147,17 +150,18 @@ func NewManager( } m := &Manager{ - Pubsub: pubsub, - P2PClient: p2pClient, - LocalKey: localKey, - Conf: conf.BlockManagerConfig, - Genesis: genesis, - Store: store, - Executor: exec, - Sequencers: types.NewSequencerSet(), - SLClient: settlementClient, - indexerService: indexerService, - logger: logger.With("module", "block_manager"), + Pubsub: pubsub, + P2PClient: p2pClient, + LocalKey: localKey, + Conf: conf.BlockManagerConfig, + Genesis: genesis, + GenesisChecksum: genesisChecksum, + Store: store, + Executor: exec, + Sequencers: types.NewSequencerSet(), + SLClient: settlementClient, + indexerService: indexerService, + logger: logger.With("module", "block_manager"), blockCache: &Cache{ cache: make(map[uint64]types.CachedBlock), }, diff --git a/block/manager_test.go b/block/manager_test.go index 0416c8d8b..47e48e6d3 100644 --- a/block/manager_test.go +++ b/block/manager_test.go @@ -114,7 +114,7 @@ func TestInitialState(t *testing.T) { for _, c := range cases { t.Run(c.name, func(t *testing.T) { - agg, err := block.NewManager(key, conf, c.genesis, c.store, nil, proxyApp, settlementlc, + agg, err := block.NewManager(key, conf, c.genesis, "", c.store, nil, proxyApp, settlementlc, nil, pubsubServer, p2pClient, nil, nil, logger) assert.NoError(err) assert.NotNil(agg) @@ -351,7 +351,7 @@ func TestApplyLocalBlock_WithFraudCheck(t *testing.T) { mockExecutor := &blockmocks.MockExecutorI{} manager.Executor = mockExecutor - mockExecutor.On("InitChain", mock.Anything, mock.Anything).Return(&abci.ResponseInitChain{}, nil) + mockExecutor.On("InitChain", mock.Anything, mock.Anything, mock.Anything).Return(&abci.ResponseInitChain{}, nil) mockExecutor.On("GetAppInfo").Return(&abci.ResponseInfo{ LastBlockHeight: int64(batch.EndHeight()), }, nil) @@ -810,7 +810,7 @@ func TestManager_ApplyBatchFromSL_FraudHandling(t *testing.T) { err = manager.SLClient.SubmitBatch(batch, manager.DAClient.GetClientType(), &daResultSubmitBatch) require.NoError(err) - //// Mock Executor to return ErrFraud + // Mock Executor to return ErrFraud mockExecutor := &blockmocks.MockExecutorI{} manager.Executor = mockExecutor mockExecutor.On("GetAppInfo").Return(&abci.ResponseInfo{ diff --git a/cmd/dymint/commands/start.go b/cmd/dymint/commands/start.go index 479f002c0..3bfa6e503 100644 --- a/cmd/dymint/commands/start.go +++ b/cmd/dymint/commands/start.go @@ -4,12 +4,17 @@ import ( "bytes" "context" "crypto/sha256" + "encoding/hex" + "encoding/json" "fmt" "io" "os" + "path/filepath" + "sort" "github.com/spf13/cobra" "github.com/spf13/viper" + tmcfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/log" @@ -87,6 +92,11 @@ func startInProcess(config *cfg.NodeConfig, tmConfig *tmcfg.Config, logger log.L } logger.Info("starting node with ABCI dymint in-process", "conf", config) + genesisChecksum, err := ComputeGenesisHash(tmConfig.GenesisFile()) + if err != nil { + return fmt.Errorf("failed to compute genesis checksum: %w", err) + } + dymintNode, err := node.NewNode( context.Background(), *config, @@ -94,6 +104,7 @@ func startInProcess(config *cfg.NodeConfig, tmConfig *tmcfg.Config, logger log.L signingKey, proxy.DefaultClientCreator(tmConfig.ProxyApp, tmConfig.ABCI, tmConfig.DBDir()), genesis, + genesisChecksum, logger, mempool.PrometheusMetrics("dymint"), ) @@ -162,3 +173,30 @@ func checkGenesisHash(config *tmcfg.Config) error { return nil } + +func ComputeGenesisHash(genesisFilePath string) (string, error) { + fileContent, err := os.ReadFile(filepath.Clean(genesisFilePath)) + if err != nil { + return "", err + } + + var jsonObject map[string]interface{} + err = json.Unmarshal(fileContent, &jsonObject) + if err != nil { + return "", err + } + + keys := make([]string, 0, len(jsonObject)) + for k := range jsonObject { + keys = append(keys, k) + } + sort.Strings(keys) + + sortedJSON, err := json.Marshal(jsonObject) + if err != nil { + return "", err + } + + hash := sha256.Sum256(sortedJSON) + return hex.EncodeToString(hash[:]), nil +} diff --git a/go.mod b/go.mod index 83c11b171..d4ca9700e 100644 --- a/go.mod +++ b/go.mod @@ -300,7 +300,7 @@ replace ( github.com/evmos/evmos/v12 => github.com/dymensionxyz/evmos/v12 v12.1.6-dymension-v0.3 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4 github.com/gorilla/rpc => github.com/dymensionxyz/rpc v1.3.1 - github.com/tendermint/tendermint => github.com/dymensionxyz/cometbft v0.34.29-0.20241030154748-3f9dfa21d17b + github.com/tendermint/tendermint => github.com/dymensionxyz/cometbft v0.34.29-0.20241104165035-feade34f8f89 ) replace github.com/osmosis-labs/osmosis/v15 => github.com/dymensionxyz/osmosis/v15 v15.2.0-dymension-v1.1.2 diff --git a/go.sum b/go.sum index 3a6302a79..839bf72b0 100644 --- a/go.sum +++ b/go.sum @@ -457,8 +457,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQxaLAeM= github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU= -github.com/dymensionxyz/cometbft v0.34.29-0.20241030154748-3f9dfa21d17b h1:rxkH+9cBG2nnReMavb2FqQXwDLjKcz0/KB8/6SV5Xlo= -github.com/dymensionxyz/cometbft v0.34.29-0.20241030154748-3f9dfa21d17b/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw= +github.com/dymensionxyz/cometbft v0.34.29-0.20241104165035-feade34f8f89 h1:rGkCcx4dWX9mxAUrq7zrdOc44XddMY/nM6kqYTWjerY= +github.com/dymensionxyz/cometbft v0.34.29-0.20241104165035-feade34f8f89/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw= github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20240821081230-b4018b2bac13 h1:u5yeve5jZR6TdRjjR+vYT/8PWKbhwCZxUmAu+/Tnxyg= github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20240821081230-b4018b2bac13/go.mod h1:jabDQYXrccscSE0fXkh7eQFYPWJCRiuWKonFGObVq6s= github.com/dymensionxyz/evmos/v12 v12.1.6-dymension-v0.3 h1:vmAdUGUc4rTIiO3Phezr7vGq+0uPDVKSA4WAe8+yl6w= diff --git a/mocks/github.com/dymensionxyz/dymint/block/mock_ExecutorI.go b/mocks/github.com/dymensionxyz/dymint/block/mock_ExecutorI.go index 4a1265c4a..4dcbd3213 100644 --- a/mocks/github.com/dymensionxyz/dymint/block/mock_ExecutorI.go +++ b/mocks/github.com/dymensionxyz/dymint/block/mock_ExecutorI.go @@ -357,9 +357,9 @@ func (_c *MockExecutorI_GetConsensusMsgs_Call) RunAndReturn(run func() []proto.M return _c } -// InitChain provides a mock function with given fields: genesis, valset -func (_m *MockExecutorI) InitChain(genesis *tenderminttypes.GenesisDoc, valset []*tenderminttypes.Validator) (*abcitypes.ResponseInitChain, error) { - ret := _m.Called(genesis, valset) +// InitChain provides a mock function with given fields: genesis, genesisChecksum, valset +func (_m *MockExecutorI) InitChain(genesis *tenderminttypes.GenesisDoc, genesisChecksum string, valset []*tenderminttypes.Validator) (*abcitypes.ResponseInitChain, error) { + ret := _m.Called(genesis, genesisChecksum, valset) if len(ret) == 0 { panic("no return value specified for InitChain") @@ -367,19 +367,19 @@ func (_m *MockExecutorI) InitChain(genesis *tenderminttypes.GenesisDoc, valset [ var r0 *abcitypes.ResponseInitChain var r1 error - if rf, ok := ret.Get(0).(func(*tenderminttypes.GenesisDoc, []*tenderminttypes.Validator) (*abcitypes.ResponseInitChain, error)); ok { - return rf(genesis, valset) + if rf, ok := ret.Get(0).(func(*tenderminttypes.GenesisDoc, string, []*tenderminttypes.Validator) (*abcitypes.ResponseInitChain, error)); ok { + return rf(genesis, genesisChecksum, valset) } - if rf, ok := ret.Get(0).(func(*tenderminttypes.GenesisDoc, []*tenderminttypes.Validator) *abcitypes.ResponseInitChain); ok { - r0 = rf(genesis, valset) + if rf, ok := ret.Get(0).(func(*tenderminttypes.GenesisDoc, string, []*tenderminttypes.Validator) *abcitypes.ResponseInitChain); ok { + r0 = rf(genesis, genesisChecksum, valset) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*abcitypes.ResponseInitChain) } } - if rf, ok := ret.Get(1).(func(*tenderminttypes.GenesisDoc, []*tenderminttypes.Validator) error); ok { - r1 = rf(genesis, valset) + if rf, ok := ret.Get(1).(func(*tenderminttypes.GenesisDoc, string, []*tenderminttypes.Validator) error); ok { + r1 = rf(genesis, genesisChecksum, valset) } else { r1 = ret.Error(1) } @@ -394,14 +394,15 @@ type MockExecutorI_InitChain_Call struct { // InitChain is a helper method to define mock.On call // - genesis *tenderminttypes.GenesisDoc +// - genesisChecksum string // - valset []*tenderminttypes.Validator -func (_e *MockExecutorI_Expecter) InitChain(genesis interface{}, valset interface{}) *MockExecutorI_InitChain_Call { - return &MockExecutorI_InitChain_Call{Call: _e.mock.On("InitChain", genesis, valset)} +func (_e *MockExecutorI_Expecter) InitChain(genesis interface{}, genesisChecksum interface{}, valset interface{}) *MockExecutorI_InitChain_Call { + return &MockExecutorI_InitChain_Call{Call: _e.mock.On("InitChain", genesis, genesisChecksum, valset)} } -func (_c *MockExecutorI_InitChain_Call) Run(run func(genesis *tenderminttypes.GenesisDoc, valset []*tenderminttypes.Validator)) *MockExecutorI_InitChain_Call { +func (_c *MockExecutorI_InitChain_Call) Run(run func(genesis *tenderminttypes.GenesisDoc, genesisChecksum string, valset []*tenderminttypes.Validator)) *MockExecutorI_InitChain_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*tenderminttypes.GenesisDoc), args[1].([]*tenderminttypes.Validator)) + run(args[0].(*tenderminttypes.GenesisDoc), args[1].(string), args[2].([]*tenderminttypes.Validator)) }) return _c } @@ -411,7 +412,7 @@ func (_c *MockExecutorI_InitChain_Call) Return(_a0 *abcitypes.ResponseInitChain, return _c } -func (_c *MockExecutorI_InitChain_Call) RunAndReturn(run func(*tenderminttypes.GenesisDoc, []*tenderminttypes.Validator) (*abcitypes.ResponseInitChain, error)) *MockExecutorI_InitChain_Call { +func (_c *MockExecutorI_InitChain_Call) RunAndReturn(run func(*tenderminttypes.GenesisDoc, string, []*tenderminttypes.Validator) (*abcitypes.ResponseInitChain, error)) *MockExecutorI_InitChain_Call { _c.Call.Return(run) return _c } diff --git a/mocks/github.com/dymensionxyz/dymint/settlement/mock_ClientI.go b/mocks/github.com/dymensionxyz/dymint/settlement/mock_ClientI.go index 8aae5c592..ad870557c 100644 --- a/mocks/github.com/dymensionxyz/dymint/settlement/mock_ClientI.go +++ b/mocks/github.com/dymensionxyz/dymint/settlement/mock_ClientI.go @@ -26,63 +26,6 @@ func (_m *MockClientI) EXPECT() *MockClientI_Expecter { return &MockClientI_Expecter{mock: &_m.Mock} } -// GetNextProposer provides a mock function with given fields: -func (_m *MockClientI) GetNextProposer() (*types.Sequencer, error) { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for GetNextProposer") - } - - var r0 *types.Sequencer - var r1 error - if rf, ok := ret.Get(0).(func() (*types.Sequencer, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() *types.Sequencer); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Sequencer) - } - } - - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockClientI_GetNextProposer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNextProposer' -type MockClientI_GetNextProposer_Call struct { - *mock.Call -} - -// GetNextProposer is a helper method to define mock.On call -func (_e *MockClientI_Expecter) GetNextProposer() *MockClientI_GetNextProposer_Call { - return &MockClientI_GetNextProposer_Call{Call: _e.mock.On("GetNextProposer")} -} - -func (_c *MockClientI_GetNextProposer_Call) Run(run func()) *MockClientI_GetNextProposer_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *MockClientI_GetNextProposer_Call) Return(_a0 *types.Sequencer, _a1 error) *MockClientI_GetNextProposer_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockClientI_GetNextProposer_Call) RunAndReturn(run func() (*types.Sequencer, error)) *MockClientI_GetNextProposer_Call { - _c.Call.Return(run) - return _c -} - // GetAllSequencers provides a mock function with given fields: func (_m *MockClientI) GetAllSequencers() ([]types.Sequencer, error) { ret := _m.Called() @@ -480,6 +423,63 @@ func (_c *MockClientI_GetLatestHeight_Call) RunAndReturn(run func() (uint64, err return _c } +// GetNextProposer provides a mock function with given fields: +func (_m *MockClientI) GetNextProposer() (*types.Sequencer, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetNextProposer") + } + + var r0 *types.Sequencer + var r1 error + if rf, ok := ret.Get(0).(func() (*types.Sequencer, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *types.Sequencer); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Sequencer) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockClientI_GetNextProposer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNextProposer' +type MockClientI_GetNextProposer_Call struct { + *mock.Call +} + +// GetNextProposer is a helper method to define mock.On call +func (_e *MockClientI_Expecter) GetNextProposer() *MockClientI_GetNextProposer_Call { + return &MockClientI_GetNextProposer_Call{Call: _e.mock.On("GetNextProposer")} +} + +func (_c *MockClientI_GetNextProposer_Call) Run(run func()) *MockClientI_GetNextProposer_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockClientI_GetNextProposer_Call) Return(_a0 *types.Sequencer, _a1 error) *MockClientI_GetNextProposer_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockClientI_GetNextProposer_Call) RunAndReturn(run func() (*types.Sequencer, error)) *MockClientI_GetNextProposer_Call { + _c.Call.Return(run) + return _c +} + // GetProposer provides a mock function with given fields: func (_m *MockClientI) GetProposerAtHeight(height int64) (*types.Sequencer, error) { ret := _m.Called(height) diff --git a/mocks/github.com/dymensionxyz/dymint/store/mock_Store.go b/mocks/github.com/dymensionxyz/dymint/store/mock_Store.go index 0432de012..764f4e340 100644 --- a/mocks/github.com/dymensionxyz/dymint/store/mock_Store.go +++ b/mocks/github.com/dymensionxyz/dymint/store/mock_Store.go @@ -473,25 +473,79 @@ func (_c *MockStore_LoadCommitByHash_Call) RunAndReturn(run func([32]byte) (*typ return _c } +// LoadDRSVersion provides a mock function with given fields: height +func (_m *MockStore) LoadDRSVersion(height uint64) (uint32, error) { + ret := _m.Called(height) + + if len(ret) == 0 { + panic("no return value specified for LoadDRSVersion") + } + + var r0 uint32 + var r1 error + if rf, ok := ret.Get(0).(func(uint64) (uint32, error)); ok { + return rf(height) + } + if rf, ok := ret.Get(0).(func(uint64) uint32); ok { + r0 = rf(height) + } else { + r0 = ret.Get(0).(uint32) + } + + if rf, ok := ret.Get(1).(func(uint64) error); ok { + r1 = rf(height) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStore_LoadDRSVersion_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadDRSVersion' +type MockStore_LoadDRSVersion_Call struct { + *mock.Call +} + +// LoadDRSVersion is a helper method to define mock.On call +// - height uint64 +func (_e *MockStore_Expecter) LoadDRSVersion(height interface{}) *MockStore_LoadDRSVersion_Call { + return &MockStore_LoadDRSVersion_Call{Call: _e.mock.On("LoadDRSVersion", height)} +} + +func (_c *MockStore_LoadDRSVersion_Call) Run(run func(height uint64)) *MockStore_LoadDRSVersion_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint64)) + }) + return _c +} + +func (_c *MockStore_LoadDRSVersion_Call) Return(_a0 uint32, _a1 error) *MockStore_LoadDRSVersion_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockStore_LoadDRSVersion_Call) RunAndReturn(run func(uint64) (uint32, error)) *MockStore_LoadDRSVersion_Call { + _c.Call.Return(run) + return _c +} + // LoadProposer provides a mock function with given fields: height -func (_m *MockStore) LoadProposer(height uint64) (*types.Sequencer, error) { +func (_m *MockStore) LoadProposer(height uint64) (types.Sequencer, error) { ret := _m.Called(height) if len(ret) == 0 { panic("no return value specified for LoadProposer") } - var r0 *types.Sequencer + var r0 types.Sequencer var r1 error - if rf, ok := ret.Get(0).(func(uint64) (*types.Sequencer, error)); ok { + if rf, ok := ret.Get(0).(func(uint64) (types.Sequencer, error)); ok { return rf(height) } - if rf, ok := ret.Get(0).(func(uint64) *types.Sequencer); ok { + if rf, ok := ret.Get(0).(func(uint64) types.Sequencer); ok { r0 = rf(height) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Sequencer) - } + r0 = ret.Get(0).(types.Sequencer) } if rf, ok := ret.Get(1).(func(uint64) error); ok { @@ -521,12 +575,12 @@ func (_c *MockStore_LoadProposer_Call) Run(run func(height uint64)) *MockStore_L return _c } -func (_c *MockStore_LoadProposer_Call) Return(_a0 *types.Sequencer, _a1 error) *MockStore_LoadProposer_Call { +func (_c *MockStore_LoadProposer_Call) Return(_a0 types.Sequencer, _a1 error) *MockStore_LoadProposer_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *MockStore_LoadProposer_Call) RunAndReturn(run func(uint64) (*types.Sequencer, error)) *MockStore_LoadProposer_Call { +func (_c *MockStore_LoadProposer_Call) RunAndReturn(run func(uint64) (types.Sequencer, error)) *MockStore_LoadProposer_Call { _c.Call.Return(run) return _c } @@ -988,8 +1042,68 @@ func (_c *MockStore_SaveBlockSource_Call) RunAndReturn(run func(uint64, types.Bl return _c } +// SaveDRSVersion provides a mock function with given fields: height, version, batch +func (_m *MockStore) SaveDRSVersion(height uint64, version uint32, batch store.KVBatch) (store.KVBatch, error) { + ret := _m.Called(height, version, batch) + + if len(ret) == 0 { + panic("no return value specified for SaveDRSVersion") + } + + var r0 store.KVBatch + var r1 error + if rf, ok := ret.Get(0).(func(uint64, uint32, store.KVBatch) (store.KVBatch, error)); ok { + return rf(height, version, batch) + } + if rf, ok := ret.Get(0).(func(uint64, uint32, store.KVBatch) store.KVBatch); ok { + r0 = rf(height, version, batch) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(store.KVBatch) + } + } + + if rf, ok := ret.Get(1).(func(uint64, uint32, store.KVBatch) error); ok { + r1 = rf(height, version, batch) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStore_SaveDRSVersion_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveDRSVersion' +type MockStore_SaveDRSVersion_Call struct { + *mock.Call +} + +// SaveDRSVersion is a helper method to define mock.On call +// - height uint64 +// - version uint32 +// - batch store.KVBatch +func (_e *MockStore_Expecter) SaveDRSVersion(height interface{}, version interface{}, batch interface{}) *MockStore_SaveDRSVersion_Call { + return &MockStore_SaveDRSVersion_Call{Call: _e.mock.On("SaveDRSVersion", height, version, batch)} +} + +func (_c *MockStore_SaveDRSVersion_Call) Run(run func(height uint64, version uint32, batch store.KVBatch)) *MockStore_SaveDRSVersion_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint64), args[1].(uint32), args[2].(store.KVBatch)) + }) + return _c +} + +func (_c *MockStore_SaveDRSVersion_Call) Return(_a0 store.KVBatch, _a1 error) *MockStore_SaveDRSVersion_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockStore_SaveDRSVersion_Call) RunAndReturn(run func(uint64, uint32, store.KVBatch) (store.KVBatch, error)) *MockStore_SaveDRSVersion_Call { + _c.Call.Return(run) + return _c +} + // SaveProposer provides a mock function with given fields: height, proposer, batch -func (_m *MockStore) SaveProposer(height uint64, proposer *types.Sequencer, batch store.KVBatch) (store.KVBatch, error) { +func (_m *MockStore) SaveProposer(height uint64, proposer types.Sequencer, batch store.KVBatch) (store.KVBatch, error) { ret := _m.Called(height, proposer, batch) if len(ret) == 0 { @@ -998,10 +1112,10 @@ func (_m *MockStore) SaveProposer(height uint64, proposer *types.Sequencer, batc var r0 store.KVBatch var r1 error - if rf, ok := ret.Get(0).(func(uint64, *types.Sequencer, store.KVBatch) (store.KVBatch, error)); ok { + if rf, ok := ret.Get(0).(func(uint64, types.Sequencer, store.KVBatch) (store.KVBatch, error)); ok { return rf(height, proposer, batch) } - if rf, ok := ret.Get(0).(func(uint64, *types.Sequencer, store.KVBatch) store.KVBatch); ok { + if rf, ok := ret.Get(0).(func(uint64, types.Sequencer, store.KVBatch) store.KVBatch); ok { r0 = rf(height, proposer, batch) } else { if ret.Get(0) != nil { @@ -1009,7 +1123,7 @@ func (_m *MockStore) SaveProposer(height uint64, proposer *types.Sequencer, batc } } - if rf, ok := ret.Get(1).(func(uint64, *types.Sequencer, store.KVBatch) error); ok { + if rf, ok := ret.Get(1).(func(uint64, types.Sequencer, store.KVBatch) error); ok { r1 = rf(height, proposer, batch) } else { r1 = ret.Error(1) @@ -1025,15 +1139,15 @@ type MockStore_SaveProposer_Call struct { // SaveProposer is a helper method to define mock.On call // - height uint64 -// - proposer *types.Sequencer +// - proposer types.Sequencer // - batch store.KVBatch func (_e *MockStore_Expecter) SaveProposer(height interface{}, proposer interface{}, batch interface{}) *MockStore_SaveProposer_Call { return &MockStore_SaveProposer_Call{Call: _e.mock.On("SaveProposer", height, proposer, batch)} } -func (_c *MockStore_SaveProposer_Call) Run(run func(height uint64, proposer *types.Sequencer, batch store.KVBatch)) *MockStore_SaveProposer_Call { +func (_c *MockStore_SaveProposer_Call) Run(run func(height uint64, proposer types.Sequencer, batch store.KVBatch)) *MockStore_SaveProposer_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(uint64), args[1].(*types.Sequencer), args[2].(store.KVBatch)) + run(args[0].(uint64), args[1].(types.Sequencer), args[2].(store.KVBatch)) }) return _c } @@ -1043,7 +1157,7 @@ func (_c *MockStore_SaveProposer_Call) Return(_a0 store.KVBatch, _a1 error) *Moc return _c } -func (_c *MockStore_SaveProposer_Call) RunAndReturn(run func(uint64, *types.Sequencer, store.KVBatch) (store.KVBatch, error)) *MockStore_SaveProposer_Call { +func (_c *MockStore_SaveProposer_Call) RunAndReturn(run func(uint64, types.Sequencer, store.KVBatch) (store.KVBatch, error)) *MockStore_SaveProposer_Call { _c.Call.Return(run) return _c } diff --git a/node/node.go b/node/node.go index 1dea5dcf0..f0f1a88e5 100644 --- a/node/node.go +++ b/node/node.go @@ -13,6 +13,12 @@ import ( "github.com/libp2p/go-libp2p/core/crypto" + "github.com/tendermint/tendermint/libs/log" + "github.com/tendermint/tendermint/libs/pubsub" + "github.com/tendermint/tendermint/libs/service" + "github.com/tendermint/tendermint/proxy" + tmtypes "github.com/tendermint/tendermint/types" + "github.com/dymensionxyz/dymint/block" "github.com/dymensionxyz/dymint/config" indexer "github.com/dymensionxyz/dymint/indexers/blockindexer" @@ -26,11 +32,6 @@ import ( "github.com/dymensionxyz/dymint/settlement" slregistry "github.com/dymensionxyz/dymint/settlement/registry" "github.com/dymensionxyz/dymint/store" - "github.com/tendermint/tendermint/libs/log" - "github.com/tendermint/tendermint/libs/pubsub" - "github.com/tendermint/tendermint/libs/service" - "github.com/tendermint/tendermint/proxy" - tmtypes "github.com/tendermint/tendermint/types" ) // prefixes used in KV store to separate main node data from DALC data @@ -80,6 +81,7 @@ func NewNode( signingKey crypto.PrivKey, clientCreator proxy.ClientCreator, genesis *tmtypes.GenesisDoc, + genesisChecksum string, logger log.Logger, metrics *mempool.Metrics, ) (*Node, error) { @@ -152,6 +154,7 @@ func NewNode( signingKey, conf, genesis, + genesisChecksum, s, mp, proxyApp, diff --git a/node/node_test.go b/node/node_test.go index 7b0a1e816..57aecf762 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -17,13 +17,15 @@ import ( "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/proxy" + tmcfg "github.com/tendermint/tendermint/config" + "github.com/dymensionxyz/dymint/config" tmmocks "github.com/dymensionxyz/dymint/mocks/github.com/tendermint/tendermint/abci/types" - tmcfg "github.com/tendermint/tendermint/config" ) // simply check that node is starting and stopping without panicking @@ -89,6 +91,7 @@ func TestMempoolDirectly(t *testing.T) { signingKey, proxy.NewLocalClientCreator(app), testutil.GenerateGenesis(0), + "", log.TestingLogger(), mempool.NopMetrics(), ) diff --git a/rpc/client/client_test.go b/rpc/client/client_test.go index f005b1ae5..afb1a915c 100644 --- a/rpc/client/client_test.go +++ b/rpc/client/client_test.go @@ -18,6 +18,7 @@ import ( "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" + abci "github.com/tendermint/tendermint/abci/types" tmcrypto "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" @@ -120,6 +121,7 @@ func TestGenesisChunked(t *testing.T) { signingKey, proxy.NewLocalClientCreator(mockApp), genDoc, + "", log.TestingLogger(), mempool.NopMetrics(), ) @@ -868,6 +870,7 @@ func TestValidatorSetHandling(t *testing.T) { signingKey, proxy.NewLocalClientCreator(app), testutil.GenerateGenesis(0), + "", log.TestingLogger(), mempool.NopMetrics(), ) @@ -1030,6 +1033,7 @@ func getRPCInternal(t *testing.T, sequencer bool) (*tmmocks.MockApplication, *cl localKey, // this is where sequencer mode is set. if same key as in settlement.Config, it's sequencer proxy.NewLocalClientCreator(app), testutil.GenerateGenesis(0), + "", log.TestingLogger(), mempool.NopMetrics(), ) @@ -1123,7 +1127,7 @@ func TestMempool2Nodes(t *testing.T) { BatchSkew: 10, }, MempoolConfig: *tmcfg.DefaultMempoolConfig(), - }, key1, signingKey1, proxy.NewLocalClientCreator(app), genesis, log.TestingLogger(), mempool.NopMetrics()) + }, key1, signingKey1, proxy.NewLocalClientCreator(app), genesis, "", log.TestingLogger(), mempool.NopMetrics()) require.NoError(err) require.NotNil(node1) @@ -1146,7 +1150,7 @@ func TestMempool2Nodes(t *testing.T) { BlockSyncRequestIntervalTime: 30 * time.Second, }, MempoolConfig: *tmcfg.DefaultMempoolConfig(), - }, key2, signingKey2, proxy.NewLocalClientCreator(app), genesis, log.TestingLogger(), mempool.NopMetrics()) + }, key2, signingKey2, proxy.NewLocalClientCreator(app), genesis, "", log.TestingLogger(), mempool.NopMetrics()) require.NoError(err) require.NotNil(node1) diff --git a/rpc/json/service_test.go b/rpc/json/service_test.go index 37f532266..41500d1ad 100644 --- a/rpc/json/service_test.go +++ b/rpc/json/service_test.go @@ -20,6 +20,7 @@ import ( "github.com/gorilla/rpc/v2/json2" "github.com/libp2p/go-libp2p/core/crypto" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/proxy" @@ -337,6 +338,7 @@ func getRPC(t *testing.T) (*tmmocks.MockApplication, *client.Client) { signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: rollappID, AppState: []byte("{\"rollappparams\": {\"params\": {\"da\": \"mock\",\"version\": 1}}}")}, + "", log.TestingLogger(), mempool.NopMetrics(), ) diff --git a/testutil/block.go b/testutil/block.go index 67017a01b..58d13eb97 100644 --- a/testutil/block.go +++ b/testutil/block.go @@ -6,19 +6,22 @@ import ( "encoding/hex" "time" + "github.com/ipfs/go-datastore" + "github.com/libp2p/go-libp2p/core/crypto" + "github.com/dymensionxyz/dymint/block" "github.com/dymensionxyz/dymint/indexers/txindex" "github.com/dymensionxyz/dymint/indexers/txindex/kv" "github.com/dymensionxyz/dymint/p2p" "github.com/dymensionxyz/dymint/settlement" - "github.com/ipfs/go-datastore" - "github.com/libp2p/go-libp2p/core/crypto" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/pubsub" "github.com/tendermint/tendermint/proxy" + tmcfg "github.com/tendermint/tendermint/config" + "github.com/dymensionxyz/dymint/config" "github.com/dymensionxyz/dymint/da" localda "github.com/dymensionxyz/dymint/da/local" @@ -27,7 +30,6 @@ import ( nodemempool "github.com/dymensionxyz/dymint/node/mempool" slregistry "github.com/dymensionxyz/dymint/settlement/registry" "github.com/dymensionxyz/dymint/store" - tmcfg "github.com/tendermint/tendermint/config" ) const ( @@ -114,7 +116,7 @@ func GetManagerWithProposerKey(conf config.BlockManagerConfig, proposerKey crypt return nil, err } - manager, err := block.NewManager(proposerKey, config, genesis, managerStore, mp, proxyApp, settlementlc, nil, + manager, err := block.NewManager(proposerKey, config, genesis, "", managerStore, mp, proxyApp, settlementlc, nil, pubsubServer, p2pClient, nil, indexer, logger) if err != nil { return nil, err diff --git a/testutil/node.go b/testutil/node.go index 0abce0cf9..2c8d88d0c 100644 --- a/testutil/node.go +++ b/testutil/node.go @@ -7,11 +7,13 @@ import ( "time" "github.com/libp2p/go-libp2p/core/crypto" + "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/types" "github.com/stretchr/testify/mock" + abci "github.com/tendermint/tendermint/abci/types" "github.com/dymensionxyz/dymint/config" @@ -69,6 +71,7 @@ func CreateNode(isSequencer bool, blockManagerConfig *config.BlockManagerConfig, signingKey, proxy.NewLocalClientCreator(app), genesis, + "", log.TestingLogger(), mempool.NopMetrics(), )