beacon/engine: move core/beacon to beacon/engine (#26616)

This PR moves core/beacon to beacon/engine so that beacon-chain related code has its own top level package which also can house the the beacon lightclient-code.
This commit is contained in:
Felföldi Zsolt 2023-02-06 16:37:58 +01:00 committed by GitHub
parent 8860b39754
commit 3a5aceed8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 183 additions and 183 deletions

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package beacon
package engine
import (
"github.com/ethereum/go-ethereum/common"

View File

@ -1,6 +1,6 @@
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package beacon
package engine
import (
"encoding/json"

View File

@ -1,6 +1,6 @@
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package beacon
package engine
import (
"encoding/json"

View File

@ -1,6 +1,6 @@
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package beacon
package engine
import (
"encoding/json"

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package beacon
package engine
import (
"fmt"

View File

@ -24,9 +24,9 @@ import (
"sync"
"time"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/beacon"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
@ -168,24 +168,24 @@ func NewConsensusAPI(eth *eth.Ethereum) *ConsensusAPI {
//
// If there are payloadAttributes: we try to assemble a block with the payloadAttributes
// and return its payloadID.
func (api *ConsensusAPI) ForkchoiceUpdatedV1(update beacon.ForkchoiceStateV1, payloadAttributes *beacon.PayloadAttributes) (beacon.ForkChoiceResponse, error) {
func (api *ConsensusAPI) ForkchoiceUpdatedV1(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) {
if payloadAttributes != nil && payloadAttributes.Withdrawals != nil {
return beacon.STATUS_INVALID, beacon.InvalidParams.With(fmt.Errorf("withdrawals not supported in V1"))
return engine.STATUS_INVALID, engine.InvalidParams.With(fmt.Errorf("withdrawals not supported in V1"))
}
return api.forkchoiceUpdated(update, payloadAttributes)
}
// ForkchoiceUpdatedV2 is equivalent to V1 with the addition of withdrawals in the payload attributes.
func (api *ConsensusAPI) ForkchoiceUpdatedV2(update beacon.ForkchoiceStateV1, payloadAttributes *beacon.PayloadAttributes) (beacon.ForkChoiceResponse, error) {
func (api *ConsensusAPI) ForkchoiceUpdatedV2(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) {
if payloadAttributes != nil {
if err := api.verifyPayloadAttributes(payloadAttributes); err != nil {
return beacon.STATUS_INVALID, beacon.InvalidParams.With(err)
return engine.STATUS_INVALID, engine.InvalidParams.With(err)
}
}
return api.forkchoiceUpdated(update, payloadAttributes)
}
func (api *ConsensusAPI) verifyPayloadAttributes(attr *beacon.PayloadAttributes) error {
func (api *ConsensusAPI) verifyPayloadAttributes(attr *engine.PayloadAttributes) error {
if !api.eth.BlockChain().Config().IsShanghai(attr.Timestamp) {
// Reject payload attributes with withdrawals before shanghai
if attr.Withdrawals != nil {
@ -200,14 +200,14 @@ func (api *ConsensusAPI) verifyPayloadAttributes(attr *beacon.PayloadAttributes)
return nil
}
func (api *ConsensusAPI) forkchoiceUpdated(update beacon.ForkchoiceStateV1, payloadAttributes *beacon.PayloadAttributes) (beacon.ForkChoiceResponse, error) {
func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) {
api.forkchoiceLock.Lock()
defer api.forkchoiceLock.Unlock()
log.Trace("Engine API request received", "method", "ForkchoiceUpdated", "head", update.HeadBlockHash, "finalized", update.FinalizedBlockHash, "safe", update.SafeBlockHash)
if update.HeadBlockHash == (common.Hash{}) {
log.Warn("Forkchoice requested update to zero hash")
return beacon.STATUS_INVALID, nil // TODO(karalabe): Why does someone send us this?
return engine.STATUS_INVALID, nil // TODO(karalabe): Why does someone send us this?
}
// Stash away the last update to warn the user if the beacon client goes offline
api.lastForkchoiceLock.Lock()
@ -221,7 +221,7 @@ func (api *ConsensusAPI) forkchoiceUpdated(update beacon.ForkchoiceStateV1, payl
if block == nil {
// If this block was previously invalidated, keep rejecting it here too
if res := api.checkInvalidAncestor(update.HeadBlockHash, update.HeadBlockHash); res != nil {
return beacon.ForkChoiceResponse{PayloadStatus: *res, PayloadID: nil}, nil
return engine.ForkChoiceResponse{PayloadStatus: *res, PayloadID: nil}, nil
}
// If the head hash is unknown (was not given to us in a newPayload request),
// we cannot resolve the header, so not much to do. This could be extended in
@ -230,7 +230,7 @@ func (api *ConsensusAPI) forkchoiceUpdated(update beacon.ForkchoiceStateV1, payl
header := api.remoteBlocks.get(update.HeadBlockHash)
if header == nil {
log.Warn("Forkchoice requested unknown head", "hash", update.HeadBlockHash)
return beacon.STATUS_SYNCING, nil
return engine.STATUS_SYNCING, nil
}
// Header advertised via a past newPayload request. Start syncing to it.
// Before we do however, make sure any legacy sync in switched off so we
@ -241,9 +241,9 @@ func (api *ConsensusAPI) forkchoiceUpdated(update beacon.ForkchoiceStateV1, payl
}
log.Info("Forkchoice requested sync to new head", "number", header.Number, "hash", header.Hash())
if err := api.eth.Downloader().BeaconSync(api.eth.SyncMode(), header); err != nil {
return beacon.STATUS_SYNCING, err
return engine.STATUS_SYNCING, err
}
return beacon.STATUS_SYNCING, nil
return engine.STATUS_SYNCING, nil
}
// Block is known locally, just sanity check that the beacon client does not
// attempt to push us back to before the merge.
@ -255,27 +255,27 @@ func (api *ConsensusAPI) forkchoiceUpdated(update beacon.ForkchoiceStateV1, payl
)
if td == nil || (block.NumberU64() > 0 && ptd == nil) {
log.Error("TDs unavailable for TTD check", "number", block.NumberU64(), "hash", update.HeadBlockHash, "td", td, "parent", block.ParentHash(), "ptd", ptd)
return beacon.STATUS_INVALID, errors.New("TDs unavailable for TDD check")
return engine.STATUS_INVALID, errors.New("TDs unavailable for TDD check")
}
if td.Cmp(ttd) < 0 {
log.Error("Refusing beacon update to pre-merge", "number", block.NumberU64(), "hash", update.HeadBlockHash, "diff", block.Difficulty(), "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)))
return beacon.ForkChoiceResponse{PayloadStatus: beacon.INVALID_TERMINAL_BLOCK, PayloadID: nil}, nil
return engine.ForkChoiceResponse{PayloadStatus: engine.INVALID_TERMINAL_BLOCK, PayloadID: nil}, nil
}
if block.NumberU64() > 0 && ptd.Cmp(ttd) >= 0 {
log.Error("Parent block is already post-ttd", "number", block.NumberU64(), "hash", update.HeadBlockHash, "diff", block.Difficulty(), "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)))
return beacon.ForkChoiceResponse{PayloadStatus: beacon.INVALID_TERMINAL_BLOCK, PayloadID: nil}, nil
return engine.ForkChoiceResponse{PayloadStatus: engine.INVALID_TERMINAL_BLOCK, PayloadID: nil}, nil
}
}
valid := func(id *beacon.PayloadID) beacon.ForkChoiceResponse {
return beacon.ForkChoiceResponse{
PayloadStatus: beacon.PayloadStatusV1{Status: beacon.VALID, LatestValidHash: &update.HeadBlockHash},
valid := func(id *engine.PayloadID) engine.ForkChoiceResponse {
return engine.ForkChoiceResponse{
PayloadStatus: engine.PayloadStatusV1{Status: engine.VALID, LatestValidHash: &update.HeadBlockHash},
PayloadID: id,
}
}
if rawdb.ReadCanonicalHash(api.eth.ChainDb(), block.NumberU64()) != update.HeadBlockHash {
// Block is not canonical, set head.
if latestValid, err := api.eth.BlockChain().SetCanonical(block); err != nil {
return beacon.ForkChoiceResponse{PayloadStatus: beacon.PayloadStatusV1{Status: beacon.INVALID, LatestValidHash: &latestValid}}, err
return engine.ForkChoiceResponse{PayloadStatus: engine.PayloadStatusV1{Status: engine.INVALID, LatestValidHash: &latestValid}}, err
}
} else if api.eth.BlockChain().CurrentBlock().Hash() == update.HeadBlockHash {
// If the specified head matches with our local head, do nothing and keep
@ -299,10 +299,10 @@ func (api *ConsensusAPI) forkchoiceUpdated(update beacon.ForkchoiceStateV1, payl
finalBlock := api.eth.BlockChain().GetBlockByHash(update.FinalizedBlockHash)
if finalBlock == nil {
log.Warn("Final block not available in database", "hash", update.FinalizedBlockHash)
return beacon.STATUS_INVALID, beacon.InvalidForkChoiceState.With(errors.New("final block not available in database"))
return engine.STATUS_INVALID, engine.InvalidForkChoiceState.With(errors.New("final block not available in database"))
} else if rawdb.ReadCanonicalHash(api.eth.ChainDb(), finalBlock.NumberU64()) != update.FinalizedBlockHash {
log.Warn("Final block not in canonical chain", "number", block.NumberU64(), "hash", update.HeadBlockHash)
return beacon.STATUS_INVALID, beacon.InvalidForkChoiceState.With(errors.New("final block not in canonical chain"))
return engine.STATUS_INVALID, engine.InvalidForkChoiceState.With(errors.New("final block not in canonical chain"))
}
// Set the finalized block
api.eth.BlockChain().SetFinalized(finalBlock)
@ -312,11 +312,11 @@ func (api *ConsensusAPI) forkchoiceUpdated(update beacon.ForkchoiceStateV1, payl
safeBlock := api.eth.BlockChain().GetBlockByHash(update.SafeBlockHash)
if safeBlock == nil {
log.Warn("Safe block not available in database")
return beacon.STATUS_INVALID, beacon.InvalidForkChoiceState.With(errors.New("safe block not available in database"))
return engine.STATUS_INVALID, engine.InvalidForkChoiceState.With(errors.New("safe block not available in database"))
}
if rawdb.ReadCanonicalHash(api.eth.ChainDb(), safeBlock.NumberU64()) != update.SafeBlockHash {
log.Warn("Safe block not in canonical chain")
return beacon.STATUS_INVALID, beacon.InvalidForkChoiceState.With(errors.New("safe block not in canonical chain"))
return engine.STATUS_INVALID, engine.InvalidForkChoiceState.With(errors.New("safe block not in canonical chain"))
}
// Set the safe block
api.eth.BlockChain().SetSafe(safeBlock)
@ -341,7 +341,7 @@ func (api *ConsensusAPI) forkchoiceUpdated(update beacon.ForkchoiceStateV1, payl
payload, err := api.eth.Miner().BuildPayload(args)
if err != nil {
log.Error("Failed to build payload", "err", err)
return valid(nil), beacon.InvalidPayloadAttributes.With(err)
return valid(nil), engine.InvalidPayloadAttributes.With(err)
}
api.localBlocks.put(id, payload)
return valid(&id), nil
@ -351,7 +351,7 @@ func (api *ConsensusAPI) forkchoiceUpdated(update beacon.ForkchoiceStateV1, payl
// ExchangeTransitionConfigurationV1 checks the given configuration against
// the configuration of the node.
func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config beacon.TransitionConfigurationV1) (*beacon.TransitionConfigurationV1, error) {
func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config engine.TransitionConfigurationV1) (*engine.TransitionConfigurationV1, error) {
log.Trace("Engine API request received", "method", "ExchangeTransitionConfiguration", "ttd", config.TerminalTotalDifficulty)
if config.TerminalTotalDifficulty == nil {
return nil, errors.New("invalid terminal total difficulty")
@ -368,7 +368,7 @@ func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config beacon.Transit
}
if config.TerminalBlockHash != (common.Hash{}) {
if hash := api.eth.BlockChain().GetCanonicalHash(uint64(config.TerminalBlockNumber)); hash == config.TerminalBlockHash {
return &beacon.TransitionConfigurationV1{
return &engine.TransitionConfigurationV1{
TerminalTotalDifficulty: (*hexutil.Big)(ttd),
TerminalBlockHash: config.TerminalBlockHash,
TerminalBlockNumber: config.TerminalBlockNumber,
@ -376,11 +376,11 @@ func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config beacon.Transit
}
return nil, fmt.Errorf("invalid terminal block hash")
}
return &beacon.TransitionConfigurationV1{TerminalTotalDifficulty: (*hexutil.Big)(ttd)}, nil
return &engine.TransitionConfigurationV1{TerminalTotalDifficulty: (*hexutil.Big)(ttd)}, nil
}
// GetPayloadV1 returns a cached payload by id.
func (api *ConsensusAPI) GetPayloadV1(payloadID beacon.PayloadID) (*beacon.ExecutableData, error) {
func (api *ConsensusAPI) GetPayloadV1(payloadID engine.PayloadID) (*engine.ExecutableData, error) {
data, err := api.getPayload(payloadID)
if err != nil {
return nil, err
@ -389,33 +389,33 @@ func (api *ConsensusAPI) GetPayloadV1(payloadID beacon.PayloadID) (*beacon.Execu
}
// GetPayloadV2 returns a cached payload by id.
func (api *ConsensusAPI) GetPayloadV2(payloadID beacon.PayloadID) (*beacon.ExecutionPayloadEnvelope, error) {
func (api *ConsensusAPI) GetPayloadV2(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
return api.getPayload(payloadID)
}
func (api *ConsensusAPI) getPayload(payloadID beacon.PayloadID) (*beacon.ExecutionPayloadEnvelope, error) {
func (api *ConsensusAPI) getPayload(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
log.Trace("Engine API request received", "method", "GetPayload", "id", payloadID)
data := api.localBlocks.get(payloadID)
if data == nil {
return nil, beacon.UnknownPayload
return nil, engine.UnknownPayload
}
return data, nil
}
// NewPayloadV1 creates an Eth1 block, inserts it in the chain, and returns the status of the chain.
func (api *ConsensusAPI) NewPayloadV1(params beacon.ExecutableData) (beacon.PayloadStatusV1, error) {
func (api *ConsensusAPI) NewPayloadV1(params engine.ExecutableData) (engine.PayloadStatusV1, error) {
if params.Withdrawals != nil {
return beacon.PayloadStatusV1{Status: beacon.INVALID}, fmt.Errorf("withdrawals not supported in V1")
return engine.PayloadStatusV1{Status: engine.INVALID}, fmt.Errorf("withdrawals not supported in V1")
}
return api.newPayload(params)
}
// NewPayloadV2 creates an Eth1 block, inserts it in the chain, and returns the status of the chain.
func (api *ConsensusAPI) NewPayloadV2(params beacon.ExecutableData) (beacon.PayloadStatusV1, error) {
func (api *ConsensusAPI) NewPayloadV2(params engine.ExecutableData) (engine.PayloadStatusV1, error) {
return api.newPayload(params)
}
func (api *ConsensusAPI) newPayload(params beacon.ExecutableData) (beacon.PayloadStatusV1, error) {
func (api *ConsensusAPI) newPayload(params engine.ExecutableData) (engine.PayloadStatusV1, error) {
// The locking here is, strictly, not required. Without these locks, this can happen:
//
// 1. NewPayload( execdata-N ) is invoked from the CL. It goes all the way down to
@ -433,10 +433,10 @@ func (api *ConsensusAPI) newPayload(params beacon.ExecutableData) (beacon.Payloa
defer api.newPayloadLock.Unlock()
log.Trace("Engine API request received", "method", "NewPayload", "number", params.Number, "hash", params.BlockHash)
block, err := beacon.ExecutableDataToBlock(params)
block, err := engine.ExecutableDataToBlock(params)
if err != nil {
log.Debug("Invalid NewPayload params", "params", params, "error", err)
return beacon.PayloadStatusV1{Status: beacon.INVALIDBLOCKHASH}, nil
return engine.PayloadStatusV1{Status: engine.INVALIDBLOCKHASH}, nil
}
// Stash away the last update to warn the user if the beacon client goes offline
api.lastNewPayloadLock.Lock()
@ -448,7 +448,7 @@ func (api *ConsensusAPI) newPayload(params beacon.ExecutableData) (beacon.Payloa
if block := api.eth.BlockChain().GetBlockByHash(params.BlockHash); block != nil {
log.Warn("Ignoring already known beacon payload", "number", params.Number, "hash", params.BlockHash, "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)))
hash := block.Hash()
return beacon.PayloadStatusV1{Status: beacon.VALID, LatestValidHash: &hash}, nil
return engine.PayloadStatusV1{Status: engine.VALID, LatestValidHash: &hash}, nil
}
// If this block was rejected previously, keep rejecting it
if res := api.checkInvalidAncestor(block.Hash(), block.Hash()); res != nil {
@ -473,11 +473,11 @@ func (api *ConsensusAPI) newPayload(params beacon.ExecutableData) (beacon.Payloa
)
if ptd.Cmp(ttd) < 0 {
log.Warn("Ignoring pre-merge payload", "number", params.Number, "hash", params.BlockHash, "td", ptd, "ttd", ttd)
return beacon.INVALID_TERMINAL_BLOCK, nil
return engine.INVALID_TERMINAL_BLOCK, nil
}
if parent.Difficulty().BitLen() > 0 && gptd != nil && gptd.Cmp(ttd) >= 0 {
log.Error("Ignoring pre-merge parent block", "number", params.Number, "hash", params.BlockHash, "td", ptd, "ttd", ttd)
return beacon.INVALID_TERMINAL_BLOCK, nil
return engine.INVALID_TERMINAL_BLOCK, nil
}
if block.Time() <= parent.Time() {
log.Warn("Invalid timestamp", "parent", block.Time(), "block", block.Time())
@ -493,7 +493,7 @@ func (api *ConsensusAPI) newPayload(params beacon.ExecutableData) (beacon.Payloa
if !api.eth.BlockChain().HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
api.remoteBlocks.put(block.Hash(), block.Header())
log.Warn("State not available, ignoring new payload")
return beacon.PayloadStatusV1{Status: beacon.ACCEPTED}, nil
return engine.PayloadStatusV1{Status: engine.ACCEPTED}, nil
}
log.Trace("Inserting block without sethead", "hash", block.Hash(), "number", block.Number)
if err := api.eth.BlockChain().InsertBlockWithoutSetHead(block); err != nil {
@ -514,14 +514,14 @@ func (api *ConsensusAPI) newPayload(params beacon.ExecutableData) (beacon.Payloa
api.eth.Downloader().Cancel()
}
hash := block.Hash()
return beacon.PayloadStatusV1{Status: beacon.VALID, LatestValidHash: &hash}, nil
return engine.PayloadStatusV1{Status: engine.VALID, LatestValidHash: &hash}, nil
}
// delayPayloadImport stashes the given block away for import at a later time,
// either via a forkchoice update or a sync extension. This method is meant to
// be called by the newpayload command when the block seems to be ok, but some
// prerequisite prevents it from being processed (e.g. no parent, or snap sync).
func (api *ConsensusAPI) delayPayloadImport(block *types.Block) (beacon.PayloadStatusV1, error) {
func (api *ConsensusAPI) delayPayloadImport(block *types.Block) (engine.PayloadStatusV1, error) {
// Sanity check that this block's parent is not on a previously invalidated
// chain. If it is, mark the block as invalid too.
if res := api.checkInvalidAncestor(block.ParentHash(), block.Hash()); res != nil {
@ -536,7 +536,7 @@ func (api *ConsensusAPI) delayPayloadImport(block *types.Block) (beacon.PayloadS
// some strain from the forkchoice update.
if err := api.eth.Downloader().BeaconExtend(api.eth.SyncMode(), block.Header()); err == nil {
log.Debug("Payload accepted for sync extension", "number", block.NumberU64(), "hash", block.Hash())
return beacon.PayloadStatusV1{Status: beacon.SYNCING}, nil
return engine.PayloadStatusV1{Status: engine.SYNCING}, nil
}
// Either no beacon sync was started yet, or it rejected the delivered
// payload as non-integratable on top of the existing sync. We'll just
@ -553,7 +553,7 @@ func (api *ConsensusAPI) delayPayloadImport(block *types.Block) (beacon.PayloadS
// and cannot afford concurrent out-if-band modifications via imports.
log.Warn("Ignoring payload while snap syncing", "number", block.NumberU64(), "hash", block.Hash())
}
return beacon.PayloadStatusV1{Status: beacon.SYNCING}, nil
return engine.PayloadStatusV1{Status: engine.SYNCING}, nil
}
// setInvalidAncestor is a callback for the downloader to notify us if a bad block
@ -568,7 +568,7 @@ func (api *ConsensusAPI) setInvalidAncestor(invalid *types.Header, origin *types
// checkInvalidAncestor checks whether the specified chain end links to a known
// bad ancestor. If yes, it constructs the payload failure response to return.
func (api *ConsensusAPI) checkInvalidAncestor(check common.Hash, head common.Hash) *beacon.PayloadStatusV1 {
func (api *ConsensusAPI) checkInvalidAncestor(check common.Hash, head common.Hash) *engine.PayloadStatusV1 {
api.invalidLock.Lock()
defer api.invalidLock.Unlock()
@ -610,8 +610,8 @@ func (api *ConsensusAPI) checkInvalidAncestor(check common.Hash, head common.Has
lastValid = &common.Hash{}
}
failure := "links to previously rejected block"
return &beacon.PayloadStatusV1{
Status: beacon.INVALID,
return &engine.PayloadStatusV1{
Status: engine.INVALID,
LatestValidHash: lastValid,
ValidationError: &failure,
}
@ -619,7 +619,7 @@ func (api *ConsensusAPI) checkInvalidAncestor(check common.Hash, head common.Has
// invalid returns a response "INVALID" with the latest valid hash supplied by latest or to the current head
// if no latestValid block was provided.
func (api *ConsensusAPI) invalid(err error, latestValid *types.Header) beacon.PayloadStatusV1 {
func (api *ConsensusAPI) invalid(err error, latestValid *types.Header) engine.PayloadStatusV1 {
currentHash := api.eth.BlockChain().CurrentBlock().Hash()
if latestValid != nil {
// Set latest valid hash to 0x0 if parent is PoW block
@ -630,7 +630,7 @@ func (api *ConsensusAPI) invalid(err error, latestValid *types.Header) beacon.Pa
}
}
errorMsg := err.Error()
return beacon.PayloadStatusV1{Status: beacon.INVALID, LatestValidHash: &currentHash, ValidationError: &errorMsg}
return engine.PayloadStatusV1{Status: engine.INVALID, LatestValidHash: &currentHash, ValidationError: &errorMsg}
}
// heartbeat loops indefinitely, and checks if there have been beacon client updates
@ -761,8 +761,8 @@ func (api *ConsensusAPI) ExchangeCapabilities([]string) []string {
// GetPayloadBodiesV1 implements engine_getPayloadBodiesByHashV1 which allows for retrieval of a list
// of block bodies by the engine api.
func (api *ConsensusAPI) GetPayloadBodiesByHashV1(hashes []common.Hash) []*beacon.ExecutionPayloadBodyV1 {
var bodies = make([]*beacon.ExecutionPayloadBodyV1, len(hashes))
func (api *ConsensusAPI) GetPayloadBodiesByHashV1(hashes []common.Hash) []*engine.ExecutionPayloadBodyV1 {
var bodies = make([]*engine.ExecutionPayloadBodyV1, len(hashes))
for i, hash := range hashes {
block := api.eth.BlockChain().GetBlockByHash(hash)
bodies[i] = getBody(block)
@ -772,9 +772,9 @@ func (api *ConsensusAPI) GetPayloadBodiesByHashV1(hashes []common.Hash) []*beaco
// GetPayloadBodiesByRangeV1 implements engine_getPayloadBodiesByRangeV1 which allows for retrieval of a range
// of block bodies by the engine api.
func (api *ConsensusAPI) GetPayloadBodiesByRangeV1(start, count uint64) ([]*beacon.ExecutionPayloadBodyV1, error) {
func (api *ConsensusAPI) GetPayloadBodiesByRangeV1(start, count uint64) ([]*engine.ExecutionPayloadBodyV1, error) {
if start == 0 || count == 0 || count > 1024 {
return nil, beacon.InvalidParams.With(fmt.Errorf("invalid start or count, start: %v count: %v", start, count))
return nil, engine.InvalidParams.With(fmt.Errorf("invalid start or count, start: %v count: %v", start, count))
}
// limit count up until current
current := api.eth.BlockChain().CurrentBlock().NumberU64()
@ -782,7 +782,7 @@ func (api *ConsensusAPI) GetPayloadBodiesByRangeV1(start, count uint64) ([]*beac
if end > current {
end = current
}
var bodies []*beacon.ExecutionPayloadBodyV1
var bodies []*engine.ExecutionPayloadBodyV1
for i := start; i < end; i++ {
block := api.eth.BlockChain().GetBlockByNumber(i)
bodies = append(bodies, getBody(block))
@ -790,7 +790,7 @@ func (api *ConsensusAPI) GetPayloadBodiesByRangeV1(start, count uint64) ([]*beac
return bodies, nil
}
func getBody(block *types.Block) *beacon.ExecutionPayloadBodyV1 {
func getBody(block *types.Block) *engine.ExecutionPayloadBodyV1 {
if block == nil {
return nil
}
@ -811,7 +811,7 @@ func getBody(block *types.Block) *beacon.ExecutionPayloadBodyV1 {
withdrawals = make([]*types.Withdrawal, 0)
}
return &beacon.ExecutionPayloadBodyV1{
return &engine.ExecutionPayloadBodyV1{
TransactionData: txs,
Withdrawals: withdrawals,
}

View File

@ -25,13 +25,13 @@ import (
"testing"
"time"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus"
beaconConsensus "github.com/ethereum/go-ethereum/consensus/beacon"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/beacon"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
@ -105,7 +105,7 @@ func TestEth2AssembleBlock(t *testing.T) {
t.Fatalf("error signing transaction, err=%v", err)
}
ethservice.TxPool().AddLocal(tx)
blockParams := beacon.PayloadAttributes{
blockParams := engine.PayloadAttributes{
Timestamp: blocks[9].Time() + 5,
}
// The miner needs to pick up on the txs in the pool, so a few retries might be
@ -117,7 +117,7 @@ func TestEth2AssembleBlock(t *testing.T) {
// assembleWithTransactions tries to assemble a block, retrying until it has 'want',
// number of transactions in it, or it has retried three times.
func assembleWithTransactions(api *ConsensusAPI, parentHash common.Hash, params *beacon.PayloadAttributes, want int) (execData *beacon.ExecutableData, err error) {
func assembleWithTransactions(api *ConsensusAPI, parentHash common.Hash, params *engine.PayloadAttributes, want int) (execData *engine.ExecutableData, err error) {
for retries := 3; retries > 0; retries-- {
execData, err = assembleBlock(api, parentHash, params)
if err != nil {
@ -141,7 +141,7 @@ func TestEth2AssembleBlockWithAnotherBlocksTxs(t *testing.T) {
// Put the 10th block's tx in the pool and produce a new block
api.eth.TxPool().AddRemotesSync(blocks[9].Transactions())
blockParams := beacon.PayloadAttributes{
blockParams := engine.PayloadAttributes{
Timestamp: blocks[8].Time() + 5,
}
// The miner needs to pick up on the txs in the pool, so a few retries might be
@ -157,14 +157,14 @@ func TestSetHeadBeforeTotalDifficulty(t *testing.T) {
defer n.Close()
api := NewConsensusAPI(ethservice)
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: blocks[5].Hash(),
SafeBlockHash: common.Hash{},
FinalizedBlockHash: common.Hash{},
}
if resp, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil {
t.Errorf("fork choice updated should not error: %v", err)
} else if resp.PayloadStatus.Status != beacon.INVALID_TERMINAL_BLOCK.Status {
} else if resp.PayloadStatus.Status != engine.INVALID_TERMINAL_BLOCK.Status {
t.Errorf("fork choice updated before total terminal difficulty should be INVALID")
}
}
@ -180,10 +180,10 @@ func TestEth2PrepareAndGetPayload(t *testing.T) {
// Put the 10th block's tx in the pool and produce a new block
ethservice.TxPool().AddLocals(blocks[9].Transactions())
blockParams := beacon.PayloadAttributes{
blockParams := engine.PayloadAttributes{
Timestamp: blocks[8].Time() + 5,
}
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: blocks[8].Hash(),
SafeBlockHash: common.Hash{},
FinalizedBlockHash: common.Hash{},
@ -208,7 +208,7 @@ func TestEth2PrepareAndGetPayload(t *testing.T) {
t.Fatalf("invalid number of transactions %d != 1", len(execData.Transactions))
}
// Test invalid payloadID
var invPayload beacon.PayloadID
var invPayload engine.PayloadID
copy(invPayload[:], payloadID[:])
invPayload[0] = ^invPayload[0]
_, err = api.GetPayloadV1(invPayload)
@ -259,12 +259,12 @@ func TestInvalidPayloadTimestamp(t *testing.T) {
for i, test := range tests {
t.Run(fmt.Sprintf("Timestamp test: %v", i), func(t *testing.T) {
params := beacon.PayloadAttributes{
params := engine.PayloadAttributes{
Timestamp: test.time,
Random: crypto.Keccak256Hash([]byte{byte(123)}),
SuggestedFeeRecipient: parent.Coinbase(),
}
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: parent.Hash(),
SafeBlockHash: common.Hash{},
FinalizedBlockHash: common.Hash{},
@ -303,13 +303,13 @@ func TestEth2NewBlock(t *testing.T) {
tx, _ := types.SignTx(types.NewContractCreation(nonce, new(big.Int), 1000000, big.NewInt(2*params.InitialBaseFee), logCode), types.LatestSigner(ethservice.BlockChain().Config()), testKey)
ethservice.TxPool().AddLocal(tx)
execData, err := assembleWithTransactions(api, parent.Hash(), &beacon.PayloadAttributes{
execData, err := assembleWithTransactions(api, parent.Hash(), &engine.PayloadAttributes{
Timestamp: parent.Time() + 5,
}, 1)
if err != nil {
t.Fatalf("Failed to create the executable data %v", err)
}
block, err := beacon.ExecutableDataToBlock(*execData)
block, err := engine.ExecutableDataToBlock(*execData)
if err != nil {
t.Fatalf("Failed to convert executable data to block %v", err)
}
@ -323,7 +323,7 @@ func TestEth2NewBlock(t *testing.T) {
t.Fatalf("Chain head shouldn't be updated")
}
checkLogEvents(t, newLogCh, rmLogsCh, 0, 0)
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: block.Hash(),
SafeBlockHash: block.Hash(),
FinalizedBlockHash: block.Hash(),
@ -345,13 +345,13 @@ func TestEth2NewBlock(t *testing.T) {
)
parent = preMergeBlocks[len(preMergeBlocks)-1]
for i := 0; i < 10; i++ {
execData, err := assembleBlock(api, parent.Hash(), &beacon.PayloadAttributes{
execData, err := assembleBlock(api, parent.Hash(), &engine.PayloadAttributes{
Timestamp: parent.Time() + 6,
})
if err != nil {
t.Fatalf("Failed to create the executable data %v", err)
}
block, err := beacon.ExecutableDataToBlock(*execData)
block, err := engine.ExecutableDataToBlock(*execData)
if err != nil {
t.Fatalf("Failed to convert executable data to block %v", err)
}
@ -363,7 +363,7 @@ func TestEth2NewBlock(t *testing.T) {
t.Fatalf("Chain head shouldn't be updated")
}
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: block.Hash(),
SafeBlockHash: block.Hash(),
FinalizedBlockHash: block.Hash(),
@ -488,10 +488,10 @@ func setupBlocks(t *testing.T, ethservice *eth.Ethereum, n int, parent *types.Bl
if err != nil {
t.Fatalf("can't execute payload: %v", err)
}
if execResp.Status != beacon.VALID {
if execResp.Status != engine.VALID {
t.Fatalf("invalid status: %v", execResp.Status)
}
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: payload.BlockHash,
SafeBlockHash: payload.ParentHash,
FinalizedBlockHash: payload.ParentHash,
@ -518,7 +518,7 @@ func TestExchangeTransitionConfig(t *testing.T) {
// invalid ttd
api := NewConsensusAPI(ethservice)
config := beacon.TransitionConfigurationV1{
config := engine.TransitionConfigurationV1{
TerminalTotalDifficulty: (*hexutil.Big)(big.NewInt(0)),
TerminalBlockHash: common.Hash{},
TerminalBlockNumber: 0,
@ -527,7 +527,7 @@ func TestExchangeTransitionConfig(t *testing.T) {
t.Fatal("expected error on invalid config, invalid ttd")
}
// invalid terminal block hash
config = beacon.TransitionConfigurationV1{
config = engine.TransitionConfigurationV1{
TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty),
TerminalBlockHash: common.Hash{1},
TerminalBlockNumber: 0,
@ -536,7 +536,7 @@ func TestExchangeTransitionConfig(t *testing.T) {
t.Fatal("expected error on invalid config, invalid hash")
}
// valid config
config = beacon.TransitionConfigurationV1{
config = engine.TransitionConfigurationV1{
TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty),
TerminalBlockHash: common.Hash{},
TerminalBlockNumber: 0,
@ -545,7 +545,7 @@ func TestExchangeTransitionConfig(t *testing.T) {
t.Fatalf("expected no error on valid config, got %v", err)
}
// valid config
config = beacon.TransitionConfigurationV1{
config = engine.TransitionConfigurationV1{
TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty),
TerminalBlockHash: preMergeBlocks[5].Hash(),
TerminalBlockNumber: 6,
@ -595,25 +595,25 @@ func TestNewPayloadOnInvalidChain(t *testing.T) {
})
ethservice.TxPool().AddRemotesSync([]*types.Transaction{tx})
var (
params = beacon.PayloadAttributes{
params = engine.PayloadAttributes{
Timestamp: parent.Time() + 1,
Random: crypto.Keccak256Hash([]byte{byte(i)}),
SuggestedFeeRecipient: parent.Coinbase(),
}
fcState = beacon.ForkchoiceStateV1{
fcState = engine.ForkchoiceStateV1{
HeadBlockHash: parent.Hash(),
SafeBlockHash: common.Hash{},
FinalizedBlockHash: common.Hash{},
}
payload *beacon.ExecutableData
resp beacon.ForkChoiceResponse
payload *engine.ExecutableData
resp engine.ForkChoiceResponse
err error
)
for i := 0; ; i++ {
if resp, err = api.ForkchoiceUpdatedV1(fcState, &params); err != nil {
t.Fatalf("error preparing payload, err=%v", err)
}
if resp.PayloadStatus.Status != beacon.VALID {
if resp.PayloadStatus.Status != engine.VALID {
t.Fatalf("error preparing payload, invalid status: %v", resp.PayloadStatus.Status)
}
// give the payload some time to be built
@ -634,10 +634,10 @@ func TestNewPayloadOnInvalidChain(t *testing.T) {
if err != nil {
t.Fatalf("can't execute payload: %v", err)
}
if execResp.Status != beacon.VALID {
if execResp.Status != engine.VALID {
t.Fatalf("invalid status: %v", execResp.Status)
}
fcState = beacon.ForkchoiceStateV1{
fcState = engine.ForkchoiceStateV1{
HeadBlockHash: payload.BlockHash,
SafeBlockHash: payload.ParentHash,
FinalizedBlockHash: payload.ParentHash,
@ -652,7 +652,7 @@ func TestNewPayloadOnInvalidChain(t *testing.T) {
}
}
func assembleBlock(api *ConsensusAPI, parentHash common.Hash, params *beacon.PayloadAttributes) (*beacon.ExecutableData, error) {
func assembleBlock(api *ConsensusAPI, parentHash common.Hash, params *engine.PayloadAttributes) (*engine.ExecutableData, error) {
args := &miner.BuildPayloadArgs{
Parent: parentHash,
Timestamp: params.Timestamp,
@ -685,7 +685,7 @@ func TestEmptyBlocks(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if status.Status != beacon.VALID {
if status.Status != engine.VALID {
t.Errorf("invalid status: expected VALID got: %v", status.Status)
}
if !bytes.Equal(status.LatestValidHash[:], payload.BlockHash[:]) {
@ -701,7 +701,7 @@ func TestEmptyBlocks(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if status.Status != beacon.INVALID {
if status.Status != engine.INVALID {
t.Errorf("invalid status: expected INVALID got: %v", status.Status)
}
// Expect 0x0 on INVALID block on top of PoW block
@ -719,7 +719,7 @@ func TestEmptyBlocks(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if status.Status != beacon.SYNCING {
if status.Status != engine.SYNCING {
t.Errorf("invalid status: expected SYNCING got: %v", status.Status)
}
if status.LatestValidHash != nil {
@ -727,8 +727,8 @@ func TestEmptyBlocks(t *testing.T) {
}
}
func getNewPayload(t *testing.T, api *ConsensusAPI, parent *types.Block) *beacon.ExecutableData {
params := beacon.PayloadAttributes{
func getNewPayload(t *testing.T, api *ConsensusAPI, parent *types.Block) *engine.ExecutableData {
params := engine.PayloadAttributes{
Timestamp: parent.Time() + 1,
Random: crypto.Keccak256Hash([]byte{byte(1)}),
SuggestedFeeRecipient: parent.Coinbase(),
@ -743,7 +743,7 @@ func getNewPayload(t *testing.T, api *ConsensusAPI, parent *types.Block) *beacon
// setBlockhash sets the blockhash of a modified ExecutableData.
// Can be used to make modified payloads look valid.
func setBlockhash(data *beacon.ExecutableData) *beacon.ExecutableData {
func setBlockhash(data *engine.ExecutableData) *engine.ExecutableData {
txs, _ := decodeTransactions(data.Transactions)
number := big.NewInt(0)
number.SetUint64(data.Number)
@ -802,7 +802,7 @@ func TestTrickRemoteBlockCache(t *testing.T) {
setupBlocks(t, ethserviceA, 10, commonAncestor, func(parent *types.Block) {})
commonAncestor = ethserviceA.BlockChain().CurrentBlock()
var invalidChain []*beacon.ExecutableData
var invalidChain []*engine.ExecutableData
// create a valid payload (P1)
//payload1 := getNewPayload(t, apiA, commonAncestor)
//invalidChain = append(invalidChain, payload1)
@ -830,15 +830,15 @@ func TestTrickRemoteBlockCache(t *testing.T) {
if err != nil {
panic(err)
}
if status.Status == beacon.VALID {
if status.Status == engine.VALID {
t.Error("invalid status: VALID on an invalid chain")
}
// Now reorg to the head of the invalid chain
resp, err := apiB.ForkchoiceUpdatedV1(beacon.ForkchoiceStateV1{HeadBlockHash: payload.BlockHash, SafeBlockHash: payload.BlockHash, FinalizedBlockHash: payload.ParentHash}, nil)
resp, err := apiB.ForkchoiceUpdatedV1(engine.ForkchoiceStateV1{HeadBlockHash: payload.BlockHash, SafeBlockHash: payload.BlockHash, FinalizedBlockHash: payload.ParentHash}, nil)
if err != nil {
t.Fatal(err)
}
if resp.PayloadStatus.Status == beacon.VALID {
if resp.PayloadStatus.Status == engine.VALID {
t.Error("invalid status: VALID on an invalid chain")
}
time.Sleep(100 * time.Millisecond)
@ -864,7 +864,7 @@ func TestInvalidBloom(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if status.Status != beacon.INVALIDBLOCKHASH {
if status.Status != engine.INVALIDBLOCKHASH {
t.Errorf("invalid status: expected VALID got: %v", status.Status)
}
}
@ -882,7 +882,7 @@ func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) {
)
// Test parent already post TTD in FCU
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: parent.Hash(),
SafeBlockHash: common.Hash{},
FinalizedBlockHash: common.Hash{},
@ -891,7 +891,7 @@ func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) {
if err != nil {
t.Fatalf("error sending forkchoice, err=%v", err)
}
if resp.PayloadStatus != beacon.INVALID_TERMINAL_BLOCK {
if resp.PayloadStatus != engine.INVALID_TERMINAL_BLOCK {
t.Fatalf("error sending invalid forkchoice, invalid status: %v", resp.PayloadStatus.Status)
}
@ -911,7 +911,7 @@ func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) {
if err != nil {
t.Fatalf("error sending NewPayload, err=%v", err)
}
if resp2 != beacon.INVALID_TERMINAL_BLOCK {
if resp2 != engine.INVALID_TERMINAL_BLOCK {
t.Fatalf("error sending invalid forkchoice, invalid status: %v", resp.PayloadStatus.Status)
}
}
@ -929,7 +929,7 @@ func TestSimultaneousNewBlock(t *testing.T) {
parent = preMergeBlocks[len(preMergeBlocks)-1]
)
for i := 0; i < 10; i++ {
execData, err := assembleBlock(api, parent.Hash(), &beacon.PayloadAttributes{
execData, err := assembleBlock(api, parent.Hash(), &engine.PayloadAttributes{
Timestamp: parent.Time() + 5,
})
if err != nil {
@ -962,14 +962,14 @@ func TestSimultaneousNewBlock(t *testing.T) {
t.Fatal(testErr)
}
}
block, err := beacon.ExecutableDataToBlock(*execData)
block, err := engine.ExecutableDataToBlock(*execData)
if err != nil {
t.Fatalf("Failed to convert executable data to block %v", err)
}
if ethservice.BlockChain().CurrentBlock().NumberU64() != block.NumberU64()-1 {
t.Fatalf("Chain head shouldn't be updated")
}
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: block.Hash(),
SafeBlockHash: block.Hash(),
FinalizedBlockHash: block.Hash(),
@ -1020,19 +1020,19 @@ func TestWithdrawals(t *testing.T) {
// 10: Build Shanghai block with no withdrawals.
parent := ethservice.BlockChain().CurrentHeader()
blockParams := beacon.PayloadAttributes{
blockParams := engine.PayloadAttributes{
Timestamp: parent.Time + 5,
Withdrawals: make([]*types.Withdrawal, 0),
}
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: parent.Hash(),
}
resp, err := api.ForkchoiceUpdatedV2(fcState, &blockParams)
if err != nil {
t.Fatalf("error preparing payload, err=%v", err)
}
if resp.PayloadStatus.Status != beacon.VALID {
t.Fatalf("unexpected status (got: %s, want: %s)", resp.PayloadStatus.Status, beacon.VALID)
if resp.PayloadStatus.Status != engine.VALID {
t.Fatalf("unexpected status (got: %s, want: %s)", resp.PayloadStatus.Status, engine.VALID)
}
// 10: verify state root is the same as parent
@ -1053,14 +1053,14 @@ func TestWithdrawals(t *testing.T) {
// 10: verify locally built block
if status, err := api.NewPayloadV2(*execData.ExecutionPayload); err != nil {
t.Fatalf("error validating payload: %v", err)
} else if status.Status != beacon.VALID {
} else if status.Status != engine.VALID {
t.Fatalf("invalid payload")
}
// 11: build shanghai block with withdrawal
aa := common.Address{0xaa}
bb := common.Address{0xbb}
blockParams = beacon.PayloadAttributes{
blockParams = engine.PayloadAttributes{
Timestamp: execData.ExecutionPayload.Timestamp + 5,
Withdrawals: []*types.Withdrawal{
{
@ -1094,7 +1094,7 @@ func TestWithdrawals(t *testing.T) {
}
if status, err := api.NewPayloadV2(*execData.ExecutionPayload); err != nil {
t.Fatalf("error validating payload: %v", err)
} else if status.Status != beacon.VALID {
} else if status.Status != engine.VALID {
t.Fatalf("invalid payload")
}
@ -1133,27 +1133,27 @@ func TestNilWithdrawals(t *testing.T) {
aa := common.Address{0xaa}
type test struct {
blockParams beacon.PayloadAttributes
blockParams engine.PayloadAttributes
wantErr bool
}
tests := []test{
// Before Shanghai
{
blockParams: beacon.PayloadAttributes{
blockParams: engine.PayloadAttributes{
Timestamp: parent.Time + 2,
Withdrawals: nil,
},
wantErr: false,
},
{
blockParams: beacon.PayloadAttributes{
blockParams: engine.PayloadAttributes{
Timestamp: parent.Time + 2,
Withdrawals: make([]*types.Withdrawal, 0),
},
wantErr: true,
},
{
blockParams: beacon.PayloadAttributes{
blockParams: engine.PayloadAttributes{
Timestamp: parent.Time + 2,
Withdrawals: []*types.Withdrawal{
{
@ -1167,21 +1167,21 @@ func TestNilWithdrawals(t *testing.T) {
},
// After Shanghai
{
blockParams: beacon.PayloadAttributes{
blockParams: engine.PayloadAttributes{
Timestamp: parent.Time + 5,
Withdrawals: nil,
},
wantErr: true,
},
{
blockParams: beacon.PayloadAttributes{
blockParams: engine.PayloadAttributes{
Timestamp: parent.Time + 5,
Withdrawals: make([]*types.Withdrawal, 0),
},
wantErr: false,
},
{
blockParams: beacon.PayloadAttributes{
blockParams: engine.PayloadAttributes{
Timestamp: parent.Time + 5,
Withdrawals: []*types.Withdrawal{
{
@ -1195,7 +1195,7 @@ func TestNilWithdrawals(t *testing.T) {
},
}
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: parent.Hash(),
}
@ -1224,7 +1224,7 @@ func TestNilWithdrawals(t *testing.T) {
}
if status, err := api.NewPayloadV2(*execData.ExecutionPayload); err != nil {
t.Fatalf("error validating payload: %v", err)
} else if status.Status != beacon.VALID {
} else if status.Status != engine.VALID {
t.Fatalf("invalid payload")
}
}
@ -1400,7 +1400,7 @@ func TestGetBlockBodiesByRangeInvalidParams(t *testing.T) {
}
}
func equalBody(a *types.Body, b *beacon.ExecutionPayloadBodyV1) bool {
func equalBody(a *types.Body, b *engine.ExecutionPayloadBodyV1) bool {
if a == nil && b == nil {
return true
} else if a == nil || b == nil {

View File

@ -19,8 +19,8 @@ package catalyst
import (
"sync"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/beacon"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/miner"
)
@ -38,7 +38,7 @@ const maxTrackedHeaders = 10
// payloadQueueItem represents an id->payload tuple to store until it's retrieved
// or evicted.
type payloadQueueItem struct {
id beacon.PayloadID
id engine.PayloadID
payload *miner.Payload
}
@ -58,7 +58,7 @@ func newPayloadQueue() *payloadQueue {
}
// put inserts a new payload into the queue at the given id.
func (q *payloadQueue) put(id beacon.PayloadID, payload *miner.Payload) {
func (q *payloadQueue) put(id engine.PayloadID, payload *miner.Payload) {
q.lock.Lock()
defer q.lock.Unlock()
@ -70,7 +70,7 @@ func (q *payloadQueue) put(id beacon.PayloadID, payload *miner.Payload) {
}
// get retrieves a previously stored payload item or nil if it does not exist.
func (q *payloadQueue) get(id beacon.PayloadID) *beacon.ExecutionPayloadEnvelope {
func (q *payloadQueue) get(id engine.PayloadID) *engine.ExecutionPayloadEnvelope {
q.lock.RLock()
defer q.lock.RUnlock()
@ -86,7 +86,7 @@ func (q *payloadQueue) get(id beacon.PayloadID) *beacon.ExecutionPayloadEnvelope
}
// has checks if a particular payload is already tracked.
func (q *payloadQueue) has(id beacon.PayloadID) bool {
func (q *payloadQueue) has(id engine.PayloadID) bool {
q.lock.RLock()
defer q.lock.RUnlock()

View File

@ -21,9 +21,9 @@ import (
"errors"
"fmt"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/beacon"
"github.com/ethereum/go-ethereum/les"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
@ -70,43 +70,43 @@ func NewConsensusAPI(les *les.LightEthereum) *ConsensusAPI {
//
// If there are payloadAttributes: we return an error since block creation is not
// supported in les mode.
func (api *ConsensusAPI) ForkchoiceUpdatedV1(heads beacon.ForkchoiceStateV1, payloadAttributes *beacon.PayloadAttributes) (beacon.ForkChoiceResponse, error) {
func (api *ConsensusAPI) ForkchoiceUpdatedV1(heads engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) {
if heads.HeadBlockHash == (common.Hash{}) {
log.Warn("Forkchoice requested update to zero hash")
return beacon.STATUS_INVALID, nil // TODO(karalabe): Why does someone send us this?
return engine.STATUS_INVALID, nil // TODO(karalabe): Why does someone send us this?
}
if err := api.checkTerminalTotalDifficulty(heads.HeadBlockHash); err != nil {
if header := api.les.BlockChain().GetHeaderByHash(heads.HeadBlockHash); header == nil {
// TODO (MariusVanDerWijden) trigger sync
return beacon.STATUS_SYNCING, nil
return engine.STATUS_SYNCING, nil
}
return beacon.STATUS_INVALID, err
return engine.STATUS_INVALID, err
}
// If the finalized block is set, check if it is in our blockchain
if heads.FinalizedBlockHash != (common.Hash{}) {
if header := api.les.BlockChain().GetHeaderByHash(heads.FinalizedBlockHash); header == nil {
// TODO (MariusVanDerWijden) trigger sync
return beacon.STATUS_SYNCING, nil
return engine.STATUS_SYNCING, nil
}
}
// SetHead
if err := api.setCanonical(heads.HeadBlockHash); err != nil {
return beacon.STATUS_INVALID, err
return engine.STATUS_INVALID, err
}
if payloadAttributes != nil {
return beacon.STATUS_INVALID, errors.New("not supported")
return engine.STATUS_INVALID, errors.New("not supported")
}
return api.validForkChoiceResponse(), nil
}
// GetPayloadV1 returns a cached payload by id. It's not supported in les mode.
func (api *ConsensusAPI) GetPayloadV1(payloadID beacon.PayloadID) (*beacon.ExecutableData, error) {
return nil, beacon.GenericServerError.With(errors.New("not supported in light client mode"))
func (api *ConsensusAPI) GetPayloadV1(payloadID engine.PayloadID) (*engine.ExecutableData, error) {
return nil, engine.GenericServerError.With(errors.New("not supported in light client mode"))
}
// ExecutePayloadV1 creates an Eth1 block, inserts it in the chain, and returns the status of the chain.
func (api *ConsensusAPI) ExecutePayloadV1(params beacon.ExecutableData) (beacon.PayloadStatusV1, error) {
block, err := beacon.ExecutableDataToBlock(params)
func (api *ConsensusAPI) ExecutePayloadV1(params engine.ExecutableData) (engine.PayloadStatusV1, error) {
block, err := engine.ExecutableDataToBlock(params)
if err != nil {
return api.invalid(), err
}
@ -118,7 +118,7 @@ func (api *ConsensusAPI) ExecutePayloadV1(params beacon.ExecutableData) (beacon.
}
*/
// TODO (MariusVanDerWijden) we should return nil here not empty hash
return beacon.PayloadStatusV1{Status: beacon.SYNCING, LatestValidHash: nil}, nil
return engine.PayloadStatusV1{Status: engine.SYNCING, LatestValidHash: nil}, nil
}
parent := api.les.BlockChain().GetHeaderByHash(params.ParentHash)
if parent == nil {
@ -136,20 +136,20 @@ func (api *ConsensusAPI) ExecutePayloadV1(params beacon.ExecutableData) (beacon.
merger.ReachTTD()
}
hash := block.Hash()
return beacon.PayloadStatusV1{Status: beacon.VALID, LatestValidHash: &hash}, nil
return engine.PayloadStatusV1{Status: engine.VALID, LatestValidHash: &hash}, nil
}
func (api *ConsensusAPI) validForkChoiceResponse() beacon.ForkChoiceResponse {
func (api *ConsensusAPI) validForkChoiceResponse() engine.ForkChoiceResponse {
currentHash := api.les.BlockChain().CurrentHeader().Hash()
return beacon.ForkChoiceResponse{
PayloadStatus: beacon.PayloadStatusV1{Status: beacon.VALID, LatestValidHash: &currentHash},
return engine.ForkChoiceResponse{
PayloadStatus: engine.PayloadStatusV1{Status: engine.VALID, LatestValidHash: &currentHash},
}
}
// invalid returns a response "INVALID" with the latest valid hash set to the current head.
func (api *ConsensusAPI) invalid() beacon.PayloadStatusV1 {
func (api *ConsensusAPI) invalid() engine.PayloadStatusV1 {
currentHash := api.les.BlockChain().CurrentHeader().Hash()
return beacon.PayloadStatusV1{Status: beacon.INVALID, LatestValidHash: &currentHash}
return engine.PayloadStatusV1{Status: engine.INVALID, LatestValidHash: &currentHash}
}
func (api *ConsensusAPI) checkTerminalTotalDifficulty(head common.Hash) error {
@ -193,7 +193,7 @@ func (api *ConsensusAPI) setCanonical(newHead common.Hash) error {
// ExchangeTransitionConfigurationV1 checks the given configuration against
// the configuration of the node.
func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config beacon.TransitionConfigurationV1) (*beacon.TransitionConfigurationV1, error) {
func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config engine.TransitionConfigurationV1) (*engine.TransitionConfigurationV1, error) {
log.Trace("Engine API request received", "method", "ExchangeTransitionConfiguration", "ttd", config.TerminalTotalDifficulty)
if config.TerminalTotalDifficulty == nil {
return nil, errors.New("invalid terminal total difficulty")
@ -207,7 +207,7 @@ func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config beacon.Transit
if config.TerminalBlockHash != (common.Hash{}) {
if hash := api.les.BlockChain().GetCanonicalHash(uint64(config.TerminalBlockNumber)); hash == config.TerminalBlockHash {
return &beacon.TransitionConfigurationV1{
return &engine.TransitionConfigurationV1{
TerminalTotalDifficulty: (*hexutil.Big)(ttd),
TerminalBlockHash: config.TerminalBlockHash,
TerminalBlockNumber: config.TerminalBlockNumber,
@ -216,5 +216,5 @@ func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config beacon.Transit
return nil, fmt.Errorf("invalid terminal block hash")
}
return &beacon.TransitionConfigurationV1{TerminalTotalDifficulty: (*hexutil.Big)(ttd)}, nil
return &engine.TransitionConfigurationV1{TerminalTotalDifficulty: (*hexutil.Big)(ttd)}, nil
}

View File

@ -20,10 +20,10 @@ import (
"math/big"
"testing"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/beacon"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/downloader"
@ -84,7 +84,7 @@ func TestSetHeadBeforeTotalDifficulty(t *testing.T) {
defer n.Close()
api := NewConsensusAPI(lesService)
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: blocks[5].Hash(),
SafeBlockHash: common.Hash{},
FinalizedBlockHash: common.Hash{},
@ -101,7 +101,7 @@ func TestExecutePayloadV1(t *testing.T) {
defer n.Close()
api := NewConsensusAPI(lesService)
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: postBlocks[0].Hash(),
SafeBlockHash: common.Hash{},
FinalizedBlockHash: common.Hash{},
@ -130,7 +130,7 @@ func TestExecutePayloadV1(t *testing.T) {
BaseFee: block.BaseFee(),
}, nil, nil, nil, trie.NewStackTrie(nil))
_, err := api.ExecutePayloadV1(beacon.ExecutableData{
_, err := api.ExecutePayloadV1(engine.ExecutableData{
ParentHash: fakeBlock.ParentHash(),
FeeRecipient: fakeBlock.Coinbase(),
StateRoot: fakeBlock.Root(),
@ -153,7 +153,7 @@ func TestExecutePayloadV1(t *testing.T) {
if headHeader.Number.Uint64() != fakeBlock.NumberU64()-1 {
t.Fatal("Unexpected chain head update")
}
fcState = beacon.ForkchoiceStateV1{
fcState = engine.ForkchoiceStateV1{
HeadBlockHash: fakeBlock.Hash(),
SafeBlockHash: common.Hash{},
FinalizedBlockHash: common.Hash{},

View File

@ -23,8 +23,8 @@ import (
"sync"
"time"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/beacon"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
@ -42,14 +42,14 @@ type BuildPayloadArgs struct {
}
// Id computes an 8-byte identifier by hashing the components of the payload arguments.
func (args *BuildPayloadArgs) Id() beacon.PayloadID {
func (args *BuildPayloadArgs) Id() engine.PayloadID {
// Hash
hasher := sha256.New()
hasher.Write(args.Parent[:])
binary.Write(hasher, binary.BigEndian, args.Timestamp)
hasher.Write(args.Random[:])
hasher.Write(args.FeeRecipient[:])
var out beacon.PayloadID
var out engine.PayloadID
copy(out[:], hasher.Sum(nil)[:8])
return out
}
@ -60,7 +60,7 @@ func (args *BuildPayloadArgs) Id() beacon.PayloadID {
// the revenue. Therefore, the empty-block here is always available and full-block
// will be set/updated afterwards.
type Payload struct {
id beacon.PayloadID
id engine.PayloadID
empty *types.Block
full *types.Block
fullFees *big.Int
@ -70,7 +70,7 @@ type Payload struct {
}
// newPayload initializes the payload object.
func newPayload(empty *types.Block, id beacon.PayloadID) *Payload {
func newPayload(empty *types.Block, id engine.PayloadID) *Payload {
payload := &Payload{
id: id,
empty: empty,
@ -108,7 +108,7 @@ func (payload *Payload) update(block *types.Block, fees *big.Int, elapsed time.D
// Resolve returns the latest built payload and also terminates the background
// thread for updating payload. It's safe to be called multiple times.
func (payload *Payload) Resolve() *beacon.ExecutionPayloadEnvelope {
func (payload *Payload) Resolve() *engine.ExecutionPayloadEnvelope {
payload.lock.Lock()
defer payload.lock.Unlock()
@ -118,23 +118,23 @@ func (payload *Payload) Resolve() *beacon.ExecutionPayloadEnvelope {
close(payload.stop)
}
if payload.full != nil {
return beacon.BlockToExecutableData(payload.full, payload.fullFees)
return engine.BlockToExecutableData(payload.full, payload.fullFees)
}
return beacon.BlockToExecutableData(payload.empty, big.NewInt(0))
return engine.BlockToExecutableData(payload.empty, big.NewInt(0))
}
// ResolveEmpty is basically identical to Resolve, but it expects empty block only.
// It's only used in tests.
func (payload *Payload) ResolveEmpty() *beacon.ExecutionPayloadEnvelope {
func (payload *Payload) ResolveEmpty() *engine.ExecutionPayloadEnvelope {
payload.lock.Lock()
defer payload.lock.Unlock()
return beacon.BlockToExecutableData(payload.empty, big.NewInt(0))
return engine.BlockToExecutableData(payload.empty, big.NewInt(0))
}
// ResolveFull is basically identical to Resolve, but it expects full block only.
// It's only used in tests.
func (payload *Payload) ResolveFull() *beacon.ExecutionPayloadEnvelope {
func (payload *Payload) ResolveFull() *engine.ExecutionPayloadEnvelope {
payload.lock.Lock()
defer payload.lock.Unlock()
@ -146,7 +146,7 @@ func (payload *Payload) ResolveFull() *beacon.ExecutionPayloadEnvelope {
}
payload.cond.Wait()
}
return beacon.BlockToExecutableData(payload.full, payload.fullFees)
return engine.BlockToExecutableData(payload.full, payload.fullFees)
}
// buildPayload builds the payload according to the provided parameters.

View File

@ -21,9 +21,9 @@ import (
"testing"
"time"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core/beacon"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/params"
)
@ -47,7 +47,7 @@ func TestBuildPayload(t *testing.T) {
if err != nil {
t.Fatalf("Failed to build payload %v", err)
}
verify := func(outer *beacon.ExecutionPayloadEnvelope, txs int) {
verify := func(outer *engine.ExecutionPayloadEnvelope, txs int) {
payload := outer.ExecutionPayload
if payload.ParentHash != b.chain.CurrentBlock().Hash() {
t.Fatal("Unexpect parent hash")

View File

@ -27,11 +27,11 @@ import (
"time"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/fdlimit"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/beacon"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
@ -142,7 +142,7 @@ func newNode(typ nodetype, genesis *core.Genesis, enodes []*enode.Node) *ethNode
}
}
func (n *ethNode) assembleBlock(parentHash common.Hash, parentTimestamp uint64) (*beacon.ExecutableData, error) {
func (n *ethNode) assembleBlock(parentHash common.Hash, parentTimestamp uint64) (*engine.ExecutableData, error) {
if n.typ != eth2MiningNode {
return nil, errors.New("invalid node type")
}
@ -150,12 +150,12 @@ func (n *ethNode) assembleBlock(parentHash common.Hash, parentTimestamp uint64)
if timestamp <= parentTimestamp {
timestamp = parentTimestamp + 1
}
payloadAttribute := beacon.PayloadAttributes{
payloadAttribute := engine.PayloadAttributes{
Timestamp: timestamp,
Random: common.Hash{},
SuggestedFeeRecipient: common.HexToAddress("0xdeadbeef"),
}
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: parentHash,
SafeBlockHash: common.Hash{},
FinalizedBlockHash: common.Hash{},
@ -168,7 +168,7 @@ func (n *ethNode) assembleBlock(parentHash common.Hash, parentTimestamp uint64)
return n.api.GetPayloadV1(*payload.PayloadID)
}
func (n *ethNode) insertBlock(eb beacon.ExecutableData) error {
func (n *ethNode) insertBlock(eb engine.ExecutableData) error {
if !eth2types(n.typ) {
return errors.New("invalid node type")
}
@ -194,18 +194,18 @@ func (n *ethNode) insertBlock(eb beacon.ExecutableData) error {
}
}
func (n *ethNode) insertBlockAndSetHead(parent *types.Header, ed beacon.ExecutableData) error {
func (n *ethNode) insertBlockAndSetHead(parent *types.Header, ed engine.ExecutableData) error {
if !eth2types(n.typ) {
return errors.New("invalid node type")
}
if err := n.insertBlock(ed); err != nil {
return err
}
block, err := beacon.ExecutableDataToBlock(ed)
block, err := engine.ExecutableDataToBlock(ed)
if err != nil {
return err
}
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: block.ParentHash(),
SafeBlockHash: common.Hash{},
FinalizedBlockHash: common.Hash{},
@ -319,7 +319,7 @@ func (mgr *nodeManager) run() {
nodes = append(nodes, mgr.getNodes(eth2NormalNode)...)
//nodes = append(nodes, mgr.getNodes(eth2LightClient)...)
for _, node := range nodes {
fcState := beacon.ForkchoiceStateV1{
fcState := engine.ForkchoiceStateV1{
HeadBlockHash: parentBlock.Hash(),
SafeBlockHash: oldest.Hash(),
FinalizedBlockHash: oldest.Hash(),
@ -362,7 +362,7 @@ func (mgr *nodeManager) run() {
log.Error("Failed to assemble the block", "err", err)
continue
}
block, _ := beacon.ExecutableDataToBlock(*ed)
block, _ := engine.ExecutableDataToBlock(*ed)
nodes := mgr.getNodes(eth2MiningNode)
nodes = append(nodes, mgr.getNodes(eth2NormalNode)...)