new rpc block number (#4953)

* new rpc block number

* log

* ops
This commit is contained in:
Enrique Jose Avila Asapche 2022-08-08 15:07:24 +03:00 committed by GitHub
parent 7a64fe44eb
commit c12d298f1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -71,11 +71,12 @@ type BlockNumber int64
type Timestamp uint64 type Timestamp uint64
const ( const (
FinalizedBlockNumber = BlockNumber(-4) LatestExecutedBlockNumber = BlockNumber(-5)
SafeBlockNumber = BlockNumber(-3) FinalizedBlockNumber = BlockNumber(-4)
PendingBlockNumber = BlockNumber(-2) SafeBlockNumber = BlockNumber(-3)
LatestBlockNumber = BlockNumber(-1) PendingBlockNumber = BlockNumber(-2)
EarliestBlockNumber = BlockNumber(0) LatestBlockNumber = BlockNumber(-1)
EarliestBlockNumber = BlockNumber(0)
) )
// UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports: // UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports:
@ -106,6 +107,8 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
case "finalized": case "finalized":
*bn = FinalizedBlockNumber *bn = FinalizedBlockNumber
return nil return nil
case "latestExecuted":
*bn = LatestExecutedBlockNumber
case "null": case "null":
*bn = LatestBlockNumber *bn = LatestBlockNumber
return nil return nil

View File

@ -13,6 +13,7 @@ import (
"github.com/ledgerwatch/erigon/eth/stagedsync/stages" "github.com/ledgerwatch/erigon/eth/stagedsync/stages"
"github.com/ledgerwatch/erigon/rpc" "github.com/ledgerwatch/erigon/rpc"
"github.com/ledgerwatch/erigon/turbo/adapter" "github.com/ledgerwatch/erigon/turbo/adapter"
"github.com/ledgerwatch/log/v3"
) )
// unable to decode supplied params, or an invalid number of parameters // unable to decode supplied params, or an invalid number of parameters
@ -63,10 +64,13 @@ func _GetBlockNumber(requireCanonical bool, blockNrOrHash rpc.BlockNumberOrHash,
case rpc.PendingBlockNumber: case rpc.PendingBlockNumber:
pendingBlock := filters.LastPendingBlock() pendingBlock := filters.LastPendingBlock()
if pendingBlock == nil { if pendingBlock == nil {
log.Warn("no pending block found returning latest executed block")
blockNumber = plainStateBlockNumber blockNumber = plainStateBlockNumber
} else { } else {
return pendingBlock.NumberU64(), pendingBlock.Hash(), false, nil return pendingBlock.NumberU64(), pendingBlock.Hash(), false, nil
} }
case rpc.LatestExecutedBlockNumber:
blockNumber = plainStateBlockNumber
default: default:
blockNumber = uint64(number.Int64()) blockNumber = uint64(number.Int64())
} }