mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth/catalyst: different idea for checking if fork is latest active
This commit is contained in:
parent
eb2da1ae66
commit
78eafeb518
1 changed files with 22 additions and 17 deletions
|
|
@ -20,7 +20,6 @@ package catalyst
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
|
@ -34,6 +33,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/miner"
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
||||
|
|
@ -192,8 +192,7 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV2(update engine.ForkchoiceStateV1, pa
|
|||
if params.BeaconRoot != nil {
|
||||
return engine.STATUS_INVALID, engine.InvalidParams.With(errors.New("unexpected beacon root"))
|
||||
}
|
||||
c := api.eth.BlockChain().Config()
|
||||
if !active(c.IsShanghai, c.IsCancun, c.LondonBlock, params.Timestamp) {
|
||||
if !latestActive(api.eth.BlockChain().Config(), "shanghai", params.Timestamp) {
|
||||
return engine.STATUS_INVALID, engine.UnsupportedFork.With(errors.New("forkchoiceUpdatedV2 must only be called for shanghai payloads"))
|
||||
}
|
||||
}
|
||||
|
|
@ -209,8 +208,7 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV3(update engine.ForkchoiceStateV1, pa
|
|||
if params.BeaconRoot == nil {
|
||||
return engine.STATUS_INVALID, engine.InvalidParams.With(errors.New("missing beacon root"))
|
||||
}
|
||||
c := api.eth.BlockChain().Config()
|
||||
if !active(c.IsCancun, c.IsPrague, c.LondonBlock, params.Timestamp) {
|
||||
if !latestActive(api.eth.BlockChain().Config(), "cancun", params.Timestamp) {
|
||||
return engine.STATUS_INVALID, engine.UnsupportedFork.With(errors.New("forkchoiceUpdatedV3 must only be called for shanghai payloads"))
|
||||
}
|
||||
}
|
||||
|
|
@ -447,8 +445,7 @@ func (api *ConsensusAPI) NewPayloadV1(params engine.ExecutableData) (engine.Payl
|
|||
|
||||
// NewPayloadV2 creates an Eth1 block, inserts it in the chain, and returns the status of the chain.
|
||||
func (api *ConsensusAPI) NewPayloadV2(params engine.ExecutableData) (engine.PayloadStatusV1, error) {
|
||||
c := api.eth.BlockChain().Config()
|
||||
if active(c.IsShanghai, c.IsCancun, c.LondonBlock, params.Timestamp) {
|
||||
if latestActive(api.eth.BlockChain().Config(), "shanghai", params.Timestamp) {
|
||||
if params.Withdrawals == nil {
|
||||
return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("nil withdrawals post-shanghai"))
|
||||
}
|
||||
|
|
@ -485,21 +482,29 @@ func (api *ConsensusAPI) NewPayloadV3(params engine.ExecutableData, versionedHas
|
|||
return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("nil parentBeaconBlockRoot post-cancun"))
|
||||
}
|
||||
|
||||
c := api.eth.BlockChain().Config()
|
||||
if !active(c.IsCancun, c.IsPrague, c.LondonBlock, params.Timestamp) {
|
||||
if !latestActive(api.eth.BlockChain().Config(), "cancun", params.Timestamp) {
|
||||
return engine.PayloadStatusV1{Status: engine.INVALID}, engine.UnsupportedFork.With(errors.New("newPayloadV3 must only be called for cancun payloads"))
|
||||
}
|
||||
|
||||
return api.newPayload(params, versionedHashes, beaconRoot)
|
||||
}
|
||||
|
||||
// active returns true only if current returns true and next returns false. It returns false otherwise.
|
||||
func active(current, next func(*big.Int, uint64) bool, london *big.Int, time uint64) bool {
|
||||
if !current(london, time) {
|
||||
return false
|
||||
}
|
||||
if next(london, time) {
|
||||
return false
|
||||
// latestActive returns true only if fork is the latest latestActive fork. It returns false otherwise.
|
||||
func latestActive(config *params.ChainConfig, fork string, time uint64) bool {
|
||||
switch fork {
|
||||
case "shanghai":
|
||||
if !config.IsShanghai(config.LondonBlock, time) {
|
||||
return false
|
||||
}
|
||||
if config.IsCancun(config.LondonBlock, time) {
|
||||
return false
|
||||
}
|
||||
case "cancun":
|
||||
if !config.IsCancun(config.LondonBlock, time) {
|
||||
return false
|
||||
}
|
||||
if config.IsPrague(config.LondonBlock, time) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue