Skip to content

Commit

Permalink
try to find the BatchData in db to avoid calculate it when it's possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR552 committed Sep 3, 2024
1 parent d3a323d commit 01cb502
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/rpcdaemon/commands/zkevm_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@ func (api *ZkEvmAPIImpl) GetBatchDataByNumbers(ctx context.Context, batchNumbers
continue
}

// try to find the BatchData in db to avoid calculate it when it is possible
batchData, err := hermezDb.GetL1BatchData(batchNumber.Uint64())
if err != nil {
return nil, err
} else if len(batchData) != 0 {
bd.BatchL2Data = batchData
bds = append(bds, bd)
continue
}

// looks weird but we're using the rpc.BlockNumber type to represent the batch number, LatestBlockNumber represents latest batch
if batchNumber == rpc.LatestBlockNumber {
batchNumber = rpc.BlockNumber(highestBatchNo)
Expand Down
5 changes: 5 additions & 0 deletions rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ const (
EarliestBlockNumber = BlockNumber(0)
)

// Returns the block number as type uint64
func (bn *BlockNumber) Uint64() uint64 {
return uint64(bn.Int64())
}

// UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports:
// - "latest", "earliest", "pending", "safe", or "finalized" as string arguments
// - the block number
Expand Down

0 comments on commit 01cb502

Please sign in to comment.