Skip to content

Commit

Permalink
chore: increase the data commitment blocks limit in the API (#1268)
Browse files Browse the repository at this point in the history
## Description

This is done to support 4 hours batches of attestations in the API
without having to make a breaking change

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
  • Loading branch information
rach-id committed Mar 27, 2024
1 parent 66eed28 commit 1d70a8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ var (
NewBaseHashFunc = sha256.New

// DataCommitmentBlocksLimit is the limit to the number of blocks we can generate a data commitment for.
// NOTE: this is no longer used as we're moving towards Blobstream X. However, we're leaving it
// here for backwards compatibility purpose until it's removed in the next breaking release.
DataCommitmentBlocksLimit = 1000
)
9 changes: 6 additions & 3 deletions rpc/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/cometbft/cometbft/libs/bytes"
cmtmath "github.com/cometbft/cometbft/libs/math"
cmtquery "github.com/cometbft/cometbft/libs/pubsub/query"
"github.com/cometbft/cometbft/pkg/consts"
ctypes "github.com/cometbft/cometbft/rpc/core/types"
rpctypes "github.com/cometbft/cometbft/rpc/jsonrpc/types"
blockidxnull "github.com/cometbft/cometbft/state/indexer/block/null"
Expand Down Expand Up @@ -333,6 +332,10 @@ func EncodeDataRootTuple(height uint64, dataRoot [32]byte) ([]byte, error) {
return append(paddedHeight, dataRoot[:]...), nil
}

// dataCommitmentBlocksLimit The maximum number of blocks to be used to create a data commitment.
// It's a local parameter to protect the API from creating unnecessarily large commitments.
const dataCommitmentBlocksLimit = 10_000 // ~33 hours of blocks assuming 12-second blocks.

// validateDataCommitmentRange runs basic checks on the asc sorted list of
// heights that will be used subsequently in generating data commitments over
// the defined set of heights.
Expand All @@ -342,8 +345,8 @@ func validateDataCommitmentRange(start uint64, end uint64) error {
}
env := GetEnvironment()
heightsRange := end - start
if heightsRange > uint64(consts.DataCommitmentBlocksLimit) {
return fmt.Errorf("the query exceeds the limit of allowed blocks %d", consts.DataCommitmentBlocksLimit)
if heightsRange > uint64(dataCommitmentBlocksLimit) {
return fmt.Errorf("the query exceeds the limit of allowed blocks %d", dataCommitmentBlocksLimit)
}
if heightsRange == 0 {
return fmt.Errorf("cannot create the data commitments for an empty set of blocks")
Expand Down

0 comments on commit 1d70a8e

Please sign in to comment.