From f87c0d6bc2654fd578e227dff1c8de6cb2ba86a3 Mon Sep 17 00:00:00 2001 From: dustinxie Date: Tue, 25 Mar 2025 17:58:13 -0700 Subject: [PATCH] [blockindex] sync indexers to keep sync with master --- blockchain/blockdao/blockindexer.go | 23 +- blockindex/contractstaking/indexer.go | 4 + blockindex/sync_indexers.go | 81 +++---- blockindex/sync_indexers_test.go | 220 +++--------------- chainservice/builder.go | 8 +- misc/scripts/mockgen.sh | 4 +- systemcontractindex/common.go | 4 + .../mock_blockindexer_withactive.go | 107 +++++++++ .../mock_blockindexer_withstart.go | 107 --------- test/mock/mock_dispatcher/mock_dispatcher.go | 15 ++ 10 files changed, 211 insertions(+), 362 deletions(-) create mode 100644 test/mock/mock_blockdao/mock_blockindexer_withactive.go delete mode 100644 test/mock/mock_blockdao/mock_blockindexer_withstart.go diff --git a/blockchain/blockdao/blockindexer.go b/blockchain/blockdao/blockindexer.go index 7b3d40c3a1..b9ade75544 100644 --- a/blockchain/blockdao/blockindexer.go +++ b/blockchain/blockdao/blockindexer.go @@ -27,11 +27,11 @@ type ( PutBlock(context.Context, *block.Block) error } - // BlockIndexerWithStart defines an interface to accept block to build index from a start height - BlockIndexerWithStart interface { + // BlockIndexerWithActive tells if an indexer is activated + BlockIndexerWithActive interface { BlockIndexer - // StartHeight returns the start height of the indexer - StartHeight() uint64 + // IsActive indicates if the index is activated (passed its start height) + IsActive() bool } // BlockIndexerChecker defines a checker of block indexer @@ -55,7 +55,7 @@ func (bic *BlockIndexerChecker) CheckIndexer(ctx context.Context, indexer BlockI if !ok { return errors.New("failed to find genesis ctx") } - tipHeight, err := indexer.Height() + indexTip, err := indexer.Height() if err != nil { return err } @@ -63,24 +63,17 @@ func (bic *BlockIndexerChecker) CheckIndexer(ctx context.Context, indexer BlockI if err != nil { return err } - if tipHeight > daoTip { + if indexTip > daoTip { return errors.New("indexer tip height cannot by higher than dao tip height") } - tipBlk, err := bic.dao.GetBlockByHeight(tipHeight) + tipBlk, err := bic.dao.GetBlockByHeight(indexTip) if err != nil { return err } if targetHeight == 0 || targetHeight > daoTip { targetHeight = daoTip } - startHeight := tipHeight + 1 - if indexerWS, ok := indexer.(BlockIndexerWithStart); ok { - indexStartHeight := indexerWS.StartHeight() - if indexStartHeight > startHeight { - startHeight = indexStartHeight - } - } - for i := startHeight; i <= targetHeight; i++ { + for i := indexTip + 1; i <= targetHeight; i++ { // ternimate if context is done if err := ctx.Err(); err != nil { return errors.Wrap(err, "terminate the indexer checking") diff --git a/blockindex/contractstaking/indexer.go b/blockindex/contractstaking/indexer.go index f3ae9ea560..2927dec349 100644 --- a/blockindex/contractstaking/indexer.go +++ b/blockindex/contractstaking/indexer.go @@ -92,6 +92,10 @@ func (s *Indexer) StartHeight() uint64 { return s.config.ContractDeployHeight } +func (s *Indexer) IsActive() bool { + return s.cache.Height() > s.config.ContractDeployHeight +} + // ContractAddress returns the contract address func (s *Indexer) ContractAddress() string { return s.config.ContractAddress diff --git a/blockindex/sync_indexers.go b/blockindex/sync_indexers.go index f35cc6247f..bd2ee2fc9f 100644 --- a/blockindex/sync_indexers.go +++ b/blockindex/sync_indexers.go @@ -8,36 +8,49 @@ package blockindex import ( "context" + "github.com/pkg/errors" + "github.com/iotexproject/iotex-core/v2/blockchain/block" "github.com/iotexproject/iotex-core/v2/blockchain/blockdao" ) -// SyncIndexers is a special index that includes multiple indexes, +var ( + ErrNotSychronized = errors.New("indexers are not synchronized") +) + +// SyncIndexers is a special index that includes a master and multiple indexes, // which stay in sync when blocks are added. type SyncIndexers struct { - indexers []blockdao.BlockIndexer - startHeights []uint64 // start height of each indexer, which will be determined when the indexer is started - minStartHeight uint64 // minimum start height of all indexers + master blockdao.BlockIndexer + indexers []blockdao.BlockIndexer } // NewSyncIndexers creates a new SyncIndexers // each indexer will PutBlock one by one in the order of the indexers -func NewSyncIndexers(indexers ...blockdao.BlockIndexer) *SyncIndexers { - return &SyncIndexers{indexers: indexers} +func NewSyncIndexers(master blockdao.BlockIndexer, indexers ...blockdao.BlockIndexer) *SyncIndexers { + return &SyncIndexers{ + master: master, + indexers: indexers} } // Start starts the indexer group func (ig *SyncIndexers) Start(ctx context.Context) error { + if err := ig.master.Start(ctx); err != nil { + return err + } for _, indexer := range ig.indexers { if err := indexer.Start(ctx); err != nil { return err } } - return ig.initStartHeight() + return ig.checkSync() } // Stop stops the indexer group func (ig *SyncIndexers) Stop(ctx context.Context) error { + if err := ig.master.Stop(ctx); err != nil { + return err + } for _, indexer := range ig.indexers { if err := indexer.Stop(ctx); err != nil { return err @@ -48,17 +61,13 @@ func (ig *SyncIndexers) Stop(ctx context.Context) error { // PutBlock puts a block into the indexers in the group func (ig *SyncIndexers) PutBlock(ctx context.Context, blk *block.Block) error { - for i, indexer := range ig.indexers { - // check if the block is higher than the indexer's start height - if blk.Height() < ig.startHeights[i] { - continue - } - // check if the block is higher than the indexer's height + for _, indexer := range ig.indexers { height, err := indexer.Height() if err != nil { return err } if blk.Height() <= height { + // if the block is lower than the indexer's height, do nothing continue } // put block @@ -69,46 +78,28 @@ func (ig *SyncIndexers) PutBlock(ctx context.Context, blk *block.Block) error { return nil } -// StartHeight returns the minimum start height of the indexers in the group -func (ig *SyncIndexers) StartHeight() uint64 { - return ig.minStartHeight -} - -// Height returns the minimum height of the indexers in the group +// Height returns the height of the indexers in the group +// which must be same as master's func (ig *SyncIndexers) Height() (uint64, error) { - var height uint64 - for i, indexer := range ig.indexers { - h, err := indexer.Height() - if err != nil { - return 0, err - } - if i == 0 || h < height { - height = h - } - } - return height, nil + return ig.master.Height() } -// initStartHeight initializes the start height of the indexers in the group -// for every indexer, the start height is the maximum of tipheight+1 and startheight -func (ig *SyncIndexers) initStartHeight() error { - ig.minStartHeight = 0 - ig.startHeights = make([]uint64, len(ig.indexers)) +func (ig *SyncIndexers) checkSync() error { + masterHeight, err := ig.master.Height() + if err != nil { + return err + } + // all other indexers must have same height as master to be in-sync for i, indexer := range ig.indexers { + if start, ok := indexer.(interface{ IsActive() bool }); ok && !start.IsActive() { + continue + } tipHeight, err := indexer.Height() if err != nil { return err } - indexStartHeight := tipHeight + 1 - if indexerWithStart, ok := indexer.(blockdao.BlockIndexerWithStart); ok { - startHeight := indexerWithStart.StartHeight() - if startHeight > indexStartHeight { - indexStartHeight = startHeight - } - } - ig.startHeights[i] = indexStartHeight - if i == 0 || indexStartHeight < ig.minStartHeight { - ig.minStartHeight = indexStartHeight + if tipHeight != masterHeight { + return errors.Wrapf(ErrNotSychronized, "indexer %d, expecting height = %d, actual height = %d", i, masterHeight, tipHeight) } } return nil diff --git a/blockindex/sync_indexers_test.go b/blockindex/sync_indexers_test.go index 7c2368ec66..d560197834 100644 --- a/blockindex/sync_indexers_test.go +++ b/blockindex/sync_indexers_test.go @@ -7,212 +7,54 @@ package blockindex import ( "context" - "strconv" "testing" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - "github.com/iotexproject/iotex-core/v2/blockchain/block" "github.com/iotexproject/iotex-core/v2/blockchain/blockdao" - "github.com/iotexproject/iotex-core/v2/test/identityset" "github.com/iotexproject/iotex-core/v2/test/mock/mock_blockdao" ) -func TestSyncIndexers_StartHeight(t *testing.T) { - require := require.New(t) +func TestSyncIndexers_CheckSync(t *testing.T) { + r := require.New(t) ctrl := gomock.NewController(t) - - cases := []struct { - name string - indexers [][2]uint64 // [startHeight, height] - expect uint64 + master := mock_blockdao.NewMockBlockIndexer(ctrl) + master.EXPECT().Start(gomock.Any()).Return(nil).Times(4) + master.EXPECT().Height().Return(uint64(10), nil).AnyTimes() + master.EXPECT().Stop(gomock.Any()).Return(nil).Times(4) + + ctx := context.Background() + for _, c := range []struct { + name string + height []uint64 // indexer's height + active []bool + err error }{ - {"no indexers", nil, 0}, - {"one indexer without start height", [][2]uint64{{0, 100}}, 101}, - {"one indexer with start height I", [][2]uint64{{100, 200}}, 201}, - {"one indexer with start height II", [][2]uint64{{300, 200}}, 300}, - {"two indexers with start height I", [][2]uint64{{100, 200}, {200, 300}}, 201}, - {"two indexers with start height II", [][2]uint64{{100, 200}, {400, 300}}, 201}, - {"two indexers with start height III", [][2]uint64{{100, 350}, {400, 300}}, 351}, - {"two indexers one with start height I", [][2]uint64{{0, 1}, {150, 1}}, 2}, - {"two indexers one with start height II", [][2]uint64{{0, 1}, {150, 200}}, 2}, - {"two indexers one with start height III", [][2]uint64{{0, 200}, {250, 1}}, 201}, - {"two indexers one with start height IV", [][2]uint64{{0, 200}, {150, 1}}, 150}, - {"two indexers I", [][2]uint64{{0, 5}, {0, 1}}, 2}, - {"two indexers II", [][2]uint64{{0, 5}, {0, 5}}, 6}, - {"two indexers III", [][2]uint64{{0, 5}, {0, 6}}, 6}, - {"multiple indexers I", [][2]uint64{{0, 5}, {0, 6}, {0, 7}}, 6}, - {"multiple indexers II", [][2]uint64{{0, 5}, {10, 6}, {0, 7}}, 6}, - {"multiple indexers III", [][2]uint64{{10, 5}, {0, 6}, {0, 7}}, 7}, - } - - for _, c := range cases { + {"2 indexer in-sync", []uint64{10, 10}, []bool{true, true}, nil}, + {"2 indexer inactive", []uint64{15, 20}, []bool{false, false}, nil}, + {"1 indexer active", []uint64{20}, []bool{true}, ErrNotSychronized}, + {"2 indexer active", []uint64{10, 20}, []bool{true, true}, ErrNotSychronized}, + } { t.Run(c.name, func(t *testing.T) { - var indexers []blockdao.BlockIndexer - for _, indexer := range c.indexers { - if indexer[0] > 0 { - mockIndexerWithStart := mock_blockdao.NewMockBlockIndexerWithStart(ctrl) - mockIndexerWithStart.EXPECT().Start(gomock.Any()).Return(nil).Times(1) - mockIndexerWithStart.EXPECT().StartHeight().Return(indexer[0]).Times(1) - mockIndexerWithStart.EXPECT().Height().Return(indexer[1], nil).Times(1) - indexers = append(indexers, mockIndexerWithStart) - } else { - mockIndexer := mock_blockdao.NewMockBlockIndexer(ctrl) - mockIndexer.EXPECT().Start(gomock.Any()).Return(nil).Times(1) - mockIndexer.EXPECT().Height().Return(indexer[1], nil).Times(1) - indexers = append(indexers, mockIndexer) + var mockIndexer []blockdao.BlockIndexer + for i := range c.height { + iwa := mock_blockdao.NewMockBlockIndexerWithActive(ctrl) + iwa.EXPECT().Start(gomock.Any()).Return(nil).Times(1) + iwa.EXPECT().IsActive().Return(c.active[i]).Times(1) + if c.active[i] { + iwa.EXPECT().Height().Return(c.height[i], nil).Times(1) } + iwa.EXPECT().Stop(gomock.Any()).Return(nil).Times(1) + mockIndexer = append(mockIndexer, iwa) } - ig := NewSyncIndexers(indexers...) - err := ig.Start(context.Background()) - require.NoError(err) - height := ig.StartHeight() - require.Equal(c.expect, height) - }) - } - -} - -func TestSyncIndexers_Height(t *testing.T) { - require := require.New(t) - ctrl := gomock.NewController(t) - defer ctrl.Finish() - - cases := []struct { - heights []uint64 - expect uint64 - }{ - {[]uint64{}, 0}, - {[]uint64{100}, 100}, - {[]uint64{100, 100}, 100}, - {[]uint64{90, 100}, 90}, - {[]uint64{100, 90}, 90}, - {[]uint64{100, 100, 100}, 100}, - {[]uint64{90, 100, 100}, 90}, - {[]uint64{90, 80, 100}, 80}, - {[]uint64{90, 80, 70}, 70}, - } - - for i := range cases { - name := strconv.FormatUint(uint64(i), 10) - t.Run(name, func(t *testing.T) { - var indexers []blockdao.BlockIndexer - for _, height := range cases[i].heights { - mockIndexer := mock_blockdao.NewMockBlockIndexer(ctrl) - mockIndexer.EXPECT().Height().Return(height, nil).Times(1) - indexers = append(indexers, mockIndexer) - } - ig := NewSyncIndexers(indexers...) - height, err := ig.Height() - require.NoError(err) - require.Equal(cases[i].expect, height) + syncx := NewSyncIndexers(master, mockIndexer...) + r.ErrorIs(syncx.Start(ctx), c.err) + r.NoError(syncx.Stop(ctx)) }) } } func TestSyncIndexers_PutBlock(t *testing.T) { - require := require.New(t) - ctrl := gomock.NewController(t) - defer ctrl.Finish() - - cases := []struct { - indexers [][2]uint64 // [startHeight, height] - blocks []uint64 // blocks to put - expectBlocks [][]uint64 // expect blocks to put on every indexer - }{ - { - [][2]uint64{}, - []uint64{100}, - [][]uint64{}, - }, - { - [][2]uint64{{100, 10}}, - []uint64{10, 20, 90, 100, 101}, - [][]uint64{{100, 101}}, - }, - { - [][2]uint64{{100, 210}}, - []uint64{10, 20, 90, 100, 101, 210, 211}, - [][]uint64{{211}}, - }, - { - [][2]uint64{{0, 200}, {250, 1}}, - []uint64{1, 2, 201, 249, 250, 251}, - [][]uint64{{201, 249, 250, 251}, {250, 251}}, - }, - { - [][2]uint64{{0, 250}, {250, 250}}, - []uint64{1, 2, 201, 249, 250, 251, 252}, - [][]uint64{{251, 252}, {251, 252}}, - }, - { - [][2]uint64{{0, 200}, {250, 1}, {300, 1}}, - []uint64{1, 2, 201, 249, 250, 251, 300, 301}, - [][]uint64{{201, 249, 250, 251, 300, 301}, {250, 251, 300, 301}, {300, 301}}, - }, - { - [][2]uint64{{0, 250}, {250, 250}, {300, 250}}, - []uint64{1, 2, 201, 249, 250, 251, 300, 301}, - [][]uint64{{251, 300, 301}, {251, 300, 301}, {300, 301}}, - }, - { - [][2]uint64{{0, 300}, {250, 300}, {300, 300}}, - []uint64{1, 2, 201, 249, 250, 251, 300, 301}, - [][]uint64{{301}, {301}, {301}}, - }, - { - [][2]uint64{{0, 400}, {250, 400}, {300, 400}}, - []uint64{1, 2, 201, 249, 250, 251, 300, 301, 400, 401}, - [][]uint64{{401}, {401}, {401}}, - }, - } - - for _, c := range cases { - t.Run("", func(t *testing.T) { - var indexers []blockdao.BlockIndexer - putBlocks := make([][]uint64, len(c.indexers)) - indexersHeight := make([]uint64, len(c.indexers)) - for id, indexer := range c.indexers { - idx := id - indexersHeight[idx] = indexer[1] - if indexer[0] > 0 { - mockIndexerWithStart := mock_blockdao.NewMockBlockIndexerWithStart(ctrl) - mockIndexerWithStart.EXPECT().Start(gomock.Any()).Return(nil).Times(1) - mockIndexerWithStart.EXPECT().StartHeight().Return(indexer[0]).Times(1) - mockIndexerWithStart.EXPECT().Height().DoAndReturn(func() (uint64, error) { - return indexersHeight[idx], nil - }).AnyTimes() - mockIndexerWithStart.EXPECT().PutBlock(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, blk *block.Block) error { - putBlocks[idx] = append(putBlocks[idx], blk.Height()) - indexersHeight[idx] = blk.Height() - return nil - }).Times(len(c.expectBlocks[idx])) - indexers = append(indexers, mockIndexerWithStart) - } else { - mockIndexer := mock_blockdao.NewMockBlockIndexer(ctrl) - mockIndexer.EXPECT().Start(gomock.Any()).Return(nil).Times(1) - mockIndexer.EXPECT().Height().DoAndReturn(func() (uint64, error) { - return indexersHeight[idx], nil - }).AnyTimes() - mockIndexer.EXPECT().PutBlock(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, blk *block.Block) error { - putBlocks[idx] = append(putBlocks[idx], blk.Height()) - indexersHeight[idx] = blk.Height() - return nil - }).Times(len(c.expectBlocks[idx])) - indexers = append(indexers, mockIndexer) - } - } - ig := NewSyncIndexers(indexers...) - err := ig.Start(context.Background()) - require.NoError(err) - for _, blkHeight := range c.blocks { - blk, err := block.NewBuilder(block.RunnableActions{}).SetHeight(blkHeight).SignAndBuild(identityset.PrivateKey(0)) - require.NoError(err) - err = ig.PutBlock(context.Background(), &blk) - require.NoError(err) - } - require.Equal(c.expectBlocks, putBlocks) - }) - } + // todo: modify this test } diff --git a/chainservice/builder.go b/chainservice/builder.go index f986851bd1..62ad779e2e 100644 --- a/chainservice/builder.go +++ b/chainservice/builder.go @@ -287,18 +287,18 @@ func (builder *Builder) buildBlockDAO(forTest bool) error { return nil } - var indexers []blockdao.BlockIndexer // indexers in synchronizedIndexers will need to run PutBlock() one by one // factory is dependent on sgdIndexer and contractStakingIndexer, so it should be put in the first place - synchronizedIndexers := []blockdao.BlockIndexer{builder.cs.factory} + var synchronizedIndexers []blockdao.BlockIndexer if builder.cs.contractStakingIndexer != nil { synchronizedIndexers = append(synchronizedIndexers, builder.cs.contractStakingIndexer) } if builder.cs.contractStakingIndexerV2 != nil { synchronizedIndexers = append(synchronizedIndexers, builder.cs.contractStakingIndexerV2) } - if len(synchronizedIndexers) > 1 { - indexers = append(indexers, blockindex.NewSyncIndexers(synchronizedIndexers...)) + var indexers []blockdao.BlockIndexer + if len(synchronizedIndexers) > 0 { + indexers = append(indexers, blockindex.NewSyncIndexers(builder.cs.factory, synchronizedIndexers...)) } else { indexers = append(indexers, builder.cs.factory) } diff --git a/misc/scripts/mockgen.sh b/misc/scripts/mockgen.sh index 10f9caedc9..ec2d92f74b 100755 --- a/misc/scripts/mockgen.sh +++ b/misc/scripts/mockgen.sh @@ -169,10 +169,10 @@ mockgen -destination=./test/mock/mock_blockdao/mock_blockindexer.go \ -package=mock_blockdao \ github.com/iotexproject/iotex-core/v2/blockchain/blockdao \ BlockIndexer -mockgen -destination=./test/mock/mock_blockdao/mock_blockindexer_withstart.go \ +mockgen -destination=./test/mock/mock_blockdao/mock_blockindexer_withactive.go \ -package=mock_blockdao \ github.com/iotexproject/iotex-core/v2/blockchain/blockdao \ - BlockIndexerWithStart + BlockIndexerWithActive mkdir -p ./test/mock/mock_envelope mockgen -destination=./test/mock/mock_envelope/mock_envelope.go \ diff --git a/systemcontractindex/common.go b/systemcontractindex/common.go index bfb9f82c0a..75396ceedb 100644 --- a/systemcontractindex/common.go +++ b/systemcontractindex/common.go @@ -82,6 +82,10 @@ func (s *IndexerCommon) loadHeight() (uint64, error) { // StartHeight returns the start height of the indexer func (s *IndexerCommon) StartHeight() uint64 { return s.startHeight } +func (s *IndexerCommon) IsActive() bool { + return s.height > s.startHeight +} + // Commit commits the height to the indexer func (s *IndexerCommon) Commit(height uint64, delta batch.KVStoreBatch) error { delta.Put(s.ns, s.key, byteutil.Uint64ToBytesBigEndian(height), "failed to put height") diff --git a/test/mock/mock_blockdao/mock_blockindexer_withactive.go b/test/mock/mock_blockdao/mock_blockindexer_withactive.go new file mode 100644 index 0000000000..1e6b3a3e2d --- /dev/null +++ b/test/mock/mock_blockdao/mock_blockindexer_withactive.go @@ -0,0 +1,107 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/iotexproject/iotex-core/v2/blockchain/blockdao (interfaces: BlockIndexerWithActive) + +// Package mock_blockdao is a generated GoMock package. +package mock_blockdao + +import ( + context "context" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + block "github.com/iotexproject/iotex-core/v2/blockchain/block" +) + +// MockBlockIndexerWithActive is a mock of BlockIndexerWithActive interface. +type MockBlockIndexerWithActive struct { + ctrl *gomock.Controller + recorder *MockBlockIndexerWithActiveMockRecorder +} + +// MockBlockIndexerWithActiveMockRecorder is the mock recorder for MockBlockIndexerWithActive. +type MockBlockIndexerWithActiveMockRecorder struct { + mock *MockBlockIndexerWithActive +} + +// NewMockBlockIndexerWithActive creates a new mock instance. +func NewMockBlockIndexerWithActive(ctrl *gomock.Controller) *MockBlockIndexerWithActive { + mock := &MockBlockIndexerWithActive{ctrl: ctrl} + mock.recorder = &MockBlockIndexerWithActiveMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBlockIndexerWithActive) EXPECT() *MockBlockIndexerWithActiveMockRecorder { + return m.recorder +} + +// Height mocks base method. +func (m *MockBlockIndexerWithActive) Height() (uint64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Height") + ret0, _ := ret[0].(uint64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Height indicates an expected call of Height. +func (mr *MockBlockIndexerWithActiveMockRecorder) Height() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Height", reflect.TypeOf((*MockBlockIndexerWithActive)(nil).Height)) +} + +// IsActive mocks base method. +func (m *MockBlockIndexerWithActive) IsActive() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsActive") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsActive indicates an expected call of IsActive. +func (mr *MockBlockIndexerWithActiveMockRecorder) IsActive() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsActive", reflect.TypeOf((*MockBlockIndexerWithActive)(nil).IsActive)) +} + +// PutBlock mocks base method. +func (m *MockBlockIndexerWithActive) PutBlock(arg0 context.Context, arg1 *block.Block) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PutBlock", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// PutBlock indicates an expected call of PutBlock. +func (mr *MockBlockIndexerWithActiveMockRecorder) PutBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutBlock", reflect.TypeOf((*MockBlockIndexerWithActive)(nil).PutBlock), arg0, arg1) +} + +// Start mocks base method. +func (m *MockBlockIndexerWithActive) Start(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Start", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Start indicates an expected call of Start. +func (mr *MockBlockIndexerWithActiveMockRecorder) Start(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockBlockIndexerWithActive)(nil).Start), arg0) +} + +// Stop mocks base method. +func (m *MockBlockIndexerWithActive) Stop(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Stop", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Stop indicates an expected call of Stop. +func (mr *MockBlockIndexerWithActiveMockRecorder) Stop(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockBlockIndexerWithActive)(nil).Stop), arg0) +} diff --git a/test/mock/mock_blockdao/mock_blockindexer_withstart.go b/test/mock/mock_blockdao/mock_blockindexer_withstart.go deleted file mode 100644 index 25fc7848d6..0000000000 --- a/test/mock/mock_blockdao/mock_blockindexer_withstart.go +++ /dev/null @@ -1,107 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/iotexproject/iotex-core/v2/blockchain/blockdao (interfaces: BlockIndexerWithStart) - -// Package mock_blockdao is a generated GoMock package. -package mock_blockdao - -import ( - context "context" - reflect "reflect" - - gomock "github.com/golang/mock/gomock" - block "github.com/iotexproject/iotex-core/v2/blockchain/block" -) - -// MockBlockIndexerWithStart is a mock of BlockIndexerWithStart interface. -type MockBlockIndexerWithStart struct { - ctrl *gomock.Controller - recorder *MockBlockIndexerWithStartMockRecorder -} - -// MockBlockIndexerWithStartMockRecorder is the mock recorder for MockBlockIndexerWithStart. -type MockBlockIndexerWithStartMockRecorder struct { - mock *MockBlockIndexerWithStart -} - -// NewMockBlockIndexerWithStart creates a new mock instance. -func NewMockBlockIndexerWithStart(ctrl *gomock.Controller) *MockBlockIndexerWithStart { - mock := &MockBlockIndexerWithStart{ctrl: ctrl} - mock.recorder = &MockBlockIndexerWithStartMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockBlockIndexerWithStart) EXPECT() *MockBlockIndexerWithStartMockRecorder { - return m.recorder -} - -// Height mocks base method. -func (m *MockBlockIndexerWithStart) Height() (uint64, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Height") - ret0, _ := ret[0].(uint64) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Height indicates an expected call of Height. -func (mr *MockBlockIndexerWithStartMockRecorder) Height() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Height", reflect.TypeOf((*MockBlockIndexerWithStart)(nil).Height)) -} - -// PutBlock mocks base method. -func (m *MockBlockIndexerWithStart) PutBlock(arg0 context.Context, arg1 *block.Block) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PutBlock", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// PutBlock indicates an expected call of PutBlock. -func (mr *MockBlockIndexerWithStartMockRecorder) PutBlock(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutBlock", reflect.TypeOf((*MockBlockIndexerWithStart)(nil).PutBlock), arg0, arg1) -} - -// Start mocks base method. -func (m *MockBlockIndexerWithStart) Start(arg0 context.Context) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Start", arg0) - ret0, _ := ret[0].(error) - return ret0 -} - -// Start indicates an expected call of Start. -func (mr *MockBlockIndexerWithStartMockRecorder) Start(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockBlockIndexerWithStart)(nil).Start), arg0) -} - -// StartHeight mocks base method. -func (m *MockBlockIndexerWithStart) StartHeight() uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StartHeight") - ret0, _ := ret[0].(uint64) - return ret0 -} - -// StartHeight indicates an expected call of StartHeight. -func (mr *MockBlockIndexerWithStartMockRecorder) StartHeight() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartHeight", reflect.TypeOf((*MockBlockIndexerWithStart)(nil).StartHeight)) -} - -// Stop mocks base method. -func (m *MockBlockIndexerWithStart) Stop(arg0 context.Context) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Stop", arg0) - ret0, _ := ret[0].(error) - return ret0 -} - -// Stop indicates an expected call of Stop. -func (mr *MockBlockIndexerWithStartMockRecorder) Stop(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockBlockIndexerWithStart)(nil).Stop), arg0) -} diff --git a/test/mock/mock_dispatcher/mock_dispatcher.go b/test/mock/mock_dispatcher/mock_dispatcher.go index 5a12391bac..38cccfc81a 100644 --- a/test/mock/mock_dispatcher/mock_dispatcher.go +++ b/test/mock/mock_dispatcher/mock_dispatcher.go @@ -100,3 +100,18 @@ func (mr *MockDispatcherMockRecorder) Stop(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockDispatcher)(nil).Stop), arg0) } + +// ValidateMessage mocks base method. +func (m *MockDispatcher) ValidateMessage(arg0 proto.Message) (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateMessage", arg0) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ValidateMessage indicates an expected call of ValidateMessage. +func (mr *MockDispatcherMockRecorder) ValidateMessage(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateMessage", reflect.TypeOf((*MockDispatcher)(nil).ValidateMessage), arg0) +}