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:
+22
-22
@@ -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: ¤tHash},
|
||||
return engine.ForkChoiceResponse{
|
||||
PayloadStatus: engine.PayloadStatusV1{Status: engine.VALID, LatestValidHash: ¤tHash},
|
||||
}
|
||||
}
|
||||
|
||||
// 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: ¤tHash}
|
||||
return engine.PayloadStatusV1{Status: engine.INVALID, LatestValidHash: ¤tHash}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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{},
|
||||
|
||||
Reference in New Issue
Block a user