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:
+12
-12
@@ -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.
|
||||
|
||||
@@ -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")
|
||||
|
||||
+10
-10
@@ -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)...)
|
||||
|
||||
Reference in New Issue
Block a user