diff --git a/proto/sedachain/batching/v1/batching.proto b/proto/sedachain/batching/v1/batching.proto index e31906e1..1023872e 100644 --- a/proto/sedachain/batching/v1/batching.proto +++ b/proto/sedachain/batching/v1/batching.proto @@ -94,4 +94,7 @@ message Params { // MaxBatchPrunePerBlock is the maximum number of batches to prune per // block. uint64 max_batch_prune_per_block = 2; + // MaxDataResultsToCheckForPrune is the maximum number of data results to + // check for pruning per block. + uint64 max_data_results_to_check_for_prune = 3; } diff --git a/proto/sedachain/batching/v1/genesis.proto b/proto/sedachain/batching/v1/genesis.proto index f6343cd6..9f077f3a 100644 --- a/proto/sedachain/batching/v1/genesis.proto +++ b/proto/sedachain/batching/v1/genesis.proto @@ -17,7 +17,6 @@ message GenesisState { repeated BatchAssignment batch_assignments = 5 [ (gogoproto.nullable) = false ]; Params params = 6 [ (gogoproto.nullable) = false ]; - uint64 first_batch_number = 7; } // BatchAssignment represents a batch assignment for genesis export diff --git a/proto/sedachain/batching/v1/tx.proto b/proto/sedachain/batching/v1/tx.proto new file mode 100644 index 00000000..179dca32 --- /dev/null +++ b/proto/sedachain/batching/v1/tx.proto @@ -0,0 +1,28 @@ +syntax = "proto3"; +package sedachain.batching.v1; + +import "cosmos/msg/v1/msg.proto"; +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "sedachain/batching/v1/batching.proto"; + +option go_package = "github.com/sedaprotocol/seda-chain/x/batching/types"; + +// Msg service defines the batching tx gRPC methods. +service Msg { + // The UpdateParams method updates the module's parameters. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); +} + +// The request message for the UpdateParams method. +message MsgUpdateParams { + option (cosmos.msg.v1.signer) = "authority"; + + // Authority is the address that controls the module (defaults to x/gov unless + // overwritten). + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + Params params = 2 [ (gogoproto.nullable) = false ]; +} + +// The response message for the UpdateParams method. +message MsgUpdateParamsResponse {} diff --git a/testutil/integration.go b/testutil/integration.go index f1334f57..27c2243f 100644 --- a/testutil/integration.go +++ b/testutil/integration.go @@ -1,6 +1,7 @@ package testutil import ( + "crypto/rand" "fmt" "time" @@ -206,10 +207,23 @@ func (app *IntegationApp) AddTime(seconds int64) { } // AddBlock increments the block number of the application context. +// It also sets the last commit hash to a random value. func (app *IntegationApp) AddBlock() { app.ctx = app.ctx.WithBlockHeight(app.ctx.BlockHeader().Height + 1) } +func (app *IntegationApp) SetRandomLastCommitHash() { + randomBytes := make([]byte, 32) + _, err := rand.Read(randomBytes) + if err != nil { + panic(err) + } + + newHeader := app.ctx.BlockHeader() + newHeader.LastCommitHash = randomBytes + app.ctx = app.ctx.WithBlockHeader(newHeader) +} + // QueryHelper returns the application query helper. // It can be used when registering query services. func (app *IntegationApp) QueryHelper() *baseapp.QueryServiceTestHelper { diff --git a/x/batching/keeper/benchmark_endblock_test.go b/x/batching/keeper/benchmark_endblock_test.go index 6ffc5953..8a28566c 100644 --- a/x/batching/keeper/benchmark_endblock_test.go +++ b/x/batching/keeper/benchmark_endblock_test.go @@ -1,11 +1,8 @@ package keeper_test import ( - "os" - "runtime/pprof" "testing" - "github.com/sedaprotocol/seda-chain/x/batching/types" "github.com/stretchr/testify/require" ) @@ -17,12 +14,6 @@ func BenchmarkBatchPruning(b *testing.B) { numBatchesToKeep := uint64(1000) maxBatchPrunePerBlock := uint64(100) - err := f.batchingKeeper.SetParams(f.Context(), types.Params{ - NumBatchesToKeep: numBatchesToKeep, - MaxBatchPrunePerBlock: maxBatchPrunePerBlock, - }) - require.NoError(b, err) - for range numBatches { f.AddBlock() @@ -34,16 +25,35 @@ func BenchmarkBatchPruning(b *testing.B) { require.NoError(b, err) } - cpuFile, err := os.Create("cpu_refactor_new.out") - require.NoError(b, err) - defer cpuFile.Close() + for b.Loop() { + _, err := f.batchingKeeper.PruneBatches(f.Context(), numBatchesToKeep, maxBatchPrunePerBlock) + require.NoError(b, err) + } +} + +func BenchmarkDataResultPruning(b *testing.B) { + f := initFixture(b) - err = pprof.StartCPUProfile(cpuFile) - require.NoError(b, err) - defer pprof.StopCPUProfile() + maxDataResultsToCheckForPrune := uint64(100) + + // Create 10 data results for each of 1000 batches + for i := range uint64(100) { + f.AddBlock() + + dataResults := generateDataResults(b, 10) + for _, dataResult := range dataResults { + err := f.batchingKeeper.SetDataResultForBatching(f.Context(), dataResult) + require.NoError(b, err) + err = f.batchingKeeper.MarkDataResultAsBatched(f.Context(), dataResult, i) + require.NoError(b, err) + } + } for b.Loop() { - err = f.batchingKeeper.PruneBatches(f.Context()) + f.AddBlock() + f.SetRandomLastCommitHash() + + err := f.batchingKeeper.PruneDataResults(f.Context(), maxDataResultsToCheckForPrune, 2000) require.NoError(b, err) } } diff --git a/x/batching/keeper/data_result.go b/x/batching/keeper/data_result.go index c6596adc..d3f7fa9b 100644 --- a/x/batching/keeper/data_result.go +++ b/x/batching/keeper/data_result.go @@ -15,6 +15,11 @@ func (k Keeper) SetDataResultForBatching(ctx context.Context, result types.DataR return k.dataResults.Set(ctx, collections.Join3(false, result.DrId, result.DrBlockHeight), result) } +// RemoveDataResult removes a data result from the store. +func (k Keeper) RemoveDataResult(ctx context.Context, batched bool, dataReqID string, dataReqHeight uint64) error { + return k.dataResults.Remove(ctx, collections.Join3(batched, dataReqID, dataReqHeight)) +} + // MarkDataResultAsBatched removes the "unbatched" variant of the given // data result and stores a "batched" variant. func (k Keeper) MarkDataResultAsBatched(ctx context.Context, result types.DataResult, batchNum uint64) error { @@ -147,6 +152,10 @@ func (k Keeper) GetBatchAssignment(ctx context.Context, dataReqID string, dataRe return k.batchAssignments.Get(ctx, collections.Join(dataReqID, dataReqHeight)) } +func (k Keeper) RemoveBatchAssignment(ctx context.Context, dataReqID string, dataReqHeight uint64) error { + return k.batchAssignments.Remove(ctx, collections.Join(dataReqID, dataReqHeight)) +} + // getAllBatchAssignments retrieves all batch assignments from the store. // Used for genesis export. func (k Keeper) getAllBatchAssignments(ctx context.Context) ([]types.BatchAssignment, error) { diff --git a/x/batching/keeper/endblock.go b/x/batching/keeper/endblock.go index 1d517c0a..2e509d5c 100644 --- a/x/batching/keeper/endblock.go +++ b/x/batching/keeper/endblock.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sedaprotocol/seda-chain/app/utils" @@ -24,97 +25,44 @@ func (k Keeper) EndBlock(ctx sdk.Context) error { if err != nil { return err } - if !isActivated { - k.Logger(ctx).Info("skip batching since proving scheme has not been activated", "index", sedatypes.SEDAKeyIndexSecp256k1) - return nil - } - batch, dataEntries, valEntries, err := k.ConstructBatch(ctx) - if err != nil { - if errors.Is(err, types.ErrNoBatchingUpdate) { + if isActivated { + batch, dataEntries, valEntries, err := k.ConstructBatch(ctx) + if err != nil { + if !errors.Is(err, types.ErrNoBatchingUpdate) { + return err + } k.Logger(ctx).Info("skip batch creation due to no update", "height", ctx.BlockHeight()) - return nil + } else { + err = k.SetNewBatch(ctx, batch, dataEntries, valEntries) + if err != nil { + return err + } } - return err - } - - err = k.SetNewBatch(ctx, batch, dataEntries, valEntries) - if err != nil { - return err + } else { + k.Logger(ctx).Info("skip batching since proving scheme has not been activated", "index", sedatypes.SEDAKeyIndexSecp256k1) } - return k.PruneBatches(ctx) -} - -// PruneBatches prunes batches and their associated data based on module -// parameters NumBatchesToKeep and MaxBatchPrunePerBlock. -func (k Keeper) PruneBatches(ctx sdk.Context) error { params, err := k.GetParams(ctx) if err != nil { return err } - // Note the current batch number here has not been used yet. - currentBatchNum, err := k.GetCurrentBatchNum(ctx) - if err != nil { - return err - } - firstBatchNum, err := k.firstBatchNumber.Get(ctx) + lastPrunedBatchNum, err := k.PruneBatches(ctx, params.NumBatchesToKeep, params.MaxBatchPrunePerBlock) if err != nil { - return err - } - if currentBatchNum-firstBatchNum <= params.NumBatchesToKeep { - k.Logger(ctx).Info("skip batch pruning", "current_batch_num", currentBatchNum, "first_batch_num", firstBatchNum) + telemetry.SetGauge(1, types.TelemetryKeyBatchingPruningFail) + k.Logger(ctx).Error("error while pruning batches", "err", err) return nil } - // Prune range is [firstBatchNum, newFirstBatchNum) - firstBatchHeight, err := k.batches.Indexes.Number.MatchExact(ctx, firstBatchNum) - if err != nil { - return err - } - - newFirstBatchNum := min(firstBatchNum+params.MaxBatchPrunePerBlock, currentBatchNum-params.NumBatchesToKeep) - newFirstBatchHeight, err := k.batchIndex.Get(ctx, newFirstBatchNum) + err = k.PruneDataResults(ctx, params.MaxDataResultsToCheckForPrune, lastPrunedBatchNum) if err != nil { - return err - } - - // Clear batches and their associated data. - batchNumRng := new(collections.Range[uint64]).StartInclusive(firstBatchNum).EndExclusive(newFirstBatchNum) - err = k.batchIndex.Clear(ctx, batchNumRng) - if err != nil { - return err - } - err = k.dataResultTreeEntries.Clear(ctx, batchNumRng) - if err != nil { - return err - } - - batchHeightRng := new(collections.Range[int64]).StartInclusive(firstBatchHeight).EndExclusive(newFirstBatchHeight) - err = k.batchesMap.Clear(ctx, batchHeightRng) - if err != nil { - return err - } - - valRng := new(collections.Range[collections.Pair[uint64, []byte]]). - StartInclusive(collections.PairPrefix[uint64, []byte](firstBatchNum)). - EndExclusive(collections.PairPrefix[uint64, []byte](newFirstBatchNum)) - err = k.validatorTreeEntries.Clear(ctx, valRng) - if err != nil { - return err - } - err = k.batchSignatures.Clear(ctx, valRng) - if err != nil { - return err - } - - err = k.firstBatchNumber.Set(ctx, newFirstBatchNum) - if err != nil { - return err + telemetry.SetGauge(1, types.TelemetryKeyBatchingPruningFail) + k.Logger(ctx).Error("error while pruning data results", "err", err) + return nil } - k.Logger(ctx).Info("successfully pruned batch data") + telemetry.SetGauge(0, types.TelemetryKeyBatchingPruningFail) return nil } diff --git a/x/batching/keeper/endblock_pruning.go b/x/batching/keeper/endblock_pruning.go new file mode 100644 index 00000000..8530b802 --- /dev/null +++ b/x/batching/keeper/endblock_pruning.go @@ -0,0 +1,150 @@ +package keeper + +import ( + "encoding/hex" + + "golang.org/x/crypto/sha3" + + "cosmossdk.io/collections" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (k Keeper) PruneDataResults(ctx sdk.Context, maxDataResultsToCheckForPrune, lastRemovedBatchNum uint64) error { + if maxDataResultsToCheckForPrune == 0 || lastRemovedBatchNum == 0 { + k.Logger(ctx).Info("skip data result pruning", "max_data_results_to_check_for_prune", maxDataResultsToCheckForPrune, "last_removed_batch_num", lastRemovedBatchNum) + return nil + } + + // Use hash of last commit hash as starting point of the range. + hasher := sha3.NewLegacyKeccak256() + hasher.Write(ctx.BlockHeader().LastCommitHash) + hash := hasher.Sum(nil) + + var rng *collections.Range[collections.Triple[bool, string, uint64]] + if ctx.BlockHeight()%2 == 0 { + rng = new(collections.Range[collections.Triple[bool, string, uint64]]). + StartInclusive(collections.TripleSuperPrefix[bool, string, uint64](true, hex.EncodeToString(hash))) + } else { + rng = new(collections.Range[collections.Triple[bool, string, uint64]]). + EndInclusive(collections.TripleSuperPrefix[bool, string, uint64](true, hex.EncodeToString(hash))). + Descending() + } + + iter, err := k.dataResults.Iterate(ctx, rng) + if err != nil { + return err + } + defer iter.Close() + + var numChecked, numPruned uint64 + for ; iter.Valid(); iter.Next() { + kv, err := iter.KeyValue() + if err != nil { + return err + } + + batchNum, err := k.GetBatchAssignment(ctx, kv.Value.DrId, kv.Value.DrBlockHeight) + if err != nil { + return err + } + + if batchNum <= lastRemovedBatchNum { + err = k.RemoveDataResult(ctx, true, kv.Value.DrId, kv.Value.DrBlockHeight) + if err != nil { + return err + } + err = k.RemoveBatchAssignment(ctx, kv.Value.DrId, kv.Value.DrBlockHeight) + if err != nil { + return err + } + numPruned++ + } + + numChecked++ + if numChecked == maxDataResultsToCheckForPrune { + break + } + } + + k.Logger(ctx).Info("pruned data results", "num_checked", numChecked, "num_pruned", numPruned) + return nil +} + +// PruneBatches prunes batches and their associated data based on module +// parameters NumBatchesToKeep and MaxBatchPrunePerBlock. It returns the +// batch number of the last pruned batch. +func (k Keeper) PruneBatches(ctx sdk.Context, numBatchesToKeep, maxBatchPrunePerBlock uint64) (uint64, error) { + currentBatchNum, err := k.GetCurrentBatchNum(ctx) + if err != nil { + return 0, err + } + if currentBatchNum <= numBatchesToKeep { + k.Logger(ctx).Info("skip batch pruning", "current_batch_num", currentBatchNum, "num_batches_to_keep", numBatchesToKeep) + return 0, nil + } + + rng := new(collections.Range[uint64]).EndExclusive(currentBatchNum - numBatchesToKeep) + iter, err := k.batches.Indexes.Number.Iterate(ctx, rng) + if err != nil { + return 0, err + } + defer iter.Close() + + var firstKey *collections.Pair[uint64, int64] + var pruneCount uint64 + var lastPrunedBatchNum uint64 + for ; iter.Valid(); iter.Next() { + fullKey, err := iter.FullKey() + if err != nil { + return 0, err + } + if firstKey == nil { + firstKey = &fullKey + } + + batchNum, batchHeight := fullKey.K1(), fullKey.K2() + if batchNum >= currentBatchNum-numBatchesToKeep { + // Should not happen because of the range configuration. + break + } + + err = k.batches.Remove(ctx, batchHeight) + if err != nil { + return 0, err + } + k.Logger(ctx).Info("pruned batch", "batch_num", batchNum) + + lastPrunedBatchNum = batchNum + + pruneCount++ + if pruneCount == maxBatchPrunePerBlock { + break + } + } + + if firstKey == nil { + // This means nothing was pruned. + k.Logger(ctx).Info("no batches to prune") + return 0, nil + } + + dataRng := new(collections.Range[uint64]).EndExclusive(firstKey.K1() + pruneCount) + err = k.dataResultTreeEntries.Clear(ctx, dataRng) + if err != nil { + return 0, err + } + + valRng := new(collections.Range[collections.Pair[uint64, []byte]]). + EndExclusive(collections.PairPrefix[uint64, []byte](firstKey.K1() + pruneCount)) + err = k.validatorTreeEntries.Clear(ctx, valRng) + if err != nil { + return 0, err + } + err = k.batchSignatures.Clear(ctx, valRng) + if err != nil { + return 0, err + } + + return lastPrunedBatchNum, nil +} diff --git a/x/batching/keeper/endblock_test.go b/x/batching/keeper/endblock_test.go index b78a0bc5..adedbebe 100644 --- a/x/batching/keeper/endblock_test.go +++ b/x/batching/keeper/endblock_test.go @@ -30,119 +30,6 @@ import ( "github.com/sedaprotocol/seda-chain/x/batching/types" ) -func TestBatchPruning(t *testing.T) { - f := initFixture(t) - - f.addBatchSigningValidators(t, 10) - - err := f.batchingKeeper.SetParams(f.Context(), types.Params{ - NumBatchesToKeep: 75, - MaxBatchPrunePerBlock: 150, - }) - require.NoError(t, err) - - // Create 300 batches with random associated data. - for range 300 { - f.AddBlock() - - err := f.batchingKeeper.SetDataResultForBatching(f.Context(), generateDataResults(t, 1)[0]) - require.NoError(t, err) - batch, dataEntries, valEntries, err := f.batchingKeeper.ConstructBatch(f.Context()) - require.NoError(t, err) - err = f.batchingKeeper.SetNewBatch(f.Context(), batch, dataEntries, valEntries) - require.NoError(t, err) - err = f.batchingKeeper.SetBatchSigSecp256k1(f.Context(), batch.BatchNumber, valEntries[0].ValidatorAddress, generateRandomBytes(64)) - require.NoError(t, err) - } - - batches, err := f.batchingKeeper.GetAllBatches(f.Context()) - require.NoError(t, err) - require.Equal(t, 300, len(batches)) - - // Should prune first 150 batches. - err = f.batchingKeeper.PruneBatches(f.Context()) - require.NoError(t, err) - - batches, err = f.batchingKeeper.GetAllBatches(f.Context()) - require.NoError(t, err) - require.Equal(t, 150, len(batches)) - require.Equal(t, uint64(150), batches[0].BatchNumber) - require.Equal(t, uint64(299), batches[len(batches)-1].BatchNumber) - - for i := uint64(0); i <= 149; i++ { - f.checkNoBatchData(t, i) - } - for i := uint64(150); i <= 299; i++ { - f.checkBatchData(t, i) - } - - // Should prune second 75 batches. - err = f.batchingKeeper.PruneBatches(f.Context()) - require.NoError(t, err) - - batches, err = f.batchingKeeper.GetAllBatches(f.Context()) - require.NoError(t, err) - require.Equal(t, 75, len(batches)) - require.Equal(t, uint64(225), batches[0].BatchNumber) - require.Equal(t, uint64(299), batches[len(batches)-1].BatchNumber) - - for i := 0; i <= 224; i++ { - f.checkNoBatchData(t, uint64(i)) - } - for i := 225; i <= 299; i++ { - f.checkBatchData(t, uint64(i)) - } - - // Should prune nothing. - err = f.batchingKeeper.PruneBatches(f.Context()) - require.NoError(t, err) - - batches, err = f.batchingKeeper.GetAllBatches(f.Context()) - require.NoError(t, err) - require.Equal(t, 75, len(batches)) - require.Equal(t, uint64(225), batches[0].BatchNumber) - require.Equal(t, uint64(299), batches[len(batches)-1].BatchNumber) - - for i := 0; i <= 224; i++ { - f.checkNoBatchData(t, uint64(i)) - } - for i := 225; i <= 299; i++ { - f.checkBatchData(t, uint64(i)) - } -} - -func (f *fixture) checkNoBatchData(t *testing.T, batchNum uint64) { - batch, err := f.batchingKeeper.GetBatchByBatchNumber(f.Context(), batchNum) - require.ErrorIs(t, err, collections.ErrNotFound) - dataEntries, err := f.batchingKeeper.GetDataResultTreeEntries(f.Context(), batchNum) - require.ErrorIs(t, err, collections.ErrNotFound) - valEntries, _ := f.batchingKeeper.GetValidatorTreeEntries(f.Context(), batchNum) - // require.ErrorIs(t, err, collections.ErrNotFound) // this function does not error even if there are no entries. - sigs, _ := f.batchingKeeper.GetBatchSignatures(f.Context(), batchNum) - // require.ErrorIs(t, err, collections.ErrNotFound) // this function does not error even if there are no entries. - - require.Empty(t, batch, "batchNum: %d", batchNum) - require.Empty(t, dataEntries, "batchNum: %d", batchNum) - require.Empty(t, valEntries, "batchNum: %d", batchNum) - require.Empty(t, sigs, "batchNum: %d", batchNum) -} - -func (f *fixture) checkBatchData(t *testing.T, batchNum uint64) { - batch, err := f.batchingKeeper.GetBatchByBatchNumber(f.Context(), batchNum) - require.NoError(t, err) - dataEntries, err := f.batchingKeeper.GetDataResultTreeEntries(f.Context(), batchNum) - require.NoError(t, err) - valEntries, err := f.batchingKeeper.GetValidatorTreeEntries(f.Context(), batchNum) - require.NoError(t, err) - sigs, err := f.batchingKeeper.GetBatchSignatures(f.Context(), batchNum) - require.NoError(t, err) - - require.NotEmpty(t, batch) - require.NotEmpty(t, dataEntries) - require.NotEmpty(t, valEntries) - require.NotEmpty(t, sigs) -} - func Test_ConstructDataResultTree(t *testing.T) { f := initFixture(t) @@ -890,3 +777,166 @@ func (f *fixture) addBatchSigningValidatorsFromTestData(t *testing.T, testData [ } return addrs, secp256k1PubKeys, powers } + +func TestBatchPruning(t *testing.T) { + f := initFixture(t) + + f.addBatchSigningValidators(t, 10) + + numBatchesToKeep := uint64(75) + maxBatchPrunePerBlock := uint64(150) + + // Should prune nothing. + lastRemovedBatchNum, err := f.batchingKeeper.PruneBatches(f.Context(), numBatchesToKeep, maxBatchPrunePerBlock) + require.NoError(t, err) + require.Equal(t, uint64(0), lastRemovedBatchNum) + + // Create 300 batches with random associated data. + for range 300 { + f.AddBlock() + + err := f.batchingKeeper.SetDataResultForBatching(f.Context(), generateDataResults(t, 1)[0]) + require.NoError(t, err) + batch, dataEntries, valEntries, err := f.batchingKeeper.ConstructBatch(f.Context()) + require.NoError(t, err) + err = f.batchingKeeper.SetNewBatch(f.Context(), batch, dataEntries, valEntries) + require.NoError(t, err) + err = f.batchingKeeper.SetBatchSigSecp256k1(f.Context(), batch.BatchNumber, valEntries[0].ValidatorAddress, generateRandomBytes(64)) + require.NoError(t, err) + } + + batches, err := f.batchingKeeper.GetAllBatches(f.Context()) + require.NoError(t, err) + require.Equal(t, 300, len(batches)) + + // Should prune first 150 batches. + lastRemovedBatchNum, err = f.batchingKeeper.PruneBatches(f.Context(), numBatchesToKeep, maxBatchPrunePerBlock) + require.NoError(t, err) + require.Equal(t, uint64(149), lastRemovedBatchNum) + + batches, err = f.batchingKeeper.GetAllBatches(f.Context()) + require.NoError(t, err) + require.Equal(t, 150, len(batches)) + require.Equal(t, uint64(150), batches[0].BatchNumber) + require.Equal(t, uint64(299), batches[len(batches)-1].BatchNumber) + + for i := 0; i <= 149; i++ { + f.checkNoBatchData(t, uint64(i)) + } + for i := 150; i <= 299; i++ { + f.checkBatchData(t, uint64(i)) + } + + // Should prune second 75 batches. + lastRemovedBatchNum, err = f.batchingKeeper.PruneBatches(f.Context(), numBatchesToKeep, maxBatchPrunePerBlock) + require.NoError(t, err) + require.Equal(t, uint64(224), lastRemovedBatchNum) + + batches, err = f.batchingKeeper.GetAllBatches(f.Context()) + require.NoError(t, err) + require.Equal(t, 75, len(batches)) + require.Equal(t, uint64(225), batches[0].BatchNumber) + require.Equal(t, uint64(299), batches[len(batches)-1].BatchNumber) + + for i := 0; i <= 224; i++ { + f.checkNoBatchData(t, uint64(i)) + } + for i := 225; i <= 299; i++ { + f.checkBatchData(t, uint64(i)) + } + + // Should prune nothing. + lastRemovedBatchNum, err = f.batchingKeeper.PruneBatches(f.Context(), numBatchesToKeep, maxBatchPrunePerBlock) + require.NoError(t, err) + require.Equal(t, uint64(0), lastRemovedBatchNum) + + batches, err = f.batchingKeeper.GetAllBatches(f.Context()) + require.NoError(t, err) + require.Equal(t, 75, len(batches)) + require.Equal(t, uint64(225), batches[0].BatchNumber) + require.Equal(t, uint64(299), batches[len(batches)-1].BatchNumber) + + for i := 0; i <= 224; i++ { + f.checkNoBatchData(t, uint64(i)) + } + for i := 225; i <= 299; i++ { + f.checkBatchData(t, uint64(i)) + } +} + +func (f *fixture) checkNoBatchData(t *testing.T, batchNum uint64) { + batch, err := f.batchingKeeper.GetBatchByBatchNumber(f.Context(), batchNum) + require.ErrorIs(t, err, collections.ErrNotFound) + dataEntries, err := f.batchingKeeper.GetDataResultTreeEntries(f.Context(), batchNum) + require.ErrorIs(t, err, collections.ErrNotFound) + valEntries, _ := f.batchingKeeper.GetValidatorTreeEntries(f.Context(), batchNum) + // require.ErrorIs(t, err, collections.ErrNotFound) // this function does not error even if there are no entries. + sigs, _ := f.batchingKeeper.GetBatchSignatures(f.Context(), batchNum) + // require.ErrorIs(t, err, collections.ErrNotFound) // this function does not error even if there are no entries. + + require.Empty(t, batch, "batchNum: %d", batchNum) + require.Empty(t, dataEntries, "batchNum: %d", batchNum) + require.Empty(t, valEntries, "batchNum: %d", batchNum) + require.Empty(t, sigs, "batchNum: %d", batchNum) +} + +func (f *fixture) checkBatchData(t *testing.T, batchNum uint64) { + batch, err := f.batchingKeeper.GetBatchByBatchNumber(f.Context(), batchNum) + require.NoError(t, err) + dataEntries, err := f.batchingKeeper.GetDataResultTreeEntries(f.Context(), batchNum) + require.NoError(t, err) + valEntries, err := f.batchingKeeper.GetValidatorTreeEntries(f.Context(), batchNum) + require.NoError(t, err) + sigs, err := f.batchingKeeper.GetBatchSignatures(f.Context(), batchNum) + require.NoError(t, err) + + require.NotEmpty(t, batch) + require.NotEmpty(t, dataEntries) + require.NotEmpty(t, valEntries) + require.NotEmpty(t, sigs) +} + +func TestDataResultPruning(t *testing.T) { + f := initFixture(t) + + maxDataResultsToCheckForPrune := uint64(100) + + // Should prune nothing. + err := f.batchingKeeper.PruneDataResults(f.Context(), maxDataResultsToCheckForPrune, 0) + require.NoError(t, err) + + // Create 10 data results for each of 100 batches + for i := range uint64(100) { + f.AddBlock() + + dataResults := generateDataResults(t, 10) + for _, dataResult := range dataResults { + err := f.batchingKeeper.SetDataResultForBatching(f.Context(), dataResult) + require.NoError(t, err) + err = f.batchingKeeper.MarkDataResultAsBatched(f.Context(), dataResult, i) + require.NoError(t, err) + } + } + + dataResults, err := f.batchingKeeper.GetDataResults(f.Context(), true) + require.NoError(t, err) + require.Equal(t, 1000, len(dataResults)) + + i := 0 + for ; i < 30; i++ { + f.AddBlock() + f.SetRandomLastCommitHash() + + err = f.batchingKeeper.PruneDataResults(f.Context(), maxDataResultsToCheckForPrune, uint64(25+25*i)) + require.NoError(t, err) + + dataResults, err = f.batchingKeeper.GetDataResults(f.Context(), true) + require.NoError(t, err) + if len(dataResults) == 0 { + break + } + } + + require.Equal(t, 0, len(dataResults)) + t.Logf("test completed after %d iterations", i) +} diff --git a/x/batching/keeper/genesis.go b/x/batching/keeper/genesis.go index c267191a..3bf174c4 100644 --- a/x/batching/keeper/genesis.go +++ b/x/batching/keeper/genesis.go @@ -14,9 +14,6 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { if err != nil { panic(err) } - if err := k.firstBatchNumber.Set(ctx, data.FirstBatchNumber); err != nil { - panic(err) - } for _, batch := range data.Batches { err := k.setBatch(ctx, batch) if err != nil { @@ -72,10 +69,6 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) types.GenesisState { if err != nil { panic(err) } - firstBatchNumber, err := k.firstBatchNumber.Get(ctx) - if err != nil { - panic(err) - } batches, err := k.GetAllBatches(ctx) if err != nil { panic(err) @@ -92,5 +85,5 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) types.GenesisState { if err != nil { panic(err) } - return types.NewGenesisState(curBatchNum, firstBatchNumber, batches, batchData, dataResults, batchAssignments, params) + return types.NewGenesisState(curBatchNum, batches, batchData, dataResults, batchAssignments, params) } diff --git a/x/batching/keeper/keeper.go b/x/batching/keeper/keeper.go index d7bbdef1..8159f366 100644 --- a/x/batching/keeper/keeper.go +++ b/x/batching/keeper/keeper.go @@ -35,15 +35,10 @@ type Keeper struct { batchAssignments collections.Map[collections.Pair[string, uint64], uint64] currentBatchNumber collections.Sequence batches *collections.IndexedMap[int64, types.Batch, BatchIndexes] - firstBatchNumber collections.Item[uint64] validatorTreeEntries collections.Map[collections.Pair[uint64, []byte], types.ValidatorTreeEntry] dataResultTreeEntries collections.Map[uint64, types.DataResultTreeEntries] batchSignatures collections.Map[collections.Pair[uint64, []byte], types.BatchSignatures] params collections.Item[types.Params] - - // Additional maps for efficient pruning - batchesMap collections.Map[int64, types.Batch] - batchIndex collections.Map[uint64, int64] } func NewKeeper( @@ -73,7 +68,6 @@ func NewKeeper( batchAssignments: collections.NewMap(sb, types.BatchAssignmentsPrefix, "batch_assignments", collections.PairKeyCodec(collections.StringKey, collections.Uint64Key), collections.Uint64Value), currentBatchNumber: collections.NewSequence(sb, types.CurrentBatchNumberKey, "current_batch_number"), batches: collections.NewIndexedMap(sb, types.BatchesKeyPrefix, "batches", collections.Int64Key, codec.CollValue[types.Batch](cdc), NewBatchIndexes(sb)), - firstBatchNumber: collections.NewItem(sb, types.FirstBatchNumberKey, "first_batch_number", collections.Uint64Value), validatorTreeEntries: collections.NewMap(sb, types.ValidatorTreeEntriesKeyPrefix, "validator_tree_entries", collections.PairKeyCodec(collections.Uint64Key, collections.BytesKey), codec.CollValue[types.ValidatorTreeEntry](cdc)), dataResultTreeEntries: collections.NewMap(sb, types.DataResultTreeEntriesKeyPrefix, "data_result_tree_entries", collections.Uint64Key, codec.CollValue[types.DataResultTreeEntries](cdc)), batchSignatures: collections.NewMap(sb, types.BatchSignaturesKeyPrefix, "batch_signatures", collections.PairKeyCodec(collections.Uint64Key, collections.BytesKey), codec.CollValue[types.BatchSignatures](cdc)), @@ -86,11 +80,6 @@ func NewKeeper( } k.Schema = schema - // Additional maps for efficient pruning - sbTemp := collections.NewSchemaBuilder(storeService) - k.batchesMap = collections.NewMap(sbTemp, types.BatchesKeyPrefix, "batches", collections.Int64Key, codec.CollValue[types.Batch](cdc)) - k.batchIndex = collections.NewMap(sbTemp, types.BatchNumberKeyPrefix, "batch_by_number", collections.Uint64Key, collections.Int64Value) - return k } diff --git a/x/batching/types/batching.pb.go b/x/batching/types/batching.pb.go index 0eb5680f..35aa4453 100644 --- a/x/batching/types/batching.pb.go +++ b/x/batching/types/batching.pb.go @@ -441,6 +441,9 @@ type Params struct { // MaxBatchPrunePerBlock is the maximum number of batches to prune per // block. MaxBatchPrunePerBlock uint64 `protobuf:"varint,2,opt,name=max_batch_prune_per_block,json=maxBatchPrunePerBlock,proto3" json:"max_batch_prune_per_block,omitempty"` + // MaxDataResultsToCheckForPrune is the maximum number of data results to + // check for pruning per block. + MaxDataResultsToCheckForPrune uint64 `protobuf:"varint,3,opt,name=max_data_results_to_check_for_prune,json=maxDataResultsToCheckForPrune,proto3" json:"max_data_results_to_check_for_prune,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -490,6 +493,13 @@ func (m *Params) GetMaxBatchPrunePerBlock() uint64 { return 0 } +func (m *Params) GetMaxDataResultsToCheckForPrune() uint64 { + if m != nil { + return m.MaxDataResultsToCheckForPrune + } + return 0 +} + func init() { proto.RegisterType((*Batch)(nil), "sedachain.batching.v1.Batch") proto.RegisterType((*DataResultTreeEntries)(nil), "sedachain.batching.v1.DataResultTreeEntries") @@ -504,61 +514,64 @@ func init() { } var fileDescriptor_5b2a028024867de2 = []byte{ - // 864 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xcd, 0x6e, 0xeb, 0x44, - 0x14, 0xae, 0xd3, 0x34, 0x3f, 0x93, 0xa4, 0x0d, 0xd3, 0x1b, 0xe4, 0xde, 0x45, 0x1c, 0x22, 0xae, - 0x14, 0x40, 0x49, 0x08, 0x11, 0x3f, 0x12, 0x6c, 0x30, 0x20, 0x51, 0xa1, 0x7b, 0x15, 0x0d, 0xe5, - 0x2e, 0x58, 0x60, 0x4d, 0x3c, 0x23, 0xc7, 0x4a, 0xec, 0x31, 0x33, 0xe3, 0xd0, 0xbe, 0x05, 0x2f, - 0xc0, 0x86, 0x67, 0xe0, 0x1d, 0x60, 0x79, 0xc5, 0x0a, 0x81, 0x64, 0xa1, 0x76, 0x97, 0x47, 0x60, - 0x85, 0x7c, 0xc6, 0x71, 0xda, 0xb2, 0x66, 0xe5, 0x39, 0xdf, 0x77, 0xce, 0x99, 0x73, 0x66, 0xbe, - 0x33, 0x46, 0x6f, 0x2a, 0xce, 0xa8, 0xbf, 0xa2, 0x61, 0x3c, 0x5d, 0x52, 0xed, 0xaf, 0xc2, 0x38, - 0x98, 0x6e, 0x67, 0xe5, 0x7a, 0x92, 0x48, 0xa1, 0x05, 0xee, 0x95, 0x5e, 0x93, 0x92, 0xd9, 0xce, - 0x9e, 0x5e, 0xf8, 0x42, 0x45, 0x42, 0x79, 0xe0, 0x34, 0x35, 0x86, 0x89, 0x78, 0xfa, 0x24, 0x10, - 0x81, 0x30, 0x78, 0xbe, 0x32, 0xe8, 0xf0, 0xa7, 0x0a, 0x3a, 0x71, 0xf3, 0x04, 0xf8, 0x0d, 0xd4, - 0x86, 0x4c, 0x5e, 0x9c, 0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 0x72, 0x6b, 0x61, 0x0c, 0xfc, 0x0e, 0x6a, 0xfa, 0x22, 0x56, 0x3c, - 0x56, 0xa9, 0xb2, 0xdb, 0x03, 0x6b, 0xd4, 0x30, 0x47, 0x52, 0x82, 0xe4, 0xb0, 0x1c, 0x7e, 0x8f, - 0x6a, 0x0b, 0x2a, 0x69, 0xa4, 0xf0, 0x18, 0x9d, 0xc7, 0x69, 0xe4, 0xc1, 0x1b, 0xc2, 0x95, 0xa7, - 0x85, 0xb7, 0xe6, 0x3c, 0x29, 0x9e, 0xc9, 0x6e, 0x9c, 0x46, 0xae, 0x61, 0xae, 0xc4, 0x57, 0x9c, - 0x27, 0xf8, 0x23, 0x74, 0x11, 0xd1, 0x6b, 0xe3, 0xee, 0x25, 0x32, 0x8d, 0x79, 0x3e, 0x91, 0x46, - 0x45, 0xa0, 0xc1, 0x2a, 0xe9, 0x45, 0xf4, 0x1a, 0x82, 0x16, 0x39, 0xbd, 0xe0, 0x46, 0x52, 0xee, - 0xf3, 0xdf, 0x6e, 0xfb, 0xd6, 0xab, 0xdb, 0xbe, 0xf5, 0xf7, 0x6d, 0xdf, 0xfa, 0xf1, 0xae, 0x7f, - 0xf4, 0xea, 0xae, 0x7f, 0xf4, 0xc7, 0x5d, 0xff, 0xe8, 0xdb, 0xf9, 0xbd, 0xe1, 0xca, 0x3b, 0x82, - 0x27, 0xdc, 0x17, 0x1b, 0x30, 0xc6, 0xe6, 0x9f, 0x71, 0x7d, 0xf8, 0x6b, 0xc0, 0xb4, 0x2d, 0x6b, - 0xe0, 0x35, 0xff, 0x37, 0x00, 0x00, 0xff, 0xff, 0x45, 0xd9, 0xf2, 0x15, 0x58, 0x06, 0x00, 0x00, + // 904 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xcd, 0x8e, 0xe3, 0x44, + 0x10, 0x5e, 0x67, 0x32, 0xf9, 0xe9, 0x24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 0xbb, 0xe2, 0x3c, 0xce, 0xdf, 0xc9, 0x76, 0x94, 0x84, 0x33, 0xc3, 0x5c, 0x8a, + 0x2f, 0x39, 0x8f, 0xf1, 0x07, 0xe8, 0x3c, 0xa4, 0x5b, 0xe3, 0xee, 0xc6, 0x32, 0x89, 0x78, 0x36, + 0x92, 0x46, 0x46, 0x20, 0xc2, 0x32, 0xe9, 0x84, 0x74, 0x0b, 0x41, 0xf3, 0x8c, 0x9e, 0x73, 0xa3, + 0x29, 0xfc, 0x05, 0x7a, 0x2d, 0x8b, 0xbc, 0xf5, 0x1c, 0xc2, 0x6e, 0x9e, 0xcf, 0xbd, 0x95, 0xfb, + 0x9d, 0x90, 0x26, 0x9b, 0x91, 0x27, 0x79, 0x25, 0xa4, 0xdb, 0x83, 0xfc, 0xd5, 0xa5, 0x78, 0x92, + 0xb9, 0x7d, 0x26, 0x24, 0xe4, 0x9c, 0x3d, 0xfd, 0xed, 0xba, 0x6b, 0xbd, 0xb8, 0xee, 0x5a, 0x7f, + 0x5f, 0x77, 0xad, 0x1f, 0x6e, 0xba, 0x0f, 0x5e, 0xdc, 0x74, 0x1f, 0xfc, 0x71, 0xd3, 0x7d, 0xf0, + 0xcd, 0xf4, 0xd6, 0xa4, 0x66, 0xc7, 0x03, 0xff, 0x03, 0x4f, 0xac, 0xc1, 0x18, 0x9a, 0x1f, 0xd0, + 0xf6, 0xf0, 0x0b, 0x82, 0xd1, 0x5d, 0x54, 0xc0, 0x6b, 0xfa, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xc7, 0x3e, 0x8b, 0x07, 0xa5, 0x06, 0x00, 0x00, } func (m *Batch) Marshal() (dAtA []byte, err error) { @@ -867,6 +880,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.MaxDataResultsToCheckForPrune != 0 { + i = encodeVarintBatching(dAtA, i, uint64(m.MaxDataResultsToCheckForPrune)) + i-- + dAtA[i] = 0x18 + } if m.MaxBatchPrunePerBlock != 0 { i = encodeVarintBatching(dAtA, i, uint64(m.MaxBatchPrunePerBlock)) i-- @@ -1042,6 +1060,9 @@ func (m *Params) Size() (n int) { if m.MaxBatchPrunePerBlock != 0 { n += 1 + sovBatching(uint64(m.MaxBatchPrunePerBlock)) } + if m.MaxDataResultsToCheckForPrune != 0 { + n += 1 + sovBatching(uint64(m.MaxDataResultsToCheckForPrune)) + } return n } @@ -2083,6 +2104,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxDataResultsToCheckForPrune", wireType) + } + m.MaxDataResultsToCheckForPrune = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBatching + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxDataResultsToCheckForPrune |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipBatching(dAtA[iNdEx:]) diff --git a/x/batching/types/genesis.go b/x/batching/types/genesis.go index e2248b44..cae91cc8 100644 --- a/x/batching/types/genesis.go +++ b/x/batching/types/genesis.go @@ -13,7 +13,6 @@ import ( // NewGenesisState constructs a GenesisState object. func NewGenesisState( curBatchNum uint64, - firstBatchNumber uint64, batches []Batch, batchData []BatchData, dataResults []GenesisDataResult, @@ -22,7 +21,6 @@ func NewGenesisState( ) GenesisState { return GenesisState{ CurrentBatchNumber: curBatchNum, - FirstBatchNumber: firstBatchNumber, Batches: batches, BatchData: batchData, DataResults: dataResults, @@ -33,16 +31,12 @@ func NewGenesisState( // DefaultGenesisState creates a default GenesisState object. func DefaultGenesisState() *GenesisState { - state := NewGenesisState(collections.DefaultSequenceStart, 0, nil, nil, nil, nil, DefaultParams()) + state := NewGenesisState(collections.DefaultSequenceStart, nil, nil, nil, nil, DefaultParams()) return &state } // ValidateGenesis validates batching genesis data. func ValidateGenesis(gs GenesisState) error { - if gs.CurrentBatchNumber != uint64(len(gs.Batches)) { - return fmt.Errorf("current batch number %d should be equal to number of batches %d", gs.CurrentBatchNumber, len(gs.Batches)) - } - for _, batch := range gs.Batches { if batch.BatchNumber > gs.CurrentBatchNumber { return fmt.Errorf("batch number %d should not exceed current batch number %d", batch.BatchNumber, gs.CurrentBatchNumber) diff --git a/x/batching/types/genesis.pb.go b/x/batching/types/genesis.pb.go index 0a1c8be6..1c0170d4 100644 --- a/x/batching/types/genesis.pb.go +++ b/x/batching/types/genesis.pb.go @@ -33,7 +33,6 @@ type GenesisState struct { DataResults []GenesisDataResult `protobuf:"bytes,4,rep,name=data_results,json=dataResults,proto3" json:"data_results"` BatchAssignments []BatchAssignment `protobuf:"bytes,5,rep,name=batch_assignments,json=batchAssignments,proto3" json:"batch_assignments"` Params Params `protobuf:"bytes,6,opt,name=params,proto3" json:"params"` - FirstBatchNumber uint64 `protobuf:"varint,7,opt,name=first_batch_number,json=firstBatchNumber,proto3" json:"first_batch_number,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -111,13 +110,6 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetFirstBatchNumber() uint64 { - if m != nil { - return m.FirstBatchNumber - } - return 0 -} - // BatchAssignment represents a batch assignment for genesis export // and import. type BatchAssignment struct { @@ -314,43 +306,42 @@ func init() { } var fileDescriptor_eccca5d98d3cb479 = []byte{ - // 567 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x8d, 0x9b, 0x90, 0x92, 0x49, 0x50, 0x9a, 0xa5, 0x48, 0x56, 0x05, 0x26, 0x0d, 0xa8, 0x0a, - 0x52, 0x71, 0x68, 0x7b, 0x84, 0x0b, 0x11, 0x15, 0xe5, 0x00, 0x82, 0x14, 0x81, 0x40, 0x48, 0xd6, - 0x3a, 0x5e, 0x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0x3e, - 0x41, 0x63, 0x4c, 0x07, 0xa1, 0x47, 0x65, 0xcc, 0xf3, 0x0e, 0xd9, 0x2a, 0x3e, 0x58, 0xd1, 0xe1, - 0x9d, 0xc6, 0xeb, 0x06, 0x67, 0xda, 0xec, 0x9c, 0x49, 0xb3, 0xbf, 0x87, 0x6c, 0x01, 0x9c, 0x54, - 0x7f, 0x2a, 0x13, 0xce, 0xf4, 0x7a, 0xae, 0x5d, 0xa3, 0xd3, 0x1c, 0xad, 0x98, 0xeb, 0xee, 0x62, - 0xb8, 0xf5, 0x15, 0x1a, 0x7f, 0x2d, 0x32, 0x31, 0xf5, 0x6b, 0xf4, 0x50, 0xcd, 0xeb, 0xfa, 0xa5, - 0x79, 0xe4, 0x04, 0xaa, 0x73, 0x4a, 0x2a, 0x05, 0x77, 0xff, 0xa9, 0xa0, 0xea, 0x0e, 0x33, 0xd9, - 0xba, 0x2f, 0xcf, 0x27, 0x96, 0x71, 0x31, 0xb1, 0x8c, 0xdf, 0x13, 0xcb, 0xf8, 0x31, 0xb5, 0x0a, - 0x17, 0x53, 0xab, 0xf0, 0x6b, 0x6a, 0x15, 0x3e, 0x1e, 0xf9, 0xa1, 0x0c, 0x12, 0xd7, 0xee, 0xc7, - 0xc3, 0x4e, 0x4a, 0x8c, 0x47, 0xa6, 0x1f, 0x0f, 0xf0, 0xcf, 0xc3, 0xec, 0x1a, 0x7d, 0x9b, 0xdd, - 0x23, 0x79, 0x36, 0x62, 0xc2, 0x2d, 0x23, 0xea, 0xe8, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd6, - 0xac, 0xf5, 0x7d, 0x04, 0x05, 0x00, 0x00, + // 554 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xc1, 0x6e, 0xd3, 0x4c, + 0x10, 0xc7, 0xe3, 0x24, 0x5f, 0x3e, 0xb2, 0x09, 0x0a, 0x5e, 0x8a, 0x64, 0x55, 0x60, 0xdc, 0x80, + 0x2a, 0x23, 0x81, 0x4d, 0xdb, 0x23, 0x5c, 0x88, 0xa8, 0x28, 0x07, 0x10, 0xa4, 0x08, 0x04, 0x42, + 0xb2, 0xd6, 0xf6, 0xca, 0xb6, 0x94, 0xd8, 0x61, 0x77, 0x1d, 0xe8, 0x3b, 0x70, 0xe0, 0x51, 0x78, + 0x8c, 0x72, 0xeb, 0x91, 0x13, 0x42, 0xc9, 0x8b, 0x20, 0x8f, 0x77, 0x9d, 0x04, 0x92, 0xc0, 0x2d, + 0x99, 0xf9, 0xcf, 0x6f, 0xd6, 0xff, 0x99, 0x5d, 0x74, 0x8b, 0xd3, 0x90, 0x04, 0x31, 0x49, 0x52, + 0xd7, 0x27, 0x22, 0x88, 0x93, 0x34, 0x72, 0xa7, 0x07, 0x6e, 0x44, 0x53, 0xca, 0x13, 0xee, 0x4c, + 0x58, 0x26, 0x32, 0x7c, 0xad, 0x12, 0x39, 0x4a, 0xe4, 0x4c, 0x0f, 0x76, 0x77, 0xa2, 0x2c, 0xca, + 0x40, 0xe1, 0x16, 0xbf, 0x4a, 0xf1, 0xee, 0xed, 0xf5, 0xc4, 0xaa, 0x10, 0x54, 0xfd, 0xaf, 0x0d, + 0xd4, 0x7d, 0x52, 0x36, 0x39, 0x15, 0x44, 0x50, 0x7c, 0x1f, 0xed, 0x04, 0x39, 0x63, 0x34, 0x15, + 0x1e, 0x48, 0xbd, 0x34, 0x1f, 0xfb, 0x94, 0x19, 0x9a, 0xa5, 0xd9, 0xcd, 0x21, 0x96, 0xb9, 0x41, + 0x91, 0x7a, 0x0e, 0x19, 0xfc, 0x10, 0xfd, 0x0f, 0x4a, 0xca, 0x8d, 0xba, 0xd5, 0xb0, 0x3b, 0x87, + 0xd7, 0x9d, 0xb5, 0xe7, 0x74, 0xa0, 0x68, 0xd0, 0x3c, 0xff, 0x71, 0xb3, 0x36, 0x54, 0x25, 0xf8, + 0x18, 0xa1, 0xb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xb2, 0x46, 0x1a, 0xa3, 0x2f, 0xa6, + 0x26, 0x13, 0xf8, 0x3d, 0xd2, 0xa7, 0x64, 0x94, 0x84, 0x44, 0x64, 0xac, 0xea, 0x50, 0x2e, 0xd7, + 0x9d, 0x0d, 0x1d, 0x5e, 0x2b, 0xbd, 0x6a, 0x70, 0xa6, 0xc6, 0x57, 0x91, 0x14, 0xfd, 0x0d, 0x2a, + 0x47, 0xea, 0x15, 0xfe, 0x13, 0x91, 0x33, 0xaa, 0x16, 0x6e, 0xeb, 0x62, 0x9c, 0x56, 0x6a, 0x49, + 0xee, 0xf9, 0xab, 0xe1, 0xfe, 0x47, 0xa4, 0xff, 0xb1, 0x9a, 0xd8, 0x50, 0xf7, 0x2b, 0x04, 0x37, + 0x2f, 0xa9, 0xbb, 0x13, 0xe2, 0x13, 0xd4, 0x59, 0x72, 0x52, 0x3a, 0xb8, 0xf7, 0x57, 0x07, 0x65, + 0x77, 0xb4, 0xb0, 0x6d, 0xf0, 0xec, 0x7c, 0x66, 0x6a, 0x17, 0x33, 0x53, 0xfb, 0x39, 0x33, 0xb5, + 0x2f, 0x73, 0xb3, 0x76, 0x31, 0x37, 0x6b, 0xdf, 0xe7, 0x66, 0xed, 0xdd, 0x51, 0x94, 0x88, 0x38, + 0xf7, 0x9d, 0x20, 0x1b, 0xbb, 0x05, 0x18, 0x9e, 0x8d, 0x20, 0x1b, 0xc1, 0x9f, 0x7b, 0xe5, 0xfb, + 0xf2, 0x69, 0xf1, 0xc2, 0x88, 0xb3, 0x09, 0xe5, 0x7e, 0x0b, 0x54, 0x47, 0xbf, 0x02, 0x00, 0x00, + 0xff, 0xff, 0xd3, 0x84, 0x10, 0x33, 0xd6, 0x04, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -373,11 +364,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.FirstBatchNumber != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.FirstBatchNumber)) - i-- - dAtA[i] = 0x38 - } { size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -647,9 +633,6 @@ func (m *GenesisState) Size() (n int) { } l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) - if m.FirstBatchNumber != 0 { - n += 1 + sovGenesis(uint64(m.FirstBatchNumber)) - } return n } @@ -935,25 +918,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field FirstBatchNumber", wireType) - } - m.FirstBatchNumber = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.FirstBatchNumber |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/batching/types/keys.go b/x/batching/types/keys.go index 27f06d75..ea464fd6 100644 --- a/x/batching/types/keys.go +++ b/x/batching/types/keys.go @@ -20,5 +20,4 @@ var ( DataResultTreeEntriesKeyPrefix = collections.NewPrefix(6) BatchSignaturesKeyPrefix = collections.NewPrefix(7) ParamsKey = collections.NewPrefix(8) - FirstBatchNumberKey = collections.NewPrefix(9) ) diff --git a/x/batching/types/params.go b/x/batching/types/params.go index e9e84c8f..5e3e4fb2 100644 --- a/x/batching/types/params.go +++ b/x/batching/types/params.go @@ -5,15 +5,17 @@ import ( ) const ( - DefaultNumBatchesToKeep = 10000 - DefaultMaxBatchPrunePerBlock = 100 + DefaultNumBatchesToKeep = 10000 + DefaultMaxBatchPrunePerBlock = 100 + DefaultMaxDataResultsToCheckForPrune = 100 ) // DefaultParams returns default batching module parameters. func DefaultParams() Params { return Params{ - NumBatchesToKeep: DefaultNumBatchesToKeep, - MaxBatchPrunePerBlock: DefaultMaxBatchPrunePerBlock, + NumBatchesToKeep: DefaultNumBatchesToKeep, + MaxBatchPrunePerBlock: DefaultMaxBatchPrunePerBlock, + MaxDataResultsToCheckForPrune: DefaultMaxDataResultsToCheckForPrune, } } diff --git a/x/batching/types/telemetry.go b/x/batching/types/telemetry.go new file mode 100644 index 00000000..ad5aa1b9 --- /dev/null +++ b/x/batching/types/telemetry.go @@ -0,0 +1,5 @@ +package types + +const ( + TelemetryKeyBatchingPruningFail = "seda_tally_end_block_batching_pruning_fail" +)