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
const (
FinalizedBlockNumber = BlockNumber(-4)
SafeBlockNumber = BlockNumber(-3)
PendingBlockNumber = BlockNumber(-2)
LatestBlockNumber = BlockNumber(-1)
EarliestBlockNumber = BlockNumber(0)
LatestExecutedBlockNumber = BlockNumber(-5)
FinalizedBlockNumber = BlockNumber(-4)
SafeBlockNumber = BlockNumber(-3)
PendingBlockNumber = BlockNumber(-2)
LatestBlockNumber = BlockNumber(-1)
EarliestBlockNumber = BlockNumber(0)
)
// UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports:
@ -106,6 +107,8 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
case "finalized":
*bn = FinalizedBlockNumber
return nil
case "latestExecuted":
*bn = LatestExecutedBlockNumber
case "null":
*bn = LatestBlockNumber
return nil

View File

@ -13,6 +13,7 @@ import (
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
"github.com/ledgerwatch/erigon/rpc"
"github.com/ledgerwatch/erigon/turbo/adapter"
"github.com/ledgerwatch/log/v3"
)
// 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:
pendingBlock := filters.LastPendingBlock()
if pendingBlock == nil {
log.Warn("no pending block found returning latest executed block")
blockNumber = plainStateBlockNumber
} else {
return pendingBlock.NumberU64(), pendingBlock.Hash(), false, nil
}
case rpc.LatestExecutedBlockNumber:
blockNumber = plainStateBlockNumber
default:
blockNumber = uint64(number.Int64())
}