Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86406c08ac | ||
|
|
ec2d7e0228 | ||
|
|
c46d7e8bd8 | ||
|
|
6cb4be4ebf | ||
|
|
3bd9a2395c | ||
|
|
5d19f2182b | ||
|
|
99a2dd5ed9 | ||
|
|
3adcfabb41 | ||
|
|
b1f0a3c79b |
17
CHANGELOG.md
17
CHANGELOG.md
@@ -1,4 +1,21 @@
|
||||
# Changelog
|
||||
## v1.4.14
|
||||
|
||||
### BUGFIX
|
||||
* [\#2643](https://github.com/bnb-chain/bsc/pull/2643)core: fix cache for receipts
|
||||
* [\#2656](https://github.com/bnb-chain/bsc/pull/2656)ethclient: fix BlobSidecars api
|
||||
* [\#2657](https://github.com/bnb-chain/bsc/pull/2657)fix: update prunefreezer’s offset when pruneancient and the dataset has pruned block
|
||||
|
||||
### FEATURE
|
||||
* [\#2661](https://github.com/bnb-chain/bsc/pull/2661)config: setup Mainnet 2 hardfork date: HaberFix & Bohr
|
||||
|
||||
### IMPROVEMENT
|
||||
* [\#2578](https://github.com/bnb-chain/bsc/pull/2578)core/systemcontracts: use vm.StateDB in UpgradeBuildInSystemContract
|
||||
* [\#2649](https://github.com/bnb-chain/bsc/pull/2649)internal/debug: remove memsize
|
||||
* [\#2655](https://github.com/bnb-chain/bsc/pull/2655)internal/ethapi: make GetFinalizedHeader monotonically increasing
|
||||
* [\#2658](https://github.com/bnb-chain/bsc/pull/2658)core: improve readability of the fork choice logic
|
||||
* [\#2665](https://github.com/bnb-chain/bsc/pull/2665)faucet: bump and resend faucet transaction if it has been pending for a while
|
||||
|
||||
## v1.4.13
|
||||
|
||||
### BUGFIX
|
||||
|
||||
@@ -371,8 +371,6 @@ func geth(ctx *cli.Context) error {
|
||||
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
|
||||
// miner.
|
||||
func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isConsole bool) {
|
||||
debug.Memsize.Add("node", stack)
|
||||
|
||||
// Start up the node itself
|
||||
utils.StartNode(ctx, stack, isConsole)
|
||||
|
||||
|
||||
@@ -1803,7 +1803,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
|
||||
}
|
||||
bc.hc.tdCache.Add(block.Hash(), externTd)
|
||||
bc.blockCache.Add(block.Hash(), block)
|
||||
bc.receiptsCache.Add(block.Hash(), receipts)
|
||||
bc.cacheReceipts(block.Hash(), receipts, block)
|
||||
if bc.chainConfig.IsCancun(block.Number(), block.Time()) {
|
||||
bc.sidecarsCache.Add(block.Hash(), block.Sidecars())
|
||||
}
|
||||
@@ -2320,8 +2320,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
|
||||
return it.index, err
|
||||
}
|
||||
|
||||
bc.cacheReceipts(block.Hash(), receipts, block)
|
||||
|
||||
// Update the metrics touched during block commit
|
||||
accountCommitTimer.Update(statedb.AccountCommits) // Account commits are complete, we can mark them
|
||||
storageCommitTimer.Update(statedb.StorageCommits) // Storage commits are complete, we can mark them
|
||||
|
||||
@@ -121,12 +121,19 @@ func (f *ForkChoice) ReorgNeeded(current *types.Header, extern *types.Header) (b
|
||||
if f.preserve != nil {
|
||||
currentPreserve, externPreserve = f.preserve(current), f.preserve(extern)
|
||||
}
|
||||
doubleSign := (extern.Coinbase == current.Coinbase)
|
||||
reorg = !currentPreserve && (externPreserve ||
|
||||
extern.Time < current.Time ||
|
||||
extern.Time == current.Time &&
|
||||
((doubleSign && extern.Hash().Cmp(current.Hash()) < 0) ||
|
||||
(!doubleSign && f.rand.Float64() < 0.5)))
|
||||
choiceRules := func() bool {
|
||||
if extern.Time == current.Time {
|
||||
doubleSign := (extern.Coinbase == current.Coinbase)
|
||||
if doubleSign {
|
||||
return extern.Hash().Cmp(current.Hash()) < 0
|
||||
} else {
|
||||
return f.rand.Float64() < 0.5
|
||||
}
|
||||
} else {
|
||||
return extern.Time < current.Time
|
||||
}
|
||||
}
|
||||
reorg = !currentPreserve && (externPreserve || choiceRules())
|
||||
}
|
||||
return reorg, nil
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ func newPrunedFreezer(datadir string, db ethdb.KeyValueStore, offset uint64) (*p
|
||||
|
||||
// repair init frozen , compatible disk-ancientdb and pruner-block-tool.
|
||||
func (f *prunedfreezer) repair(datadir string) error {
|
||||
offset := atomic.LoadUint64(&f.frozen)
|
||||
// compatible freezer
|
||||
minItems := uint64(math.MaxUint64)
|
||||
for name, disableSnappy := range chainFreezerNoSnappy {
|
||||
@@ -96,19 +97,14 @@ func (f *prunedfreezer) repair(datadir string) error {
|
||||
table.Close()
|
||||
}
|
||||
|
||||
// If minItems is non-zero, it indicates that the chain freezer was previously enabled, and we should use minItems as the current frozen value.
|
||||
// If minItems is zero, it indicates that the pruneAncient was previously enabled, and we should continue using frozen
|
||||
// (retrieved from CurrentAncientFreezer) as the current frozen value.
|
||||
offset := minItems
|
||||
if offset == 0 {
|
||||
// no item in ancientDB, init `offset` to the `f.frozen`
|
||||
offset = atomic.LoadUint64(&f.frozen)
|
||||
}
|
||||
log.Info("Read ancientdb item counts", "items", minItems, "offset", offset)
|
||||
// If the dataset has undergone a prune block, the offset is a non-zero value, otherwise the offset is a zero value.
|
||||
// The minItems is the value relative to offset
|
||||
offset += minItems
|
||||
|
||||
// FrozenOfAncientFreezer is the progress of the last prune-freezer freeze.
|
||||
frozenInDB := ReadFrozenOfAncientFreezer(f.db)
|
||||
maxOffset := max(offset, frozenInDB)
|
||||
log.Info("Read ancient db item counts", "items", minItems, "frozen", maxOffset)
|
||||
|
||||
atomic.StoreUint64(&f.frozen, maxOffset)
|
||||
if err := f.Sync(); err != nil {
|
||||
@@ -161,12 +157,12 @@ func (f *prunedfreezer) AncientOffSet() uint64 {
|
||||
|
||||
// MigrateTable processes the entries in a given table in sequence
|
||||
// converting them to a new format if they're of an old format.
|
||||
func (db *prunedfreezer) MigrateTable(kind string, convert convertLegacyFn) error {
|
||||
func (f *prunedfreezer) MigrateTable(kind string, convert convertLegacyFn) error {
|
||||
return errNotSupported
|
||||
}
|
||||
|
||||
// AncientDatadir returns an error as we don't have a backing chain freezer.
|
||||
func (db *prunedfreezer) AncientDatadir() (string, error) {
|
||||
func (f *prunedfreezer) AncientDatadir() (string, error) {
|
||||
return "", errNotSupported
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts/bohr"
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts/bruno"
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts/euler"
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts/planck"
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts/plato"
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts/ramanujan"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
)
|
||||
@@ -40,7 +41,7 @@ type Upgrade struct {
|
||||
Configs []*UpgradeConfig
|
||||
}
|
||||
|
||||
type upgradeHook func(blockNumber *big.Int, contractAddr common.Address, statedb *state.StateDB) error
|
||||
type upgradeHook func(blockNumber *big.Int, contractAddr common.Address, statedb vm.StateDB) error
|
||||
|
||||
const (
|
||||
mainNet = "Mainnet"
|
||||
@@ -789,10 +790,11 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func UpgradeBuildInSystemContract(config *params.ChainConfig, blockNumber *big.Int, lastBlockTime uint64, blockTime uint64, statedb *state.StateDB) {
|
||||
if config == nil || blockNumber == nil || statedb == nil {
|
||||
func UpgradeBuildInSystemContract(config *params.ChainConfig, blockNumber *big.Int, lastBlockTime uint64, blockTime uint64, statedb vm.StateDB) {
|
||||
if config == nil || blockNumber == nil || statedb == nil || reflect.ValueOf(statedb).IsNil() {
|
||||
return
|
||||
}
|
||||
|
||||
var network string
|
||||
switch GenesisHash {
|
||||
/* Add mainnet genesis hash */
|
||||
@@ -876,7 +878,7 @@ func UpgradeBuildInSystemContract(config *params.ChainConfig, blockNumber *big.I
|
||||
*/
|
||||
}
|
||||
|
||||
func applySystemContractUpgrade(upgrade *Upgrade, blockNumber *big.Int, statedb *state.StateDB, logger log.Logger) {
|
||||
func applySystemContractUpgrade(upgrade *Upgrade, blockNumber *big.Int, statedb vm.StateDB, logger log.Logger) {
|
||||
if upgrade == nil {
|
||||
logger.Info("Empty upgrade config", "height", blockNumber.String())
|
||||
return
|
||||
|
||||
@@ -2,9 +2,13 @@ package systemcontracts
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -39,3 +43,31 @@ func TestAllCodesHash(t *testing.T) {
|
||||
allCodeHash := sha256.Sum256(allCodes)
|
||||
require.Equal(t, allCodeHash[:], common.Hex2Bytes("833cc0fc87c46ad8a223e44ccfdc16a51a7e7383525136441bd0c730f06023df"))
|
||||
}
|
||||
|
||||
func TestUpgradeBuildInSystemContractNilInterface(t *testing.T) {
|
||||
var (
|
||||
config = params.BSCChainConfig
|
||||
blockNumber = big.NewInt(37959559)
|
||||
lastBlockTime uint64 = 1713419337
|
||||
blockTime uint64 = 1713419340
|
||||
statedb vm.StateDB
|
||||
)
|
||||
|
||||
GenesisHash = params.BSCGenesisHash
|
||||
|
||||
UpgradeBuildInSystemContract(config, blockNumber, lastBlockTime, blockTime, statedb)
|
||||
}
|
||||
|
||||
func TestUpgradeBuildInSystemContractNilValue(t *testing.T) {
|
||||
var (
|
||||
config = params.BSCChainConfig
|
||||
blockNumber = big.NewInt(37959559)
|
||||
lastBlockTime uint64 = 1713419337
|
||||
blockTime uint64 = 1713419340
|
||||
statedb vm.StateDB = (*state.StateDB)(nil)
|
||||
)
|
||||
|
||||
GenesisHash = params.BSCGenesisHash
|
||||
|
||||
UpgradeBuildInSystemContract(config, blockNumber, lastBlockTime, blockTime, statedb)
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
)
|
||||
|
||||
@@ -53,3 +55,40 @@ func (s *BlobSidecar) SanityCheck(blockNumber *big.Int, blockHash common.Hash) e
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *BlobSidecar) MarshalJSON() ([]byte, error) {
|
||||
fields := map[string]interface{}{
|
||||
"blockHash": s.BlockHash,
|
||||
"blockNumber": hexutil.EncodeUint64(s.BlockNumber.Uint64()),
|
||||
"txHash": s.TxHash,
|
||||
"txIndex": hexutil.EncodeUint64(s.TxIndex),
|
||||
}
|
||||
fields["blobSidecar"] = s.BlobTxSidecar
|
||||
return json.Marshal(fields)
|
||||
}
|
||||
|
||||
func (s *BlobSidecar) UnmarshalJSON(input []byte) error {
|
||||
type blobSidecar struct {
|
||||
BlobSidecar BlobTxSidecar `json:"blobSidecar"`
|
||||
BlockNumber *hexutil.Big `json:"blockNumber"`
|
||||
BlockHash common.Hash `json:"blockHash"`
|
||||
TxIndex *hexutil.Big `json:"txIndex"`
|
||||
TxHash common.Hash `json:"txHash"`
|
||||
}
|
||||
var blob blobSidecar
|
||||
if err := json.Unmarshal(input, &blob); err != nil {
|
||||
return err
|
||||
}
|
||||
s.BlobTxSidecar = blob.BlobSidecar
|
||||
if blob.BlockNumber == nil {
|
||||
return errors.New("missing required field 'blockNumber' for BlobSidecar")
|
||||
}
|
||||
s.BlockNumber = blob.BlockNumber.ToInt()
|
||||
s.BlockHash = blob.BlockHash
|
||||
if blob.TxIndex == nil {
|
||||
return errors.New("missing required field 'txIndex' for BlobSidecar")
|
||||
}
|
||||
s.TxIndex = blob.TxIndex.ToInt().Uint64()
|
||||
s.TxHash = blob.TxHash
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -441,14 +441,14 @@ func (b *EthAPIBackend) Engine() consensus.Engine {
|
||||
return b.eth.engine
|
||||
}
|
||||
|
||||
func (b *EthAPIBackend) CurrentTurnLength() (turnLength uint8, err error) {
|
||||
func (b *EthAPIBackend) CurrentValidators() ([]common.Address, error) {
|
||||
if p, ok := b.eth.engine.(*parlia.Parlia); ok {
|
||||
service := p.APIs(b.Chain())[0].Service
|
||||
currentHead := rpc.LatestBlockNumber
|
||||
return service.(*parlia.API).GetTurnLength(¤tHead)
|
||||
return service.(*parlia.API).GetValidators(¤tHead)
|
||||
}
|
||||
|
||||
return 1, nil
|
||||
return []common.Address{}, errors.New("not supported")
|
||||
}
|
||||
|
||||
func (b *EthAPIBackend) CurrentHeader() *types.Header {
|
||||
|
||||
@@ -131,8 +131,8 @@ func (ec *Client) BlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumb
|
||||
}
|
||||
|
||||
// BlobSidecars return the Sidecars of a given block number or hash.
|
||||
func (ec *Client) BlobSidecars(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.BlobTxSidecar, error) {
|
||||
var r []*types.BlobTxSidecar
|
||||
func (ec *Client) BlobSidecars(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.BlobSidecar, error) {
|
||||
var r []*types.BlobSidecar
|
||||
err := ec.c.CallContext(ctx, &r, "eth_getBlobSidecars", blockNrOrHash.String())
|
||||
if err == nil && r == nil {
|
||||
return nil, ethereum.NotFound
|
||||
@@ -141,8 +141,8 @@ func (ec *Client) BlobSidecars(ctx context.Context, blockNrOrHash rpc.BlockNumbe
|
||||
}
|
||||
|
||||
// BlobSidecarByTxHash return a sidecar of a given blob transaction
|
||||
func (ec *Client) BlobSidecarByTxHash(ctx context.Context, hash common.Hash) (*types.BlobTxSidecar, error) {
|
||||
var r *types.BlobTxSidecar
|
||||
func (ec *Client) BlobSidecarByTxHash(ctx context.Context, hash common.Hash) (*types.BlobSidecar, error) {
|
||||
var r *types.BlobSidecar
|
||||
err := ec.c.CallContext(ctx, &r, "eth_getBlobSidecarByTxHash", hash)
|
||||
if err == nil && r == nil {
|
||||
return nil, ethereum.NotFound
|
||||
|
||||
1
go.mod
1
go.mod
@@ -27,7 +27,6 @@ require (
|
||||
github.com/fatih/color v1.16.0
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e
|
||||
github.com/fjl/memsize v0.0.2
|
||||
github.com/fsnotify/fsnotify v1.6.0
|
||||
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08
|
||||
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46
|
||||
|
||||
2
go.sum
2
go.sum
@@ -335,8 +335,6 @@ github.com/ferranbt/fastssz v0.0.0-20210905181407-59cf6761a7d5 h1:6dVcS0LktRSyEE
|
||||
github.com/ferranbt/fastssz v0.0.0-20210905181407-59cf6761a7d5/go.mod h1:S8yiDeAXy8f88W4Ul+0dBMPx49S05byYbmZD6Uv94K4=
|
||||
github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e h1:bBLctRc7kr01YGvaDfgLbTwjFNW5jdp5y5rj8XXBHfY=
|
||||
github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e/go.mod h1:AzA8Lj6YtixmJWL+wkKoBGsLWy9gFrAzi4g+5bCKwpY=
|
||||
github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA=
|
||||
github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
||||
github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg=
|
||||
github.com/flynn/noise v1.1.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag=
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
"github.com/ethereum/go-ethereum/metrics/exp"
|
||||
"github.com/fjl/memsize/memsizeui"
|
||||
"github.com/mattn/go-colorable"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/urfave/cli/v2"
|
||||
@@ -38,8 +37,6 @@ import (
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
)
|
||||
|
||||
var Memsize memsizeui.Handler
|
||||
|
||||
var (
|
||||
verbosityFlag = &cli.IntFlag{
|
||||
Name: "verbosity",
|
||||
@@ -313,7 +310,6 @@ func StartPProf(address string, withMetrics bool) {
|
||||
if withMetrics {
|
||||
exp.Exp(metrics.DefaultRegistry)
|
||||
}
|
||||
http.Handle("/memsize/", http.StripPrefix("/memsize", &Memsize))
|
||||
log.Info("Starting pprof server", "addr", fmt.Sprintf("http://%s/debug/pprof", address))
|
||||
go func() {
|
||||
if err := http.ListenAndServe(address, nil); err != nil {
|
||||
|
||||
@@ -862,54 +862,72 @@ func (s *BlockChainAPI) Health() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// GetFinalizedHeader returns the requested finalized block header.
|
||||
// - probabilisticFinalized should be in range [2,21],
|
||||
// then the block header with number `max(fastFinalized, latest-probabilisticFinalized)` is returned
|
||||
func (s *BlockChainAPI) GetFinalizedHeader(ctx context.Context, probabilisticFinalized int64) (map[string]interface{}, error) {
|
||||
if probabilisticFinalized < 2 || probabilisticFinalized > 21 {
|
||||
return nil, fmt.Errorf("%d out of range [2,21]", probabilisticFinalized)
|
||||
func (s *BlockChainAPI) getFinalizedNumber(ctx context.Context, verifiedValidatorNum int64) (int64, error) {
|
||||
parliaConfig := s.b.ChainConfig().Parlia
|
||||
if parliaConfig == nil {
|
||||
return 0, fmt.Errorf("only parlia engine supported")
|
||||
}
|
||||
|
||||
currentTurnLength, err := s.b.CurrentTurnLength()
|
||||
curValidators, err := s.b.CurrentValidators()
|
||||
if err != nil { // impossible
|
||||
return nil, err
|
||||
return 0, err
|
||||
}
|
||||
valLen := int64(len(curValidators))
|
||||
if verifiedValidatorNum < 1 || verifiedValidatorNum > valLen {
|
||||
return 0, fmt.Errorf("%d out of range [1,%d]", verifiedValidatorNum, valLen)
|
||||
}
|
||||
|
||||
fastFinalizedHeader, err := s.b.HeaderByNumber(ctx, rpc.FinalizedBlockNumber)
|
||||
if err != nil { // impossible
|
||||
return nil, err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
latestHeader, err := s.b.HeaderByNumber(ctx, rpc.LatestBlockNumber)
|
||||
if err != nil { // impossible
|
||||
return 0, err
|
||||
}
|
||||
lastHeader := latestHeader
|
||||
confirmedValSet := make(map[common.Address]struct{}, valLen)
|
||||
confirmedValSet[lastHeader.Coinbase] = struct{}{}
|
||||
for count := 1; int64(len(confirmedValSet)) < verifiedValidatorNum && count <= int(parliaConfig.Epoch) && lastHeader.Number.Int64() > max(fastFinalizedHeader.Number.Int64(), 1); count++ {
|
||||
lastHeader, err = s.b.HeaderByHash(ctx, lastHeader.ParentHash)
|
||||
if err != nil { // impossible
|
||||
return 0, err
|
||||
}
|
||||
confirmedValSet[lastHeader.Coinbase] = struct{}{}
|
||||
}
|
||||
|
||||
finalizedBlockNumber := max(fastFinalizedHeader.Number.Int64(), lastHeader.Number.Int64())
|
||||
log.Debug("getFinalizedNumber", "LatestBlockNumber", latestHeader.Number.Int64(), "fastFinalizedHeight", fastFinalizedHeader.Number.Int64(),
|
||||
"lastHeader", lastHeader.Number.Int64(), "finalizedBlockNumber", finalizedBlockNumber, "len(confirmedValSet)", len(confirmedValSet))
|
||||
|
||||
return finalizedBlockNumber, nil
|
||||
}
|
||||
|
||||
// GetFinalizedHeader returns the finalized block header based on the specified parameters.
|
||||
// - `verifiedValidatorNum` must be within the range [1, len(currentValidators)].
|
||||
// - The function calculates `probabilisticFinalizedHeight` as the highest height of the block verified by `verifiedValidatorNum` validators,
|
||||
// it then returns the block header with a height equal to `max(fastFinalizedHeight, probabilisticFinalizedHeight)`.
|
||||
// - The height of the returned block header is guaranteed to be monotonically increasing.
|
||||
func (s *BlockChainAPI) GetFinalizedHeader(ctx context.Context, verifiedValidatorNum int64) (map[string]interface{}, error) {
|
||||
finalizedBlockNumber, err := s.getFinalizedNumber(ctx, verifiedValidatorNum)
|
||||
if err != nil { // impossible
|
||||
return nil, err
|
||||
}
|
||||
finalizedBlockNumber := max(fastFinalizedHeader.Number.Int64(), latestHeader.Number.Int64()-probabilisticFinalized*int64(currentTurnLength))
|
||||
|
||||
return s.GetHeaderByNumber(ctx, rpc.BlockNumber(finalizedBlockNumber))
|
||||
}
|
||||
|
||||
// GetFinalizedBlock returns the requested finalized block.
|
||||
// - probabilisticFinalized should be in range [2,21],
|
||||
// then the block with number `max(fastFinalized, latest-probabilisticFinalized)` is returned
|
||||
// - When fullTx is true all transactions in the block are returned, otherwise
|
||||
// only the transaction hash is returned.
|
||||
func (s *BlockChainAPI) GetFinalizedBlock(ctx context.Context, probabilisticFinalized int64, fullTx bool) (map[string]interface{}, error) {
|
||||
if probabilisticFinalized < 2 || probabilisticFinalized > 21 {
|
||||
return nil, fmt.Errorf("%d out of range [2,21]", probabilisticFinalized)
|
||||
}
|
||||
|
||||
currentTurnLength, err := s.b.CurrentTurnLength()
|
||||
// GetFinalizedBlock returns the finalized block based on the specified parameters.
|
||||
// - `verifiedValidatorNum` must be within the range [1, len(currentValidators)].
|
||||
// - The function calculates `probabilisticFinalizedHeight` as the highest height of the block verified by `verifiedValidatorNum` validators,
|
||||
// it then returns the block with a height equal to `max(fastFinalizedHeight, probabilisticFinalizedHeight)`.
|
||||
// - If `fullTx` is true, the block includes all transactions; otherwise, only transaction hashes are included.
|
||||
// - The height of the returned block is guaranteed to be monotonically increasing.
|
||||
func (s *BlockChainAPI) GetFinalizedBlock(ctx context.Context, verifiedValidatorNum int64, fullTx bool) (map[string]interface{}, error) {
|
||||
finalizedBlockNumber, err := s.getFinalizedNumber(ctx, verifiedValidatorNum)
|
||||
if err != nil { // impossible
|
||||
return nil, err
|
||||
}
|
||||
fastFinalizedHeader, err := s.b.HeaderByNumber(ctx, rpc.FinalizedBlockNumber)
|
||||
if err != nil { // impossible
|
||||
return nil, err
|
||||
}
|
||||
latestHeader, err := s.b.HeaderByNumber(ctx, rpc.LatestBlockNumber)
|
||||
if err != nil { // impossible
|
||||
return nil, err
|
||||
}
|
||||
finalizedBlockNumber := max(fastFinalizedHeader.Number.Int64(), latestHeader.Number.Int64()-probabilisticFinalized*int64(currentTurnLength))
|
||||
|
||||
return s.GetBlockByNumber(ctx, rpc.BlockNumber(finalizedBlockNumber), fullTx)
|
||||
}
|
||||
|
||||
@@ -631,9 +631,9 @@ func (b testBackend) TxPoolContentFrom(addr common.Address) ([]*types.Transactio
|
||||
func (b testBackend) SubscribeNewTxsEvent(events chan<- core.NewTxsEvent) event.Subscription {
|
||||
panic("implement me")
|
||||
}
|
||||
func (b testBackend) ChainConfig() *params.ChainConfig { return b.chain.Config() }
|
||||
func (b testBackend) Engine() consensus.Engine { return b.chain.Engine() }
|
||||
func (b testBackend) CurrentTurnLength() (uint8, error) { return 1, nil }
|
||||
func (b testBackend) ChainConfig() *params.ChainConfig { return b.chain.Config() }
|
||||
func (b testBackend) Engine() consensus.Engine { return b.chain.Engine() }
|
||||
func (b testBackend) CurrentValidators() ([]common.Address, error) { return []common.Address{}, nil }
|
||||
func (b testBackend) GetLogs(ctx context.Context, blockHash common.Hash, number uint64) ([][]*types.Log, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
@@ -89,8 +89,8 @@ type Backend interface {
|
||||
|
||||
ChainConfig() *params.ChainConfig
|
||||
Engine() consensus.Engine
|
||||
// CurrentTurnLength return the turnLength at the latest block
|
||||
CurrentTurnLength() (uint8, error)
|
||||
// CurrentValidators return the list of validator at the latest block
|
||||
CurrentValidators() ([]common.Address, error)
|
||||
|
||||
// This is copied from filters.Backend
|
||||
// eth/filters needs to be initialized from this backend type, so methods needed by
|
||||
|
||||
@@ -416,7 +416,7 @@ func (b *backendMock) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent)
|
||||
|
||||
func (b *backendMock) Engine() consensus.Engine { return nil }
|
||||
|
||||
func (b *backendMock) CurrentTurnLength() (uint8, error) { return 1, nil }
|
||||
func (b *backendMock) CurrentValidators() ([]common.Address, error) { return []common.Address{}, nil }
|
||||
|
||||
func (b *backendMock) MevRunning() bool { return false }
|
||||
func (b *backendMock) HasBuilder(builder common.Address) bool { return false }
|
||||
|
||||
@@ -153,8 +153,8 @@ var (
|
||||
FeynmanFixTime: newUint64(1713419340), // 2024-04-18 05:49:00 AM UTC
|
||||
CancunTime: newUint64(1718863500), // 2024-06-20 06:05:00 AM UTC
|
||||
HaberTime: newUint64(1718863500), // 2024-06-20 06:05:00 AM UTC
|
||||
HaberFixTime: nil, // TBD
|
||||
BohrTime: nil,
|
||||
HaberFixTime: newUint64(1727316120), // 2024-09-26 02:02:00 AM UTC
|
||||
BohrTime: newUint64(1727317200), // 2024-09-26 02:20:00 AM UTC
|
||||
|
||||
Parlia: &ParliaConfig{
|
||||
Period: 3,
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
const (
|
||||
VersionMajor = 1 // Major version component of the current release
|
||||
VersionMinor = 4 // Minor version component of the current release
|
||||
VersionPatch = 13 // Patch version component of the current release
|
||||
VersionPatch = 14 // Patch version component of the current release
|
||||
VersionMeta = "" // Version metadata to append to the version string
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user