mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-08 03:51:20 +00:00
3c8cbda809
Co-authored-by: Ubuntu <ubuntu@ip-10-0-0-234.eu-west-1.compute.internal>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package borfinality
|
|
|
|
import (
|
|
"github.com/ledgerwatch/erigon-lib/common"
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
"github.com/ledgerwatch/erigon/core/rawdb"
|
|
"github.com/ledgerwatch/erigon/core/types"
|
|
"github.com/ledgerwatch/erigon/eth/borfinality/whitelist"
|
|
)
|
|
|
|
func GetFinalizedBlockNumber(tx kv.Tx) uint64 {
|
|
currentBlockNum := rawdb.ReadCurrentHeader(tx)
|
|
|
|
service := whitelist.GetWhitelistingService()
|
|
|
|
doExist, number, hash := service.GetWhitelistedMilestone()
|
|
if doExist && number <= currentBlockNum.Number.Uint64() {
|
|
|
|
blockHeader := rawdb.ReadHeaderByNumber(tx, number)
|
|
|
|
if blockHeader == nil {
|
|
return 0
|
|
}
|
|
|
|
if blockHeader.Hash() == hash {
|
|
return number
|
|
}
|
|
}
|
|
|
|
doExist, number, hash = service.GetWhitelistedCheckpoint()
|
|
if doExist && number <= currentBlockNum.Number.Uint64() {
|
|
blockHeader := rawdb.ReadHeaderByNumber(tx, number)
|
|
|
|
if blockHeader == nil {
|
|
return 0
|
|
}
|
|
|
|
if blockHeader.Hash() == hash {
|
|
return number
|
|
}
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
// CurrentFinalizedBlock retrieves the current finalized block of the canonical
|
|
// chain. The block is retrieved from the blockchain's internal cache.
|
|
func CurrentFinalizedBlock(tx kv.Tx, number uint64) *types.Block {
|
|
hash, err := rawdb.ReadCanonicalHash(tx, number)
|
|
if err != nil || hash == (common.Hash{}) {
|
|
return nil
|
|
}
|
|
|
|
return rawdb.ReadBlock(tx, hash, number)
|
|
}
|