diff --git a/block/block.go b/block/block.go index 4f990f614..d8a5f859d 100644 --- a/block/block.go +++ b/block/block.go @@ -100,7 +100,7 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta select { case m.pruningC <- retainHeight: default: - m.logger.Error("pruning channel full. skipping pruning", "retainHeight", retainHeight) + m.logger.Debug("pruning channel full. skipping pruning", "retainHeight", retainHeight) } } return nil diff --git a/block/manager.go b/block/manager.go index d3d9de65c..7e4750067 100644 --- a/block/manager.go +++ b/block/manager.go @@ -80,7 +80,7 @@ type Manager struct { pruningC chan int64 // indexer - indexerService *txindex.IndexerService + IndexerService *txindex.IndexerService } // NewManager creates new block Manager. @@ -119,7 +119,7 @@ func NewManager( Executor: exec, DAClient: dalc, SLClient: settlementClient, - indexerService: indexerService, + IndexerService: indexerService, Retriever: dalc.(da.BatchRetriever), logger: logger, blockCache: &Cache{ diff --git a/block/manager_test.go b/block/manager_test.go index f58c75fb8..6ee9b631b 100644 --- a/block/manager_test.go +++ b/block/manager_test.go @@ -60,6 +60,7 @@ func TestInitialState(t *testing.T) { GossipSubCacheSize: 50, BootstrapRetryTime: 30 * time.Second, BlockSyncRequestIntervalTime: 30 * time.Second, + BlockSyncEnabled: true, }, privKey, "TestChain", emptyStore, pubsubServer, datastore.NewMapDatastore(), logger) assert.NoError(err) assert.NotNil(p2pClient) diff --git a/block/pruning.go b/block/pruning.go index 6a588a7f9..040a32816 100644 --- a/block/pruning.go +++ b/block/pruning.go @@ -2,45 +2,30 @@ package block import ( "context" - "fmt" - - "github.com/dymensionxyz/gerr-cosmos/gerrc" ) -func (m *Manager) PruneBlocks(retainHeight uint64) error { - if m.IsSequencer() && m.NextHeightToSubmit() < retainHeight { // do not delete anything that we might submit in future - return fmt.Errorf("cannot prune blocks before they have been submitted: retain height %d: next height to submit: %d: %w", - retainHeight, - m.NextHeightToSubmit(), - gerrc.ErrInvalidArgument) +// PruneBlocks prune all block related data from dymint store up to (but not including) retainHeight. +func (m *Manager) PruneBlocks(retainHeight uint64) { + // logging pruning result + logResult := func(err error, source string, retainHeight uint64, pruned uint64) { + if err != nil { + m.logger.Error("pruning", "from", source, "retain height", retainHeight, "err", err) + } else { + m.logger.Debug("pruned", "from", source, "retain height", retainHeight, "pruned", pruned) + } } // prune blocks from blocksync store - err := m.p2pClient.RemoveBlocks(context.Background(), m.State.BaseHeight, retainHeight) - if err != nil { - m.logger.Error("pruning blocksync store", "retain_height", retainHeight, "err", err) - } + pruned, err := m.p2pClient.RemoveBlocks(context.Background(), retainHeight) + logResult(err, "blocksync", retainHeight, pruned) - // prune blocks from indexer store - err = m.indexerService.Prune(m.State.BaseHeight, retainHeight) - if err != nil { - m.logger.Error("pruning indexer", "retain_height", retainHeight, "err", err) - } + // prune indexed block and txs and associated events + pruned, err = m.IndexerService.Prune(retainHeight, m.Store) + logResult(err, "indexer", retainHeight, pruned) // prune blocks from dymint store - pruned, err := m.Store.PruneBlocks(m.State.BaseHeight, retainHeight) - if err != nil { - return fmt.Errorf("prune block store: %w", err) - } - - m.State.BaseHeight = retainHeight - _, err = m.Store.SaveState(m.State, nil) - if err != nil { - return fmt.Errorf("save state: %w", err) - } - - m.logger.Info("pruned blocks", "pruned", pruned, "retain_height", retainHeight) - return nil + pruned, err = m.Store.PruneStore(retainHeight, m.logger) + logResult(err, "dymint store", retainHeight, pruned) } func (m *Manager) PruningLoop(ctx context.Context) error { @@ -49,11 +34,14 @@ func (m *Manager) PruningLoop(ctx context.Context) error { case <-ctx.Done(): return ctx.Err() case retainHeight := <-m.pruningC: - err := m.PruneBlocks(uint64(retainHeight)) - if err != nil { - m.logger.Error("pruning blocks", "retainHeight", retainHeight, "err", err) - } + var pruningHeight uint64 + if m.IsSequencer() { // do not delete anything that we might submit in future + pruningHeight = min(m.NextHeightToSubmit(), uint64(retainHeight)) + } else { + pruningHeight = uint64(retainHeight) + } + m.PruneBlocks(pruningHeight) } } } diff --git a/block/pruning_test.go b/block/pruning_test.go index 50346eb88..716fce7c6 100644 --- a/block/pruning_test.go +++ b/block/pruning_test.go @@ -5,8 +5,10 @@ import ( "testing" "github.com/dymensionxyz/dymint/testutil" + "github.com/dymensionxyz/gerr-cosmos/gerrc" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/proxy" ) @@ -45,13 +47,23 @@ func TestPruningRetainHeight(t *testing.T) { _, _, err = manager.ProduceAndGossipBlock(ctx, true) require.NoError(err) } + validRetainHeight := manager.NextHeightToSubmit() // the max possible valid retain height + + validatePruning := func(i uint64, expectedPruned uint64, pruned uint64, err error) { + if i <= validRetainHeight { + require.NoError(err) + assert.Equal(t, expectedPruned, pruned) + } else { + require.Error(gerrc.ErrInvalidArgument) + } + } + for i := validRetainHeight; i < manager.State.Height(); i++ { + baseHeight := uint64(1) + expectedPruned := validRetainHeight - baseHeight + + pruned, err := manager.Store.PruneStore(validRetainHeight, log.NewNopLogger()) + validatePruning(i, expectedPruned, pruned, err) - validRetainHeight := lastSubmitted + 1 // the max possible valid retain height - for i := validRetainHeight + 1; i < manager.State.Height(); i++ { - err = manager.PruneBlocks(i) - require.Error(err) // cannot prune blocks before they have been submitted } - err = manager.PruneBlocks(validRetainHeight) - require.NoError(err) } diff --git a/block/state.go b/block/state.go index ef8e2a8c9..02d2d6fae 100644 --- a/block/state.go +++ b/block/state.go @@ -55,14 +55,10 @@ func NewStateFromGenesis(genDoc *tmtypes.GenesisDoc) (*types.State, error) { } s := types.State{ - Version: InitStateVersion, - ChainID: genDoc.ChainID, - InitialHeight: uint64(genDoc.InitialHeight), - - BaseHeight: uint64(genDoc.InitialHeight), - - LastHeightValidatorsChanged: genDoc.InitialHeight, - + Version: InitStateVersion, + ChainID: genDoc.ChainID, + InitialHeight: uint64(genDoc.InitialHeight), + LastHeightValidatorsChanged: genDoc.InitialHeight, ConsensusParams: *genDoc.ConsensusParams, LastHeightConsensusParamsChanged: genDoc.InitialHeight, } diff --git a/indexers/blockindexer/kv/kv.go b/indexers/blockindexer/kv/kv.go index 65164ec36..f4f1e97a3 100644 --- a/indexers/blockindexer/kv/kv.go +++ b/indexers/blockindexer/kv/kv.go @@ -528,19 +528,12 @@ func (idx *BlockerIndexer) indexEvents(batch store.KVBatch, events []abci.Event, } func (idx *BlockerIndexer) Prune(from, to uint64, logger log.Logger) (uint64, error) { - if from <= 0 { - return 0, fmt.Errorf("from height must be greater than 0: %w", gerrc.ErrInvalidArgument) - } - - if to <= from { - return 0, fmt.Errorf("to height must be greater than from height: to: %d: from: %d: %w", to, from, gerrc.ErrInvalidArgument) - } - blocksPruned, err := idx.pruneBlocks(from, to, logger) - return blocksPruned, err + return idx.pruneBlocks(from, to, logger) } func (idx *BlockerIndexer) pruneBlocks(from, to uint64, logger log.Logger) (uint64, error) { pruned := uint64(0) + toFlush := uint64(0) batch := idx.store.NewBatch() defer batch.Discard() @@ -553,9 +546,21 @@ func (idx *BlockerIndexer) pruneBlocks(from, to uint64, logger log.Logger) (uint } for h := int64(from); h < int64(to); h++ { + + // flush every 1000 blocks to avoid batches becoming too large + if toFlush > 1000 { + err := flush(batch, h) + if err != nil { + return 0, err + } + batch.Discard() + batch = idx.store.NewBatch() + toFlush = 0 + } + ok, err := idx.Has(h) if err != nil { - logger.Debug("pruning block indexer checking height", "err", err) + logger.Debug("pruning block indexer checking height", "height", h, "err", err) continue } if !ok { @@ -563,28 +568,25 @@ func (idx *BlockerIndexer) pruneBlocks(from, to uint64, logger log.Logger) (uint } key, err := heightKey(h) if err != nil { - logger.Debug("pruning block indexer getting height key", "err", err) + logger.Debug("pruning block indexer getting height key", "height", h, "err", err) continue } + pruned++ + toFlush++ + if err := batch.Delete(key); err != nil { - logger.Debug("pruning block indexer deleting height key", "err", err) + logger.Debug("pruning block indexer deleting height key", "height", h, "err", err) continue } - if err := idx.pruneEvents(h, batch); err != nil { - logger.Debug("pruning block indexer events", "err", err) - continue - } - pruned++ - // flush every 1000 blocks to avoid batches becoming too large - if pruned%1000 == 0 && pruned > 0 { - err := flush(batch, h) - if err != nil { - return 0, err - } - batch.Discard() - batch = idx.store.NewBatch() + prunedEvents, err := idx.pruneEvents(h, logger, batch) + pruned += prunedEvents + toFlush += prunedEvents + + if err != nil { + logger.Debug("pruning block indexer events", "height", h, "err", err) } + } err := flush(batch, int64(to)) @@ -595,27 +597,32 @@ func (idx *BlockerIndexer) pruneBlocks(from, to uint64, logger log.Logger) (uint return pruned, nil } -func (idx *BlockerIndexer) pruneEvents(height int64, batch store.KVBatch) error { +func (idx *BlockerIndexer) pruneEvents(height int64, logger log.Logger, batch store.KVBatch) (uint64, error) { + pruned := uint64(0) + eventKey, err := eventHeightKey(height) if err != nil { - return err + return pruned, err } keysList, err := idx.store.Get(eventKey) if err != nil { - return err + return pruned, err } eventKeys := &dymint.EventKeys{} err = eventKeys.Unmarshal(keysList) if err != nil { - return err + return pruned, err } for _, key := range eventKeys.Keys { err := batch.Delete(key) if err != nil { - return err + logger.Error("pruning block indexer iterate events", "height", height, "err", err) + continue } + pruned++ + } - return nil + return pruned, nil } func (idx *BlockerIndexer) addEventKeys(height int64, beginKeys *dymint.EventKeys, endKeys *dymint.EventKeys, batch store.KVBatch) error { diff --git a/indexers/blockindexer/kv/kv_test.go b/indexers/blockindexer/kv/kv_test.go index b7a8a17f6..ff017616e 100644 --- a/indexers/blockindexer/kv/kv_test.go +++ b/indexers/blockindexer/kv/kv_test.go @@ -154,12 +154,17 @@ func TestBlockIndexerPruning(t *testing.T) { indexer := blockidxkv.New(prefixStore) numBlocks := uint64(100) + numEvents := uint64(0) // index block data for i := uint64(1); i <= numBlocks; i++ { + beginBlock := getBeginBlock() + endBlock := getEndBlock() + numEvents += uint64(len(beginBlock.Events)) + numEvents += uint64(len(endBlock.Events)) indexer.Index(types.EventDataNewBlockHeader{ Header: types.Header{Height: int64(i)}, - ResultBeginBlock: getBeginBlock(), - ResultEndBlock: getEndBlock(), + ResultBeginBlock: beginBlock, + ResultEndBlock: endBlock, }) } @@ -173,7 +178,7 @@ func TestBlockIndexerPruning(t *testing.T) { // prune indexer for all heights pruned, err := indexer.Prune(1, numBlocks+1, log.NewNopLogger()) require.NoError(t, err) - require.Equal(t, numBlocks, pruned) + require.Equal(t, numBlocks+numEvents, pruned) // check the query returns empty results, err = indexer.Search(context.Background(), q) diff --git a/indexers/txindex/indexer.go b/indexers/txindex/indexer.go index 694b90d86..281c1dccc 100644 --- a/indexers/txindex/indexer.go +++ b/indexers/txindex/indexer.go @@ -32,13 +32,15 @@ type TxIndexer interface { // Batch groups together multiple Index operations to be performed at the same time. // NOTE: Batch is NOT thread-safe and must not be modified after starting its execution. type Batch struct { - Ops []*abci.TxResult + Height int64 + Ops []*abci.TxResult } // NewBatch creates a new Batch. -func NewBatch(n int64) *Batch { +func NewBatch(n int64, height int64) *Batch { return &Batch{ - Ops: make([]*abci.TxResult, n), + Height: height, + Ops: make([]*abci.TxResult, n), } } diff --git a/indexers/txindex/indexer_service.go b/indexers/txindex/indexer_service.go index 88a79b8ae..e5ec76696 100644 --- a/indexers/txindex/indexer_service.go +++ b/indexers/txindex/indexer_service.go @@ -2,8 +2,11 @@ package txindex import ( "context" + "errors" indexer "github.com/dymensionxyz/dymint/indexers/blockindexer" + "github.com/dymensionxyz/dymint/store" + "github.com/dymensionxyz/gerr-cosmos/gerrc" "github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/types" ) @@ -59,7 +62,7 @@ func (is *IndexerService) OnStart() error { msg := <-blockHeadersSub.Out() eventDataHeader, _ := msg.Data().(types.EventDataNewBlockHeader) height := eventDataHeader.Header.Height - batch := NewBatch(eventDataHeader.NumTxs) + batch := NewBatch(eventDataHeader.NumTxs, height) for i := int64(0); i < eventDataHeader.NumTxs; i++ { msg2 := <-txsSub.Out() @@ -99,14 +102,33 @@ func (is *IndexerService) OnStop() { } // Prune removes tx and blocks indexed up to (but not including) a height. -func (is *IndexerService) Prune(from, to uint64) error { - _, err := is.blockIdxr.Prune(from, to, is.Logger) +func (is *IndexerService) Prune(to uint64, s store.Store) (uint64, error) { + // load indexer base height + indexerBaseHeight, err := s.LoadIndexerBaseHeight() + + if errors.Is(err, gerrc.ErrNotFound) { + is.Logger.Error("load indexer base height", "err", err) + } else if err != nil { + return 0, err + } + + // prune indexed blocks + blockPruned, err := is.blockIdxr.Prune(indexerBaseHeight, to, is.Logger) if err != nil { - return err + return blockPruned, err } - _, err = is.txIdxr.Prune(from, to, is.Logger) + + // prune indexes txs + txPruned, err := is.txIdxr.Prune(indexerBaseHeight, to, is.Logger) if err != nil { - return err + return txPruned, err } - return nil + + // store indexer base height + err = s.SaveIndexerBaseHeight(to) + if err != nil { + is.Logger.Error("saving indexer base height", "err", err) + } + + return blockPruned + txPruned, nil } diff --git a/indexers/txindex/indexer_service_test.go b/indexers/txindex/indexer_service_test.go index abd281605..9c08b3d63 100644 --- a/indexers/txindex/indexer_service_test.go +++ b/indexers/txindex/indexer_service_test.go @@ -48,19 +48,45 @@ func TestIndexerServiceIndexesBlocks(t *testing.T) { NumTxs: int64(2), }) require.NoError(t, err) + txResult1 := &abci.TxResult{ Height: 1, Index: uint32(0), Tx: types.Tx("foo"), - Result: abci.ResponseDeliverTx{Code: 0}, + Result: abci.ResponseDeliverTx{ + Code: 0, + Events: []abci.Event{{Type: "test_event", + Attributes: []abci.EventAttribute{ + { + Key: []byte("foo"), + Value: []byte("100"), + Index: true, + }, + }, + }, + }, + }, } + err = eventBus.PublishEventTx(types.EventDataTx{TxResult: *txResult1}) require.NoError(t, err) txResult2 := &abci.TxResult{ Height: 1, Index: uint32(1), Tx: types.Tx("bar"), - Result: abci.ResponseDeliverTx{Code: 0}, + Result: abci.ResponseDeliverTx{ + Code: 0, + Events: []abci.Event{{Type: "test_event", + Attributes: []abci.EventAttribute{ + { + Key: []byte("foo"), + Value: []byte("100"), + Index: true, + }, + }, + }, + }, + }, } err = eventBus.PublishEventTx(types.EventDataTx{TxResult: *txResult2}) require.NoError(t, err) @@ -84,9 +110,10 @@ func TestIndexerServiceIndexesBlocks(t *testing.T) { expectedBlocksPruned := uint64(1) require.Equal(t, expectedBlocksPruned, blocksPruned) - txPruned, err := txIndexer.Prune(1, 2, log.NewNopLogger()) + pruned, err := txIndexer.Prune(1, 2, log.NewNopLogger()) require.NoError(t, err) - expectedTxPruned := uint64(2) - require.Equal(t, expectedTxPruned, txPruned) + // 2 indexed tx + indexed 2 events = 4 pruned + expectedPruned := uint64(4) + require.Equal(t, expectedPruned, pruned) } diff --git a/indexers/txindex/kv/kv.go b/indexers/txindex/kv/kv.go index d9b54508f..2286b9828 100644 --- a/indexers/txindex/kv/kv.go +++ b/indexers/txindex/kv/kv.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/hex" + "errors" "fmt" "strconv" "strings" @@ -21,6 +22,7 @@ import ( "github.com/dymensionxyz/dymint/types" "github.com/dymensionxyz/dymint/types/pb/dymint" dmtypes "github.com/dymensionxyz/dymint/types/pb/dymint" + "github.com/dymensionxyz/gerr-cosmos/gerrc" ) const ( @@ -73,6 +75,7 @@ func (txi *TxIndex) AddBatch(b *txindex.Batch) error { storeBatch := txi.store.NewBatch() defer storeBatch.Discard() + var eventKeysBatch dmtypes.EventKeys for _, result := range b.Ops { hash := types.Tx(result.Tx).Hash() @@ -81,12 +84,7 @@ func (txi *TxIndex) AddBatch(b *txindex.Batch) error { if err != nil { return err } - - err = txi.addEventKeys(result.Height, &eventKeys, storeBatch) - if err != nil { - return err - } - + eventKeysBatch.Keys = append(eventKeysBatch.Keys, eventKeys.Keys...) // index by height (always) err = storeBatch.Set(keyForHeight(result), hash) if err != nil { @@ -104,6 +102,11 @@ func (txi *TxIndex) AddBatch(b *txindex.Batch) error { } } + err := txi.addEventKeys(b.Height, &eventKeysBatch, storeBatch) + if err != nil { + return err + } + return storeBatch.Commit() } @@ -570,15 +573,16 @@ LOOP: } func (txi *TxIndex) Prune(from, to uint64, logger log.Logger) (uint64, error) { - pruned, err := txi.pruneTxs(from, to) + pruned, err := txi.pruneTxsAndEvents(from, to, logger) if err != nil { return 0, err } return pruned, nil } -func (txi *TxIndex) pruneTxs(from, to uint64) (uint64, error) { +func (txi *TxIndex) pruneTxsAndEvents(from, to uint64, logger log.Logger) (uint64, error) { pruned := uint64(0) + toFlush := uint64(0) batch := txi.store.NewBatch() defer batch.Discard() @@ -591,31 +595,45 @@ func (txi *TxIndex) pruneTxs(from, to uint64) (uint64, error) { } for h := from; h < to; h++ { + // flush every 1000 txs to avoid batches becoming too large + if toFlush > 1000 { + err := flush(batch, int64(h)) + if err != nil { + return 0, err + } + batch.Discard() + batch = txi.store.NewBatch() + toFlush = 0 + } + // all txs indexed are iterated by height it := txi.store.PrefixIterator(prefixForHeight(int64(h))) - defer it.Discard() + // deleted all events indexed with prefix height (by hash and by keyheight) for ; it.Valid(); it.Next() { + toFlush++ if err := batch.Delete(it.Key()); err != nil { + logger.Error("pruning txs indexer event key", "height", h, "error", err) continue } + if err := batch.Delete(it.Value()); err != nil { - continue - } - if err := txi.pruneEvents(h, batch); err != nil { + logger.Error("pruning txs indexer event val", "height", h, "error", err) continue } pruned++ - // flush every 1000 txs to avoid batches becoming too large - if pruned%1000 == 0 && pruned > 0 { - err := flush(batch, int64(h)) - if err != nil { - return 0, err - } - batch.Discard() - batch = txi.store.NewBatch() - } } + + it.Discard() + + // all events associated to the same height are pruned + prunedEvents, err := txi.pruneEvents(h, batch) + if err != nil && !errors.Is(err, gerrc.ErrNotFound) { + logger.Error("pruning txs indexer events by height", "height", h, "error", err, "") + } + pruned += prunedEvents + toFlush += prunedEvents + } err := flush(batch, int64(to)) @@ -626,27 +644,29 @@ func (txi *TxIndex) pruneTxs(from, to uint64) (uint64, error) { return pruned, nil } -func (txi *TxIndex) pruneEvents(height uint64, batch store.KVBatch) error { +func (txi *TxIndex) pruneEvents(height uint64, batch store.KVBatch) (uint64, error) { + pruned := uint64(0) eventKey, err := eventHeightKey(int64(height)) if err != nil { - return err + return pruned, err } keysList, err := txi.store.Get(eventKey) if err != nil { - return err + return pruned, err } eventKeys := &dymint.EventKeys{} err = eventKeys.Unmarshal(keysList) if err != nil { - return err + return pruned, err } for _, key := range eventKeys.Keys { + pruned++ err := batch.Delete(key) if err != nil { - return err + return pruned, err } } - return nil + return pruned, nil } func (txi *TxIndex) addEventKeys(height int64, eventKeys *dymint.EventKeys, batch store.KVBatch) error { @@ -686,10 +706,9 @@ func keyForEvent(key string, value []byte, result *abci.TxResult) []byte { } func keyForHeight(result *abci.TxResult) []byte { - return []byte(fmt.Sprintf("%s/%d/%d/%d", + return []byte(fmt.Sprintf("%s/%d/%d", tmtypes.TxHeightKey, result.Height, - result.Height, result.Index, )) } diff --git a/indexers/txindex/kv/kv_test.go b/indexers/txindex/kv/kv_test.go index 60caf7f54..abba1995d 100644 --- a/indexers/txindex/kv/kv_test.go +++ b/indexers/txindex/kv/kv_test.go @@ -36,7 +36,7 @@ func TestTxIndex(t *testing.T) { } hash := tx.Hash() - batch := txindex.NewBatch(1) + batch := txindex.NewBatch(1, txResult.Height) if err := batch.Add(txResult); err != nil { t.Error(err) } @@ -321,7 +321,7 @@ func TestTxIndexerPruning(t *testing.T) { numBlocks := uint64(100) txsWithEvents := 0 - + numEvents := uint64(0) // index tx event data for i := uint64(1); i <= numBlocks; i++ { events := getNEvents(rand.Intn(10)) @@ -331,6 +331,7 @@ func TestTxIndexerPruning(t *testing.T) { if len(events) > 0 { txsWithEvents++ } + numEvents += uint64(len(events)) } q := query.MustParse("account.number = 1") @@ -342,7 +343,7 @@ func TestTxIndexerPruning(t *testing.T) { // prune indexer for all heights pruned, err := indexer.Prune(1, numBlocks+1, log.NewNopLogger()) require.NoError(t, err) - require.Equal(t, uint64(numBlocks), pruned) + require.Equal(t, numBlocks+numEvents, pruned) // check the query returns empty results, err = indexer.Search(context.Background(), q) @@ -428,7 +429,7 @@ func benchmarkTxIndex(txsCount int64, b *testing.B) { require.NoError(b, err) indexer := NewTxIndex(store) - batch := txindex.NewBatch(txsCount) + batch := txindex.NewBatch(txsCount, int64(0)) txIndex := uint32(0) for i := int64(0); i < txsCount; i++ { tx := tmrand.Bytes(250) diff --git a/mocks/github.com/dymensionxyz/dymension/v3/x/rollapp/types/mock_QueryClient.go b/mocks/github.com/dymensionxyz/dymension/v3/x/rollapp/types/mock_QueryClient.go index 34778c1f1..18a2755cb 100644 --- a/mocks/github.com/dymensionxyz/dymension/v3/x/rollapp/types/mock_QueryClient.go +++ b/mocks/github.com/dymensionxyz/dymension/v3/x/rollapp/types/mock_QueryClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.0. DO NOT EDIT. +// Code generated by mockery v2.42.3. DO NOT EDIT. package types diff --git a/mocks/github.com/dymensionxyz/dymension/v3/x/sequencer/types/mock_QueryClient.go b/mocks/github.com/dymensionxyz/dymension/v3/x/sequencer/types/mock_QueryClient.go index c130f0bdd..01110f730 100644 --- a/mocks/github.com/dymensionxyz/dymension/v3/x/sequencer/types/mock_QueryClient.go +++ b/mocks/github.com/dymensionxyz/dymension/v3/x/sequencer/types/mock_QueryClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.0. DO NOT EDIT. +// Code generated by mockery v2.42.3. DO NOT EDIT. package types diff --git a/mocks/github.com/dymensionxyz/dymint/da/avail/mock_SubstrateApiI.go b/mocks/github.com/dymensionxyz/dymint/da/avail/mock_SubstrateApiI.go index b0dcef1df..6a52c1df8 100644 --- a/mocks/github.com/dymensionxyz/dymint/da/avail/mock_SubstrateApiI.go +++ b/mocks/github.com/dymensionxyz/dymint/da/avail/mock_SubstrateApiI.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.0. DO NOT EDIT. +// Code generated by mockery v2.42.3. DO NOT EDIT. package avail diff --git a/mocks/github.com/dymensionxyz/dymint/da/celestia/types/mock_CelestiaRPCClient.go b/mocks/github.com/dymensionxyz/dymint/da/celestia/types/mock_CelestiaRPCClient.go index a7975a856..4935cc66a 100644 --- a/mocks/github.com/dymensionxyz/dymint/da/celestia/types/mock_CelestiaRPCClient.go +++ b/mocks/github.com/dymensionxyz/dymint/da/celestia/types/mock_CelestiaRPCClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.0. DO NOT EDIT. +// Code generated by mockery v2.42.3. DO NOT EDIT. package types diff --git a/mocks/github.com/dymensionxyz/dymint/da/mock_DataAvailabilityLayerClient.go b/mocks/github.com/dymensionxyz/dymint/da/mock_DataAvailabilityLayerClient.go index 8f298f169..905253a46 100644 --- a/mocks/github.com/dymensionxyz/dymint/da/mock_DataAvailabilityLayerClient.go +++ b/mocks/github.com/dymensionxyz/dymint/da/mock_DataAvailabilityLayerClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.0. DO NOT EDIT. +// Code generated by mockery v2.42.3. DO NOT EDIT. package da diff --git a/mocks/github.com/dymensionxyz/dymint/settlement/dymension/mock_CosmosClient.go b/mocks/github.com/dymensionxyz/dymint/settlement/dymension/mock_CosmosClient.go index f31ee7fe3..f03a6c1c2 100644 --- a/mocks/github.com/dymensionxyz/dymint/settlement/dymension/mock_CosmosClient.go +++ b/mocks/github.com/dymensionxyz/dymint/settlement/dymension/mock_CosmosClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.0. DO NOT EDIT. +// Code generated by mockery v2.42.3. DO NOT EDIT. package dymension diff --git a/mocks/github.com/dymensionxyz/dymint/settlement/mock_ClientI.go b/mocks/github.com/dymensionxyz/dymint/settlement/mock_ClientI.go index 7c980a17e..25c19a6ae 100644 --- a/mocks/github.com/dymensionxyz/dymint/settlement/mock_ClientI.go +++ b/mocks/github.com/dymensionxyz/dymint/settlement/mock_ClientI.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.0. DO NOT EDIT. +// Code generated by mockery v2.42.3. DO NOT EDIT. package settlement diff --git a/mocks/github.com/dymensionxyz/dymint/store/mock_Store.go b/mocks/github.com/dymensionxyz/dymint/store/mock_Store.go index 7235d0ec5..639a4aa1e 100644 --- a/mocks/github.com/dymensionxyz/dymint/store/mock_Store.go +++ b/mocks/github.com/dymensionxyz/dymint/store/mock_Store.go @@ -1,12 +1,15 @@ -// Code generated by mockery v2.43.0. DO NOT EDIT. +// Code generated by mockery v2.42.3. DO NOT EDIT. package store import ( - store "github.com/dymensionxyz/dymint/store" + cid "github.com/ipfs/go-cid" mock "github.com/stretchr/testify/mock" + state "github.com/tendermint/tendermint/proto/tendermint/state" + store "github.com/dymensionxyz/dymint/store" + tenderminttypes "github.com/tendermint/tendermint/types" types "github.com/dymensionxyz/dymint/types" @@ -26,8 +29,21 @@ func (_m *MockStore) EXPECT() *MockStore_Expecter { } // Close provides a mock function with given fields: -func (_m *MockStore) Close() { - _m.Called() +func (_m *MockStore) Close() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Close") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 } // MockStore_Close_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Close' @@ -47,12 +63,67 @@ func (_c *MockStore_Close_Call) Run(run func()) *MockStore_Close_Call { return _c } -func (_c *MockStore_Close_Call) Return() *MockStore_Close_Call { - _c.Call.Return() +func (_c *MockStore_Close_Call) Return(_a0 error) *MockStore_Close_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockStore_Close_Call) RunAndReturn(run func() error) *MockStore_Close_Call { + _c.Call.Return(run) + return _c +} + +// LoadBaseHeight provides a mock function with given fields: +func (_m *MockStore) LoadBaseHeight() (uint64, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for LoadBaseHeight") + } + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func() (uint64, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() uint64); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStore_LoadBaseHeight_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadBaseHeight' +type MockStore_LoadBaseHeight_Call struct { + *mock.Call +} + +// LoadBaseHeight is a helper method to define mock.On call +func (_e *MockStore_Expecter) LoadBaseHeight() *MockStore_LoadBaseHeight_Call { + return &MockStore_LoadBaseHeight_Call{Call: _e.mock.On("LoadBaseHeight")} +} + +func (_c *MockStore_LoadBaseHeight_Call) Run(run func()) *MockStore_LoadBaseHeight_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockStore_LoadBaseHeight_Call) Return(_a0 uint64, _a1 error) *MockStore_LoadBaseHeight_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *MockStore_Close_Call) RunAndReturn(run func()) *MockStore_Close_Call { +func (_c *MockStore_LoadBaseHeight_Call) RunAndReturn(run func() (uint64, error)) *MockStore_LoadBaseHeight_Call { _c.Call.Return(run) return _c } @@ -173,6 +244,62 @@ func (_c *MockStore_LoadBlockByHash_Call) RunAndReturn(run func([32]byte) (*type return _c } +// LoadBlockCid provides a mock function with given fields: height +func (_m *MockStore) LoadBlockCid(height uint64) (cid.Cid, error) { + ret := _m.Called(height) + + if len(ret) == 0 { + panic("no return value specified for LoadBlockCid") + } + + var r0 cid.Cid + var r1 error + if rf, ok := ret.Get(0).(func(uint64) (cid.Cid, error)); ok { + return rf(height) + } + if rf, ok := ret.Get(0).(func(uint64) cid.Cid); ok { + r0 = rf(height) + } else { + r0 = ret.Get(0).(cid.Cid) + } + + if rf, ok := ret.Get(1).(func(uint64) error); ok { + r1 = rf(height) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStore_LoadBlockCid_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadBlockCid' +type MockStore_LoadBlockCid_Call struct { + *mock.Call +} + +// LoadBlockCid is a helper method to define mock.On call +// - height uint64 +func (_e *MockStore_Expecter) LoadBlockCid(height interface{}) *MockStore_LoadBlockCid_Call { + return &MockStore_LoadBlockCid_Call{Call: _e.mock.On("LoadBlockCid", height)} +} + +func (_c *MockStore_LoadBlockCid_Call) Run(run func(height uint64)) *MockStore_LoadBlockCid_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint64)) + }) + return _c +} + +func (_c *MockStore_LoadBlockCid_Call) Return(_a0 cid.Cid, _a1 error) *MockStore_LoadBlockCid_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockStore_LoadBlockCid_Call) RunAndReturn(run func(uint64) (cid.Cid, error)) *MockStore_LoadBlockCid_Call { + _c.Call.Return(run) + return _c +} + // LoadBlockResponses provides a mock function with given fields: height func (_m *MockStore) LoadBlockResponses(height uint64) (*state.ABCIResponses, error) { ret := _m.Called(height) @@ -231,6 +358,61 @@ func (_c *MockStore_LoadBlockResponses_Call) RunAndReturn(run func(uint64) (*sta return _c } +// LoadBlockSyncBaseHeight provides a mock function with given fields: +func (_m *MockStore) LoadBlockSyncBaseHeight() (uint64, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for LoadBlockSyncBaseHeight") + } + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func() (uint64, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() uint64); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStore_LoadBlockSyncBaseHeight_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadBlockSyncBaseHeight' +type MockStore_LoadBlockSyncBaseHeight_Call struct { + *mock.Call +} + +// LoadBlockSyncBaseHeight is a helper method to define mock.On call +func (_e *MockStore_Expecter) LoadBlockSyncBaseHeight() *MockStore_LoadBlockSyncBaseHeight_Call { + return &MockStore_LoadBlockSyncBaseHeight_Call{Call: _e.mock.On("LoadBlockSyncBaseHeight")} +} + +func (_c *MockStore_LoadBlockSyncBaseHeight_Call) Run(run func()) *MockStore_LoadBlockSyncBaseHeight_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockStore_LoadBlockSyncBaseHeight_Call) Return(_a0 uint64, _a1 error) *MockStore_LoadBlockSyncBaseHeight_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockStore_LoadBlockSyncBaseHeight_Call) RunAndReturn(run func() (uint64, error)) *MockStore_LoadBlockSyncBaseHeight_Call { + _c.Call.Return(run) + return _c +} + // LoadCommit provides a mock function with given fields: height func (_m *MockStore) LoadCommit(height uint64) (*types.Commit, error) { ret := _m.Called(height) @@ -347,6 +529,61 @@ func (_c *MockStore_LoadCommitByHash_Call) RunAndReturn(run func([32]byte) (*typ return _c } +// LoadIndexerBaseHeight provides a mock function with given fields: +func (_m *MockStore) LoadIndexerBaseHeight() (uint64, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for LoadIndexerBaseHeight") + } + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func() (uint64, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() uint64); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStore_LoadIndexerBaseHeight_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadIndexerBaseHeight' +type MockStore_LoadIndexerBaseHeight_Call struct { + *mock.Call +} + +// LoadIndexerBaseHeight is a helper method to define mock.On call +func (_e *MockStore_Expecter) LoadIndexerBaseHeight() *MockStore_LoadIndexerBaseHeight_Call { + return &MockStore_LoadIndexerBaseHeight_Call{Call: _e.mock.On("LoadIndexerBaseHeight")} +} + +func (_c *MockStore_LoadIndexerBaseHeight_Call) Run(run func()) *MockStore_LoadIndexerBaseHeight_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockStore_LoadIndexerBaseHeight_Call) Return(_a0 uint64, _a1 error) *MockStore_LoadIndexerBaseHeight_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockStore_LoadIndexerBaseHeight_Call) RunAndReturn(run func() (uint64, error)) *MockStore_LoadIndexerBaseHeight_Call { + _c.Call.Return(run) + return _c +} + // LoadState provides a mock function with given fields: func (_m *MockStore) LoadState() (*types.State, error) { ret := _m.Called() @@ -509,27 +746,27 @@ func (_c *MockStore_NewBatch_Call) RunAndReturn(run func() store.KVBatch) *MockS return _c } -// PruneBlocks provides a mock function with given fields: from, to -func (_m *MockStore) PruneBlocks(from uint64, to uint64) (uint64, error) { - ret := _m.Called(from, to) +// PruneStore provides a mock function with given fields: to, logger +func (_m *MockStore) PruneStore(to uint64, logger types.Logger) (uint64, error) { + ret := _m.Called(to, logger) if len(ret) == 0 { - panic("no return value specified for PruneBlocks") + panic("no return value specified for PruneStore") } var r0 uint64 var r1 error - if rf, ok := ret.Get(0).(func(uint64, uint64) (uint64, error)); ok { - return rf(from, to) + if rf, ok := ret.Get(0).(func(uint64, types.Logger) (uint64, error)); ok { + return rf(to, logger) } - if rf, ok := ret.Get(0).(func(uint64, uint64) uint64); ok { - r0 = rf(from, to) + if rf, ok := ret.Get(0).(func(uint64, types.Logger) uint64); ok { + r0 = rf(to, logger) } else { r0 = ret.Get(0).(uint64) } - if rf, ok := ret.Get(1).(func(uint64, uint64) error); ok { - r1 = rf(from, to) + if rf, ok := ret.Get(1).(func(uint64, types.Logger) error); ok { + r1 = rf(to, logger) } else { r1 = ret.Error(1) } @@ -537,31 +774,123 @@ func (_m *MockStore) PruneBlocks(from uint64, to uint64) (uint64, error) { return r0, r1 } -// MockStore_PruneBlocks_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PruneBlocks' -type MockStore_PruneBlocks_Call struct { +// MockStore_PruneStore_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PruneStore' +type MockStore_PruneStore_Call struct { *mock.Call } -// PruneBlocks is a helper method to define mock.On call -// - from uint64 +// PruneStore is a helper method to define mock.On call // - to uint64 -func (_e *MockStore_Expecter) PruneBlocks(from interface{}, to interface{}) *MockStore_PruneBlocks_Call { - return &MockStore_PruneBlocks_Call{Call: _e.mock.On("PruneBlocks", from, to)} +// - logger types.Logger +func (_e *MockStore_Expecter) PruneStore(to interface{}, logger interface{}) *MockStore_PruneStore_Call { + return &MockStore_PruneStore_Call{Call: _e.mock.On("PruneStore", to, logger)} } -func (_c *MockStore_PruneBlocks_Call) Run(run func(from uint64, to uint64)) *MockStore_PruneBlocks_Call { +func (_c *MockStore_PruneStore_Call) Run(run func(to uint64, logger types.Logger)) *MockStore_PruneStore_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(uint64), args[1].(uint64)) + run(args[0].(uint64), args[1].(types.Logger)) }) return _c } -func (_c *MockStore_PruneBlocks_Call) Return(_a0 uint64, _a1 error) *MockStore_PruneBlocks_Call { +func (_c *MockStore_PruneStore_Call) Return(_a0 uint64, _a1 error) *MockStore_PruneStore_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *MockStore_PruneBlocks_Call) RunAndReturn(run func(uint64, uint64) (uint64, error)) *MockStore_PruneBlocks_Call { +func (_c *MockStore_PruneStore_Call) RunAndReturn(run func(uint64, types.Logger) (uint64, error)) *MockStore_PruneStore_Call { + _c.Call.Return(run) + return _c +} + +// RemoveBlockCid provides a mock function with given fields: height +func (_m *MockStore) RemoveBlockCid(height uint64) error { + ret := _m.Called(height) + + if len(ret) == 0 { + panic("no return value specified for RemoveBlockCid") + } + + var r0 error + if rf, ok := ret.Get(0).(func(uint64) error); ok { + r0 = rf(height) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockStore_RemoveBlockCid_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveBlockCid' +type MockStore_RemoveBlockCid_Call struct { + *mock.Call +} + +// RemoveBlockCid is a helper method to define mock.On call +// - height uint64 +func (_e *MockStore_Expecter) RemoveBlockCid(height interface{}) *MockStore_RemoveBlockCid_Call { + return &MockStore_RemoveBlockCid_Call{Call: _e.mock.On("RemoveBlockCid", height)} +} + +func (_c *MockStore_RemoveBlockCid_Call) Run(run func(height uint64)) *MockStore_RemoveBlockCid_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint64)) + }) + return _c +} + +func (_c *MockStore_RemoveBlockCid_Call) Return(_a0 error) *MockStore_RemoveBlockCid_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockStore_RemoveBlockCid_Call) RunAndReturn(run func(uint64) error) *MockStore_RemoveBlockCid_Call { + _c.Call.Return(run) + return _c +} + +// SaveBaseHeight provides a mock function with given fields: height +func (_m *MockStore) SaveBaseHeight(height uint64) error { + ret := _m.Called(height) + + if len(ret) == 0 { + panic("no return value specified for SaveBaseHeight") + } + + var r0 error + if rf, ok := ret.Get(0).(func(uint64) error); ok { + r0 = rf(height) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockStore_SaveBaseHeight_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveBaseHeight' +type MockStore_SaveBaseHeight_Call struct { + *mock.Call +} + +// SaveBaseHeight is a helper method to define mock.On call +// - height uint64 +func (_e *MockStore_Expecter) SaveBaseHeight(height interface{}) *MockStore_SaveBaseHeight_Call { + return &MockStore_SaveBaseHeight_Call{Call: _e.mock.On("SaveBaseHeight", height)} +} + +func (_c *MockStore_SaveBaseHeight_Call) Run(run func(height uint64)) *MockStore_SaveBaseHeight_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint64)) + }) + return _c +} + +func (_c *MockStore_SaveBaseHeight_Call) Return(_a0 error) *MockStore_SaveBaseHeight_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockStore_SaveBaseHeight_Call) RunAndReturn(run func(uint64) error) *MockStore_SaveBaseHeight_Call { _c.Call.Return(run) return _c } @@ -626,6 +955,66 @@ func (_c *MockStore_SaveBlock_Call) RunAndReturn(run func(*types.Block, *types.C return _c } +// SaveBlockCid provides a mock function with given fields: height, _a1, batch +func (_m *MockStore) SaveBlockCid(height uint64, _a1 cid.Cid, batch store.KVBatch) (store.KVBatch, error) { + ret := _m.Called(height, _a1, batch) + + if len(ret) == 0 { + panic("no return value specified for SaveBlockCid") + } + + var r0 store.KVBatch + var r1 error + if rf, ok := ret.Get(0).(func(uint64, cid.Cid, store.KVBatch) (store.KVBatch, error)); ok { + return rf(height, _a1, batch) + } + if rf, ok := ret.Get(0).(func(uint64, cid.Cid, store.KVBatch) store.KVBatch); ok { + r0 = rf(height, _a1, batch) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(store.KVBatch) + } + } + + if rf, ok := ret.Get(1).(func(uint64, cid.Cid, store.KVBatch) error); ok { + r1 = rf(height, _a1, batch) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockStore_SaveBlockCid_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveBlockCid' +type MockStore_SaveBlockCid_Call struct { + *mock.Call +} + +// SaveBlockCid is a helper method to define mock.On call +// - height uint64 +// - _a1 cid.Cid +// - batch store.KVBatch +func (_e *MockStore_Expecter) SaveBlockCid(height interface{}, _a1 interface{}, batch interface{}) *MockStore_SaveBlockCid_Call { + return &MockStore_SaveBlockCid_Call{Call: _e.mock.On("SaveBlockCid", height, _a1, batch)} +} + +func (_c *MockStore_SaveBlockCid_Call) Run(run func(height uint64, _a1 cid.Cid, batch store.KVBatch)) *MockStore_SaveBlockCid_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint64), args[1].(cid.Cid), args[2].(store.KVBatch)) + }) + return _c +} + +func (_c *MockStore_SaveBlockCid_Call) Return(_a0 store.KVBatch, _a1 error) *MockStore_SaveBlockCid_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockStore_SaveBlockCid_Call) RunAndReturn(run func(uint64, cid.Cid, store.KVBatch) (store.KVBatch, error)) *MockStore_SaveBlockCid_Call { + _c.Call.Return(run) + return _c +} + // SaveBlockResponses provides a mock function with given fields: height, responses, batch func (_m *MockStore) SaveBlockResponses(height uint64, responses *state.ABCIResponses, batch store.KVBatch) (store.KVBatch, error) { ret := _m.Called(height, responses, batch) @@ -686,6 +1075,98 @@ func (_c *MockStore_SaveBlockResponses_Call) RunAndReturn(run func(uint64, *stat return _c } +// SaveBlockSyncBaseHeight provides a mock function with given fields: height +func (_m *MockStore) SaveBlockSyncBaseHeight(height uint64) error { + ret := _m.Called(height) + + if len(ret) == 0 { + panic("no return value specified for SaveBlockSyncBaseHeight") + } + + var r0 error + if rf, ok := ret.Get(0).(func(uint64) error); ok { + r0 = rf(height) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockStore_SaveBlockSyncBaseHeight_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveBlockSyncBaseHeight' +type MockStore_SaveBlockSyncBaseHeight_Call struct { + *mock.Call +} + +// SaveBlockSyncBaseHeight is a helper method to define mock.On call +// - height uint64 +func (_e *MockStore_Expecter) SaveBlockSyncBaseHeight(height interface{}) *MockStore_SaveBlockSyncBaseHeight_Call { + return &MockStore_SaveBlockSyncBaseHeight_Call{Call: _e.mock.On("SaveBlockSyncBaseHeight", height)} +} + +func (_c *MockStore_SaveBlockSyncBaseHeight_Call) Run(run func(height uint64)) *MockStore_SaveBlockSyncBaseHeight_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint64)) + }) + return _c +} + +func (_c *MockStore_SaveBlockSyncBaseHeight_Call) Return(_a0 error) *MockStore_SaveBlockSyncBaseHeight_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockStore_SaveBlockSyncBaseHeight_Call) RunAndReturn(run func(uint64) error) *MockStore_SaveBlockSyncBaseHeight_Call { + _c.Call.Return(run) + return _c +} + +// SaveIndexerBaseHeight provides a mock function with given fields: height +func (_m *MockStore) SaveIndexerBaseHeight(height uint64) error { + ret := _m.Called(height) + + if len(ret) == 0 { + panic("no return value specified for SaveIndexerBaseHeight") + } + + var r0 error + if rf, ok := ret.Get(0).(func(uint64) error); ok { + r0 = rf(height) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockStore_SaveIndexerBaseHeight_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveIndexerBaseHeight' +type MockStore_SaveIndexerBaseHeight_Call struct { + *mock.Call +} + +// SaveIndexerBaseHeight is a helper method to define mock.On call +// - height uint64 +func (_e *MockStore_Expecter) SaveIndexerBaseHeight(height interface{}) *MockStore_SaveIndexerBaseHeight_Call { + return &MockStore_SaveIndexerBaseHeight_Call{Call: _e.mock.On("SaveIndexerBaseHeight", height)} +} + +func (_c *MockStore_SaveIndexerBaseHeight_Call) Run(run func(height uint64)) *MockStore_SaveIndexerBaseHeight_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint64)) + }) + return _c +} + +func (_c *MockStore_SaveIndexerBaseHeight_Call) Return(_a0 error) *MockStore_SaveIndexerBaseHeight_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockStore_SaveIndexerBaseHeight_Call) RunAndReturn(run func(uint64) error) *MockStore_SaveIndexerBaseHeight_Call { + _c.Call.Return(run) + return _c +} + // SaveState provides a mock function with given fields: _a0, batch func (_m *MockStore) SaveState(_a0 *types.State, batch store.KVBatch) (store.KVBatch, error) { ret := _m.Called(_a0, batch) diff --git a/mocks/github.com/tendermint/tendermint/abci/types/mock_Application.go b/mocks/github.com/tendermint/tendermint/abci/types/mock_Application.go index 8424b4c94..7393ef94e 100644 --- a/mocks/github.com/tendermint/tendermint/abci/types/mock_Application.go +++ b/mocks/github.com/tendermint/tendermint/abci/types/mock_Application.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.0. DO NOT EDIT. +// Code generated by mockery v2.42.3. DO NOT EDIT. package types diff --git a/mocks/github.com/tendermint/tendermint/proxy/mock_AppConnConsensus.go b/mocks/github.com/tendermint/tendermint/proxy/mock_AppConnConsensus.go index 61691deb8..9ec6b2d18 100644 --- a/mocks/github.com/tendermint/tendermint/proxy/mock_AppConnConsensus.go +++ b/mocks/github.com/tendermint/tendermint/proxy/mock_AppConnConsensus.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.0. DO NOT EDIT. +// Code generated by mockery v2.42.3. DO NOT EDIT. package proxy diff --git a/mocks/github.com/tendermint/tendermint/proxy/mock_AppConns.go b/mocks/github.com/tendermint/tendermint/proxy/mock_AppConns.go index 4d5b4030d..affc90a4e 100644 --- a/mocks/github.com/tendermint/tendermint/proxy/mock_AppConns.go +++ b/mocks/github.com/tendermint/tendermint/proxy/mock_AppConns.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.0. DO NOT EDIT. +// Code generated by mockery v2.42.3. DO NOT EDIT. package proxy diff --git a/p2p/block_sync.go b/p2p/block_sync.go index e7bda4bf2..f8be1e2c0 100644 --- a/p2p/block_sync.go +++ b/p2p/block_sync.go @@ -113,5 +113,5 @@ func (blocksync *BlockSync) LoadBlock(ctx context.Context, cid cid.Cid) (BlockDa // RemoveBlock removes the block from the DAGservice. func (blocksync *BlockSync) DeleteBlock(ctx context.Context, cid cid.Cid) error { - return blocksync.dsrv.Remove(ctx, cid) + return blocksync.dsrv.DeleteBlock(ctx, cid) } diff --git a/p2p/block_sync_dag.go b/p2p/block_sync_dag.go index 18d78dca3..d9df4d440 100644 --- a/p2p/block_sync_dag.go +++ b/p2p/block_sync_dag.go @@ -112,6 +112,23 @@ func (bsDagService *BlockSyncDagService) LoadBlock(ctx context.Context, cid cid. return data, nil } +func (bsDagService *BlockSyncDagService) DeleteBlock(ctx context.Context, cid cid.Cid) error { + // first it gets the root node + root, err := bsDagService.Get(ctx, cid) + if err != nil { + return err + } + + // then it iterates all the cids to remove them from the block store + for _, l := range root.Links() { + err := bsDagService.Remove(ctx, l.Cid) + if err != nil { + return err + } + } + return nil +} + // dagReader is used to read the DAG (all the block chunks) from the root (IPLD) node func dagReader(root ipld.Node, ds ipld.DAGService) (io.Reader, error) { ctx := context.Background() diff --git a/p2p/client.go b/p2p/client.go index 9ea2168a6..ef2611120 100644 --- a/p2p/client.go +++ b/p2p/client.go @@ -3,6 +3,7 @@ package p2p import ( "context" "encoding/hex" + "errors" "fmt" "strconv" "strings" @@ -204,6 +205,7 @@ func (c *Client) SaveBlock(ctx context.Context, height uint64, blockBytes []byte if !c.conf.BlockSyncEnabled { return nil } + cid, err := c.blocksync.SaveBlock(ctx, blockBytes) if err != nil { return fmt.Errorf("blocksync add block: %w", err) @@ -220,27 +222,44 @@ func (c *Client) SaveBlock(ctx context.Context, height uint64, blockBytes []byte } // RemoveBlocks is used to prune blocks from the block sync datastore. -func (c *Client) RemoveBlocks(ctx context.Context, from, to uint64) error { - if from <= 0 { - return fmt.Errorf("from height must be greater than 0: %w", gerrc.ErrInvalidArgument) - } +func (c *Client) RemoveBlocks(ctx context.Context, to uint64) (uint64, error) { + prunedBlocks := uint64(0) - if to <= from { - return fmt.Errorf("to height must be greater than from height: to: %d: from: %d: %w", to, from, gerrc.ErrInvalidArgument) + from, err := c.store.LoadBlockSyncBaseHeight() + if errors.Is(err, gerrc.ErrNotFound) { + c.logger.Error("load blocksync base height", "err", err) + } else if err != nil { + return prunedBlocks, err } for h := from; h < to; h++ { cid, err := c.store.LoadBlockCid(h) if err != nil { - return fmt.Errorf("load block id from store %d: %w", h, err) + c.logger.Error("load block id from store", "height", h, "err", err) + continue } + + err = c.store.RemoveBlockCid(h) + if err != nil { + c.logger.Error("remove cid from dymint store", "height", h, "cid", cid, "err", err) + } + err = c.blocksync.DeleteBlock(ctx, cid) if err != nil { - return fmt.Errorf("remove block height %d: %w", h, err) + c.logger.Error("remove blocksync block", "height", h, "err", err) + continue } + + prunedBlocks++ } - return nil + + err = c.store.SaveBlockSyncBaseHeight(to) + if err != nil { + return prunedBlocks, err + } + + return prunedBlocks, nil } // AdvertiseBlockIdToDHT is used to advertise the identifier (cid) for a specific block height to the DHT, using a PutValue operation @@ -619,7 +638,11 @@ func (c *Client) advertiseBlockSyncCids(ctx context.Context) { if err != nil { return } - for h := state.BaseHeight; h <= state.Height(); h++ { + baseHeight, err := c.store.LoadBaseHeight() + if err != nil { + return + } + for h := baseHeight; h <= state.Height(); h++ { id, err := c.store.LoadBlockCid(h) if err != nil || id == cid.Undef { diff --git a/proto/types/dymint/state.proto b/proto/types/dymint/state.proto index b75f8187c..70e2984fa 100755 --- a/proto/types/dymint/state.proto +++ b/proto/types/dymint/state.proto @@ -37,5 +37,5 @@ message State { bytes app_hash = 15; uint64 last_store_height = 16 [(gogoproto.customname) = "LastStoreHeight"]; - uint64 base_height = 17; + reserved 17; } diff --git a/rpc/client/client.go b/rpc/client/client.go index 5fb78c44e..6ed5b54b5 100644 --- a/rpc/client/client.go +++ b/rpc/client/client.go @@ -26,6 +26,7 @@ import ( "github.com/dymensionxyz/dymint/node" "github.com/dymensionxyz/dymint/types" "github.com/dymensionxyz/dymint/version" + "github.com/dymensionxyz/gerr-cosmos/gerrc" ) const ( @@ -312,8 +313,13 @@ func (c *Client) GenesisChunked(context context.Context, id uint) (*ctypes.Resul func (c *Client) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) { const limit int64 = 20 - minHeight, maxHeight, err := filterMinMax( - 0, // FIXME: we might be pruned + baseHeight, err := c.node.BlockManager.Store.LoadBaseHeight() + if err != nil && !errors.Is(err, gerrc.ErrNotFound) { + return nil, err + } + + minHeight, maxHeight, err = filterMinMax( + int64(baseHeight), int64(c.node.GetBlockManagerHeight()), minHeight, maxHeight, diff --git a/store/pruning.go b/store/pruning.go index 6b3950c43..5811ff5e8 100644 --- a/store/pruning.go +++ b/store/pruning.go @@ -1,21 +1,64 @@ package store import ( + "errors" "fmt" + "github.com/dymensionxyz/dymint/types" "github.com/dymensionxyz/gerr-cosmos/gerrc" ) -// PruneBlocks removes block up to (but not including) a height. It returns number of blocks pruned. -func (s *DefaultStore) PruneBlocks(from, to uint64) (uint64, error) { - if from <= 0 { - return 0, fmt.Errorf("from height must be greater than 0: %w", gerrc.ErrInvalidArgument) +// PruneStore removes blocks up to (but not including) a height. It returns number of blocks pruned. +func (s *DefaultStore) PruneStore(to uint64, logger types.Logger) (uint64, error) { + pruned := uint64(0) + from, err := s.LoadBaseHeight() + if errors.Is(err, gerrc.ErrNotFound) { + logger.Error("load store base height", "err", err) + } else if err != nil { + return pruned, err } - if to <= from { - return 0, fmt.Errorf("to height must be greater than from height: to: %d: from: %d: %w", to, from, gerrc.ErrInvalidArgument) + pruned, err = s.pruneHeights(from, to, logger) + if err != nil { + return pruned, fmt.Errorf("pruning blocks. from: %d to: %d: err:%w", from, to, err) } + err = s.SaveBaseHeight(to) + if err != nil { + logger.Error("saving base height", "error", err) + } + return pruned, nil +} + +// pruneHeights prunes all store entries that are stored along blocks (blocks,commit and block hash) +func (s *DefaultStore) pruneHeights(from, to uint64, logger types.Logger) (uint64, error) { + pruneBlocks := func(batch KVBatch, height uint64) error { + hash, err := s.loadHashFromIndex(height) + if err != nil { + return err + } + if err := batch.Delete(getBlockKey(hash)); err != nil { + return err + } + if err := batch.Delete(getCommitKey(hash)); err != nil { + return err + } + if err := batch.Delete(getIndexKey(height)); err != nil { + return err + } + if err := batch.Delete(getResponsesKey(height)); err != nil { + return err + } + + return nil + } + + prunedBlocks, err := s.prune(from, to, pruneBlocks, logger) + return prunedBlocks, err +} + +// prune is the common function for all pruning that iterates through all heights and prunes according to the pruning function set +func (s *DefaultStore) prune(from, to uint64, prune func(batch KVBatch, height uint64) error, logger types.Logger) (uint64, error) { pruned := uint64(0) batch := s.db.NewBatch() defer batch.Discard() @@ -29,29 +72,11 @@ func (s *DefaultStore) PruneBlocks(from, to uint64) (uint64, error) { } for h := from; h < to; h++ { - hash, err := s.loadHashFromIndex(h) + err := prune(batch, h) if err != nil { + logger.Debug("unable to prune", "height", h, "err", err) continue } - if err := batch.Delete(getBlockKey(hash)); err != nil { - return 0, err - } - if err := batch.Delete(getCommitKey(hash)); err != nil { - return 0, err - } - if err := batch.Delete(getIndexKey(h)); err != nil { - return 0, err - } - if err := batch.Delete(getResponsesKey(h)); err != nil { - return 0, err - } - if err := batch.Delete(getValidatorsKey(h)); err != nil { - return 0, err - } - if err := batch.Delete(getCidKey(h)); err != nil { - return 0, err - } - pruned++ // flush every 1000 blocks to avoid batches becoming too large @@ -63,11 +88,12 @@ func (s *DefaultStore) PruneBlocks(from, to uint64) (uint64, error) { batch.Discard() batch = s.db.NewBatch() } - } + } err := flush(batch, to) if err != nil { return 0, err } + return pruned, nil } diff --git a/store/pruning_test.go b/store/pruning_test.go index 3a75cb508..b6b0ccbc3 100644 --- a/store/pruning_test.go +++ b/store/pruning_test.go @@ -6,20 +6,19 @@ import ( "github.com/dymensionxyz/dymint/store" "github.com/dymensionxyz/dymint/testutil" "github.com/dymensionxyz/dymint/types" - "github.com/ipfs/go-cid" - mh "github.com/multiformats/go-multihash" "github.com/stretchr/testify/assert" + "github.com/tendermint/tendermint/libs/log" ) func TestStorePruning(t *testing.T) { t.Parallel() cases := []struct { - name string - blocks []*types.Block - from uint64 - to uint64 - shouldError bool + name string + blocks []*types.Block + from uint64 + to uint64 + pruned uint64 }{ {"blocks with pruning", []*types.Block{ testutil.GetRandomBlock(1, 0), @@ -27,33 +26,33 @@ func TestStorePruning(t *testing.T) { testutil.GetRandomBlock(3, 0), testutil.GetRandomBlock(4, 0), testutil.GetRandomBlock(5, 0), - }, 3, 5, false}, + }, 3, 5, 2}, {"blocks out of order", []*types.Block{ testutil.GetRandomBlock(2, 0), testutil.GetRandomBlock(3, 0), testutil.GetRandomBlock(1, 0), testutil.GetRandomBlock(5, 0), - }, 3, 5, false}, + }, 3, 5, 1}, {"with a gap", []*types.Block{ testutil.GetRandomBlock(1, 0), testutil.GetRandomBlock(9, 0), testutil.GetRandomBlock(10, 0), - }, 3, 5, false}, + }, 3, 5, 0}, {"pruning height 0", []*types.Block{ testutil.GetRandomBlock(1, 0), testutil.GetRandomBlock(2, 0), testutil.GetRandomBlock(3, 0), - }, 0, 1, true}, + }, 0, 1, 0}, {"pruning same height", []*types.Block{ testutil.GetRandomBlock(1, 0), testutil.GetRandomBlock(2, 0), testutil.GetRandomBlock(3, 0), - }, 3, 3, true}, + }, 3, 3, 0}, {"to height exceeds actual block cnt", []*types.Block{ testutil.GetRandomBlock(1, 0), testutil.GetRandomBlock(2, 0), testutil.GetRandomBlock(3, 0), - }, 2, 5, false}, // it shouldn't error it should just no-op + }, 2, 5, 2}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { @@ -61,41 +60,30 @@ func TestStorePruning(t *testing.T) { bstore := store.New(store.NewDefaultInMemoryKVStore()) savedHeights := make(map[uint64]bool) + savedRespHeights := make(map[uint64]bool) + + bstore.SaveBaseHeight(c.from) for _, block := range c.blocks { _, err := bstore.SaveBlock(block, &types.Commit{}, nil) assert.NoError(err) savedHeights[block.Header.Height] = true - blockBytes, err := block.MarshalBinary() - assert.NoError(err) - // Create a cid manually by specifying the 'prefix' parameters - pref := &cid.Prefix{ - Codec: cid.DagProtobuf, - MhLength: -1, - MhType: mh.SHA2_256, - Version: 1, - } - cid, err := pref.Sum(blockBytes) - assert.NoError(err) - _, err = bstore.SaveBlockCid(block.Header.Height, cid, nil) - assert.NoError(err) // TODO: add block responses and commits } - // And then feed it some data - //expectedCid, err := pref.Sum(block) // Validate all blocks are saved for k := range savedHeights { _, err := bstore.LoadBlock(k) assert.NoError(err) } - _, err := bstore.PruneBlocks(c.from, c.to) - if c.shouldError { - assert.Error(err) - return + for k := range savedRespHeights { + _, err := bstore.LoadBlockResponses(k) + assert.NoError(err) } + pruned, err := bstore.PruneStore(c.to, log.NewNopLogger()) + assert.Equal(c.pruned, pruned) assert.NoError(err) // Validate only blocks in the range are pruned @@ -110,16 +98,10 @@ func TestStorePruning(t *testing.T) { _, err = bstore.LoadCommit(k) assert.Error(err, "Commit at height %d should be pruned", k) - _, err = bstore.LoadBlockCid(k) - assert.Error(err, "Cid at height %d should be pruned", k) - } else { _, err := bstore.LoadBlock(k) assert.NoError(err) - _, err = bstore.LoadBlockCid(k) - assert.NoError(err) - } } }) diff --git a/store/store.go b/store/store.go index 3e09671e5..e830386c9 100644 --- a/store/store.go +++ b/store/store.go @@ -16,13 +16,16 @@ import ( ) var ( - blockPrefix = [1]byte{1} - indexPrefix = [1]byte{2} - commitPrefix = [1]byte{3} - statePrefix = [1]byte{4} - responsesPrefix = [1]byte{5} - validatorsPrefix = [1]byte{6} - cidPrefix = [1]byte{7} + blockPrefix = [1]byte{1} + indexPrefix = [1]byte{2} + commitPrefix = [1]byte{3} + statePrefix = [1]byte{4} + responsesPrefix = [1]byte{5} + validatorsPrefix = [1]byte{6} + cidPrefix = [1]byte{7} + baseHeightPrefix = [1]byte{8} + blocksyncBaseHeightPrefix = [1]byte{9} + indexerBaseHeightPrefix = [1]byte{10} ) // DefaultStore is a default store implementation. @@ -273,6 +276,53 @@ func (s *DefaultStore) LoadBlockCid(height uint64) (cid.Cid, error) { return parsedCid, nil } +func (s *DefaultStore) RemoveBlockCid(height uint64) error { + err := s.db.Delete(getCidKey(height)) + return err +} + +func (s *DefaultStore) LoadBaseHeight() (uint64, error) { + b, err := s.db.Get(getBaseHeightKey()) + if err != nil { + return 0, err + } + return binary.LittleEndian.Uint64(b), nil +} + +func (s *DefaultStore) SaveBaseHeight(height uint64) error { + b := make([]byte, 8) + binary.LittleEndian.PutUint64(b, height) + return s.db.Set(getBaseHeightKey(), b) +} + +func (s *DefaultStore) LoadBlockSyncBaseHeight() (uint64, error) { + b, err := s.db.Get(getBlockSyncBaseHeightKey()) + if err != nil { + return 0, err + } + return binary.LittleEndian.Uint64(b), nil +} + +func (s *DefaultStore) SaveBlockSyncBaseHeight(height uint64) error { + b := make([]byte, 8) + binary.LittleEndian.PutUint64(b, height) + return s.db.Set(getBlockSyncBaseHeightKey(), b) +} + +func (s *DefaultStore) LoadIndexerBaseHeight() (uint64, error) { + b, err := s.db.Get(getIndexerBaseHeightKey()) + if err != nil { + return 0, err + } + return binary.LittleEndian.Uint64(b), nil +} + +func (s *DefaultStore) SaveIndexerBaseHeight(height uint64) error { + b := make([]byte, 8) + binary.LittleEndian.PutUint64(b, height) + return s.db.Set(getIndexerBaseHeightKey(), b) +} + func getBlockKey(hash [32]byte) []byte { return append(blockPrefix[:], hash[:]...) } @@ -308,3 +358,15 @@ func getCidKey(height uint64) []byte { binary.BigEndian.PutUint64(buf, height) return append(cidPrefix[:], buf[:]...) } + +func getBaseHeightKey() []byte { + return baseHeightPrefix[:] +} + +func getBlockSyncBaseHeightKey() []byte { + return blocksyncBaseHeightPrefix[:] +} + +func getIndexerBaseHeightKey() []byte { + return indexerBaseHeightPrefix[:] +} diff --git a/store/storeIface.go b/store/storeIface.go index 503151d1a..d06bccfbf 100644 --- a/store/storeIface.go +++ b/store/storeIface.go @@ -72,11 +72,25 @@ type Store interface { LoadValidators(height uint64) (*tmtypes.ValidatorSet, error) - PruneBlocks(from, to uint64) (uint64, error) + PruneStore(to uint64, logger types.Logger) (uint64, error) Close() error SaveBlockCid(height uint64, cid cid.Cid, batch KVBatch) (KVBatch, error) LoadBlockCid(height uint64) (cid.Cid, error) + + RemoveBlockCid(height uint64) error + + LoadBaseHeight() (uint64, error) + + SaveBaseHeight(height uint64) error + + LoadBlockSyncBaseHeight() (uint64, error) + + SaveBlockSyncBaseHeight(height uint64) error + + LoadIndexerBaseHeight() (uint64, error) + + SaveIndexerBaseHeight(height uint64) error } diff --git a/test/loadtime/cmd/report/main.go b/test/loadtime/cmd/report/main.go index c981a65e4..6b132ae5d 100644 --- a/test/loadtime/cmd/report/main.go +++ b/test/loadtime/cmd/report/main.go @@ -52,7 +52,7 @@ func newBlockStore(kvstore store.KV, baseHeight uint64) *BlockStore { } return &BlockStore{ DefaultStore: store, - base: state.BaseHeight, + base: baseHeight, height: state.Height(), } } diff --git a/testutil/block.go b/testutil/block.go index 172fe4711..226f89dc5 100644 --- a/testutil/block.go +++ b/testutil/block.go @@ -99,6 +99,7 @@ func GetManagerWithProposerKey(conf config.BlockManagerConfig, proposerKey crypt GossipSubCacheSize: 50, BootstrapRetryTime: 30 * time.Second, BlockSyncRequestIntervalTime: 30 * time.Second, + BlockSyncEnabled: true, }, p2pKey, "TestChain", managerStore, pubsubServer, datastore.NewMapDatastore(), logger) if err != nil { return nil, err diff --git a/testutil/types.go b/testutil/types.go index 09cee1bb6..3cf932965 100644 --- a/testutil/types.go +++ b/testutil/types.go @@ -216,7 +216,6 @@ func GenerateState(initialHeight int64, lastBlockHeight int64) *types.State { s := &types.State{ ChainID: "test-chain", InitialHeight: uint64(initialHeight), - BaseHeight: uint64(initialHeight), AppHash: [32]byte{}, LastResultsHash: GetEmptyLastResultsHash(), Version: tmstate.Version{ diff --git a/types/pb/dymint/state.pb.go b/types/pb/dymint/state.pb.go index a5dbdefee..985c89d87 100644 --- a/types/pb/dymint/state.pb.go +++ b/types/pb/dymint/state.pb.go @@ -46,7 +46,6 @@ type State struct { LastResultsHash []byte `protobuf:"bytes,14,opt,name=last_results_hash,json=lastResultsHash,proto3" json:"last_results_hash,omitempty"` AppHash []byte `protobuf:"bytes,15,opt,name=app_hash,json=appHash,proto3" json:"app_hash,omitempty"` LastStoreHeight uint64 `protobuf:"varint,16,opt,name=last_store_height,json=lastStoreHeight,proto3" json:"last_store_height,omitempty"` - BaseHeight uint64 `protobuf:"varint,17,opt,name=base_height,json=baseHeight,proto3" json:"base_height,omitempty"` } func (m *State) Reset() { *m = State{} } @@ -187,13 +186,6 @@ func (m *State) GetLastStoreHeight() uint64 { return 0 } -func (m *State) GetBaseHeight() uint64 { - if m != nil { - return m.BaseHeight - } - return 0 -} - func init() { proto.RegisterType((*State)(nil), "dymint.State") } @@ -201,46 +193,46 @@ func init() { func init() { proto.RegisterFile("types/dymint/state.proto", fileDescriptor_4b679420add07272) } var fileDescriptor_4b679420add07272 = []byte{ - // 617 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xcd, 0x6e, 0x9b, 0x40, - 0x14, 0x85, 0x4d, 0xe3, 0xc4, 0xce, 0x38, 0x0e, 0x09, 0xe9, 0x82, 0xa4, 0x12, 0x90, 0xf4, 0x47, - 0x56, 0x17, 0x20, 0x35, 0xfb, 0x56, 0x22, 0x91, 0x6a, 0x57, 0x51, 0x55, 0xe1, 0x2a, 0x8b, 0x6e, - 0xd0, 0x00, 0x53, 0x18, 0x15, 0x33, 0x88, 0x19, 0x47, 0x71, 0x9f, 0x22, 0x4f, 0xd3, 0x67, 0xc8, - 0x32, 0xcb, 0xae, 0xdc, 0xca, 0x7e, 0x91, 0x6a, 0x66, 0x00, 0xd3, 0x58, 0x96, 0xb2, 0x33, 0xe7, - 0x7e, 0xf7, 0x70, 0x86, 0x7b, 0x3d, 0x40, 0x67, 0xb3, 0x1c, 0x51, 0x27, 0x9a, 0x4d, 0x70, 0xc6, - 0x1c, 0xca, 0x20, 0x43, 0x76, 0x5e, 0x10, 0x46, 0xb4, 0x1d, 0xa9, 0x9d, 0x3c, 0x8f, 0x49, 0x4c, - 0x84, 0xe4, 0xf0, 0x5f, 0xb2, 0x7a, 0x62, 0xc6, 0x84, 0xc4, 0x29, 0x72, 0xc4, 0x53, 0x30, 0xfd, - 0xee, 0x30, 0x3c, 0x41, 0x94, 0xc1, 0x49, 0x5e, 0x02, 0xa7, 0xd2, 0x98, 0xa1, 0x2c, 0x42, 0x85, - 0x30, 0x87, 0x41, 0x88, 0x1d, 0xa1, 0x96, 0xc8, 0xd9, 0x1a, 0x52, 0x0a, 0x0d, 0xe6, 0xcd, 0x06, - 0xe6, 0x06, 0xa6, 0x38, 0x82, 0x8c, 0x14, 0x25, 0xf7, 0x72, 0x03, 0x97, 0xc3, 0x02, 0x4e, 0x36, - 0xbf, 0x50, 0x1c, 0xb8, 0xf9, 0xc2, 0xb3, 0x5f, 0x1d, 0xb0, 0x3d, 0xe6, 0xaa, 0x76, 0x0e, 0x3a, - 0x37, 0xa8, 0xa0, 0x98, 0x64, 0xba, 0x62, 0x29, 0x83, 0xde, 0xbb, 0x63, 0x7b, 0xd5, 0x69, 0xcb, - 0x4f, 0x75, 0x2d, 0x01, 0xaf, 0x22, 0xb5, 0x63, 0xd0, 0x0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x64, 0xc2, 0x2f, 0x3a, 0x94, 0xf1, 0x7f, 0xea, 0xed, 0xec, 0x67, 0x75, - 0xeb, 0x95, 0x37, 0x45, 0x50, 0x3e, 0x07, 0x3b, 0x62, 0xc1, 0xcf, 0xff, 0x05, 0x00, 0x00, 0xff, - 0xff, 0xaf, 0x47, 0xf8, 0xdf, 0x1c, 0x05, 0x00, 0x00, + // 609 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xcf, 0x6e, 0x9b, 0x4c, + 0x14, 0xc5, 0xcd, 0x17, 0x27, 0x26, 0xe3, 0x38, 0x38, 0xe4, 0x5b, 0x90, 0x54, 0xc2, 0x24, 0xfd, + 0x23, 0xab, 0x0b, 0x90, 0x9a, 0x7d, 0x2b, 0xe1, 0x48, 0xb5, 0xa3, 0xa8, 0xaa, 0x70, 0x95, 0x45, + 0x37, 0x68, 0x80, 0x29, 0x8c, 0x8a, 0x19, 0xc4, 0x8c, 0xa3, 0xb8, 0x4f, 0x91, 0x7d, 0x5f, 0x28, + 0xcb, 0x2c, 0xbb, 0x72, 0x2b, 0xfb, 0x45, 0xaa, 0x99, 0x01, 0x9b, 0xc6, 0xb2, 0x94, 0x9d, 0x39, + 0xf7, 0x77, 0x0f, 0x67, 0xb8, 0xd7, 0x03, 0x0c, 0x36, 0xcb, 0x11, 0x75, 0xa2, 0xd9, 0x04, 0x67, + 0xcc, 0xa1, 0x0c, 0x32, 0x64, 0xe7, 0x05, 0x61, 0x44, 0xdf, 0x93, 0xda, 0xe9, 0xff, 0x31, 0x89, + 0x89, 0x90, 0x1c, 0xfe, 0x4b, 0x56, 0x4f, 0x7b, 0x31, 0x21, 0x71, 0x8a, 0x1c, 0xf1, 0x14, 0x4c, + 0xbf, 0x39, 0x0c, 0x4f, 0x10, 0x65, 0x70, 0x92, 0x97, 0xc0, 0x99, 0x34, 0x66, 0x28, 0x8b, 0x50, + 0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0xa1, 0x8c, 0x14, 0xa8, 0xda, + 0xe7, 0xae, 0xa5, 0xf4, 0x9b, 0xee, 0xf1, 0x62, 0xde, 0xd3, 0xf8, 0x22, 0x8e, 0x79, 0x4d, 0x86, + 0x91, 0xde, 0x35, 0xe1, 0xaa, 0xa9, 0xb6, 0xba, 0xea, 0x55, 0x53, 0x3d, 0xea, 0xea, 0xee, 0xf0, + 0x61, 0x61, 0x2a, 0x8f, 0x0b, 0x53, 0xf9, 0xb3, 0x30, 0x95, 0xfb, 0xa5, 0xd9, 0x78, 0x5c, 0x9a, + 0x8d, 0x5f, 0x4b, 0xb3, 0xf1, 0xd5, 0x8e, 0x31, 0x4b, 0xa6, 0x81, 0x1d, 0x92, 0x09, 0xbf, 0xcd, + 0x50, 0xc6, 0xff, 0x8e, 0x77, 0xb3, 0x1f, 0xd5, 0xd5, 0x56, 0x5e, 0x07, 0x41, 0xf9, 0x1c, 0xec, + 0x89, 0x2d, 0xbe, 0xf8, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x66, 0x06, 0x2c, 0xce, 0x01, 0x05, 0x00, + 0x00, } func (m *State) Marshal() (dAtA []byte, err error) { @@ -263,13 +255,6 @@ func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.BaseHeight != 0 { - i = encodeVarintState(dAtA, i, uint64(m.BaseHeight)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x88 - } if m.LastStoreHeight != 0 { i = encodeVarintState(dAtA, i, uint64(m.LastStoreHeight)) i-- @@ -463,9 +448,6 @@ func (m *State) Size() (n int) { if m.LastStoreHeight != 0 { n += 2 + sovState(uint64(m.LastStoreHeight)) } - if m.BaseHeight != 0 { - n += 2 + sovState(uint64(m.BaseHeight)) - } return n } @@ -942,25 +924,6 @@ func (m *State) Unmarshal(dAtA []byte) error { break } } - case 17: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field BaseHeight", wireType) - } - m.BaseHeight = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowState - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.BaseHeight |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } default: iNdEx = preIndex skippy, err := skipState(dAtA[iNdEx:]) diff --git a/types/serialization.go b/types/serialization.go index 60baf29bf..250f1801d 100644 --- a/types/serialization.go +++ b/types/serialization.go @@ -264,7 +264,6 @@ func (s *State) ToProto() (*pb.State, error) { LastBlockHeight: int64(s.Height()), NextValidators: nextValidators, Validators: validators, - BaseHeight: s.BaseHeight, LastHeightValidatorsChanged: s.LastHeightValidatorsChanged, ConsensusParams: s.ConsensusParams, LastHeightConsensusParamsChanged: s.LastHeightConsensusParamsChanged, @@ -280,7 +279,6 @@ func (s *State) FromProto(other *pb.State) error { s.ChainID = other.ChainId s.InitialHeight = uint64(other.InitialHeight) s.SetHeight(uint64(other.LastBlockHeight)) - s.BaseHeight = other.BaseHeight s.NextValidators, err = types.ValidatorSetFromProto(other.NextValidators) if err != nil { diff --git a/types/state.go b/types/state.go index 8e45a981e..1e0e6289e 100644 --- a/types/state.go +++ b/types/state.go @@ -20,9 +20,6 @@ type State struct { // LastBlockHeight=0 at genesis (ie. block(H=0) does not exist) LastBlockHeight atomic.Uint64 - // BaseHeight is the height of the first block we have in store after pruning. - BaseHeight uint64 - NextValidators *types.ValidatorSet Validators *types.ValidatorSet LastHeightValidatorsChanged int64