Skip to content

Commit

Permalink
fix: parse rpcBatchNumber correctly by string (#1395)
Browse files Browse the repository at this point in the history
  • Loading branch information
V-Staykov authored Oct 31, 2024
1 parent 434376b commit fda8166
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions turbo/jsonrpc/zkevm_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,11 @@ func (api *ZkEvmAPIImpl) GetBatchDataByNumbers(ctx context.Context, batchNumbers
bds := make([]*types.BatchDataSlim, 0, len(batchNumbers.Numbers))

for _, batchRpcNumber := range batchNumbers.Numbers {
// looks weird but we're using the rpc.BlockNumber type to represent the batch number, LatestBlockNumber represents latest batch
if batchRpcNumber == rpc.LatestBlockNumber {
batchRpcNumber = rpc.BlockNumber(highestBatchNo)
batchNo, _, err := rpchelper.GetBatchNumber(batchRpcNumber, tx, nil)
if err != nil {
return nil, err
}

batchNo := batchRpcNumber.Uint64()

bd := &types.BatchDataSlim{
Number: types.ArgUint64(batchNo),
Empty: false,
Expand Down Expand Up @@ -419,7 +417,7 @@ func (api *ZkEvmAPIImpl) getBatchBlocksWithSenders(ctx context.Context, tx kv.Tx

// GetBatchByNumber returns a batch from the current canonical chain. If number is nil, the
// latest known batch is returned.
func (api *ZkEvmAPIImpl) GetBatchByNumber(ctx context.Context, batchNumber rpc.BlockNumber, fullTx *bool) (json.RawMessage, error) {
func (api *ZkEvmAPIImpl) GetBatchByNumber(ctx context.Context, rpcBatchNumber rpc.BlockNumber, fullTx *bool) (json.RawMessage, error) {
tx, err := api.db.BeginRo(ctx)
if err != nil {
return nil, err
Expand All @@ -435,6 +433,11 @@ func (api *ZkEvmAPIImpl) GetBatchByNumber(ctx context.Context, batchNumber rpc.B
return nil, err
}

batchNo, _, err := rpchelper.GetBatchNumber(rpcBatchNumber, tx, nil)
if err != nil {
return nil, err
}

// check sync status of node
syncStatus, err := api.ethApi.Syncing(ctx)
if err != nil {
Expand All @@ -447,17 +450,10 @@ func (api *ZkEvmAPIImpl) GetBatchByNumber(ctx context.Context, batchNumber rpc.B
}

}
if batchNumber.Uint64() > highestBatchNo {
if batchNo > highestBatchNo {
return nil, nil
}

// 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)
}

batchNo := batchNumber.Uint64()

batch := &types.Batch{
Number: types.ArgUint64(batchNo),
}
Expand Down Expand Up @@ -1797,14 +1793,19 @@ func (api *ZkEvmAPIImpl) GetForkById(ctx context.Context, forkId hexutil.Uint64)
}

// GetForkIdByBatchNumber returns the fork ID given the provided batch number
func (api *ZkEvmAPIImpl) GetForkIdByBatchNumber(ctx context.Context, batchNumber rpc.BlockNumber) (hexutil.Uint64, error) {
func (api *ZkEvmAPIImpl) GetForkIdByBatchNumber(ctx context.Context, rpcBatchNumber rpc.BlockNumber) (hexutil.Uint64, error) {
tx, err := api.db.BeginRo(ctx)
if err != nil {
return hexutil.Uint64(0), err
}
defer tx.Rollback()

currentForkId, err := getForkIdByBatchNo(tx, uint64(batchNumber))
batchNumber, _, err := rpchelper.GetBatchNumber(rpcBatchNumber, tx, nil)
if err != nil {
return 0, err
}

currentForkId, err := getForkIdByBatchNo(tx, batchNumber)
if err != nil {
return 0, err
}
Expand Down

0 comments on commit fda8166

Please sign in to comment.