Compare commits
1 Commits
57355ad8ad
...
96d5ae7897
Author | SHA1 | Date |
---|---|---|
|
96d5ae7897 |
|
@ -33,8 +33,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
|
||||||
"github.com/ethereum/go-ethereum/params/forks"
|
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -97,16 +95,6 @@ type SimulatedBeacon struct {
|
||||||
lastBlockTime uint64
|
lastBlockTime uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func payloadVersion(config *params.ChainConfig, time uint64) engine.PayloadVersion {
|
|
||||||
switch config.LatestFork(time) {
|
|
||||||
case forks.Prague, forks.Cancun:
|
|
||||||
return engine.PayloadV3
|
|
||||||
case forks.Paris, forks.Shanghai:
|
|
||||||
return engine.PayloadV2
|
|
||||||
}
|
|
||||||
panic("invalid fork, simulated beacon needs to be started post-merge")
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewSimulatedBeacon constructs a new simulated beacon chain.
|
// NewSimulatedBeacon constructs a new simulated beacon chain.
|
||||||
func NewSimulatedBeacon(period uint64, eth *eth.Ethereum) (*SimulatedBeacon, error) {
|
func NewSimulatedBeacon(period uint64, eth *eth.Ethereum) (*SimulatedBeacon, error) {
|
||||||
block := eth.BlockChain().CurrentBlock()
|
block := eth.BlockChain().CurrentBlock()
|
||||||
|
@ -119,8 +107,7 @@ func NewSimulatedBeacon(period uint64, eth *eth.Ethereum) (*SimulatedBeacon, err
|
||||||
|
|
||||||
// if genesis block, send forkchoiceUpdated to trigger transition to PoS
|
// if genesis block, send forkchoiceUpdated to trigger transition to PoS
|
||||||
if block.Number.Sign() == 0 {
|
if block.Number.Sign() == 0 {
|
||||||
version := payloadVersion(eth.BlockChain().Config(), block.Time)
|
if _, err := engineAPI.ForkchoiceUpdatedV3(current, nil); err != nil {
|
||||||
if _, err := engineAPI.forkchoiceUpdated(current, nil, version, false); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,8 +171,6 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
return fmt.Errorf("failed to sync txpool: %w", err)
|
return fmt.Errorf("failed to sync txpool: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
version := payloadVersion(c.eth.BlockChain().Config(), timestamp)
|
|
||||||
|
|
||||||
var random [32]byte
|
var random [32]byte
|
||||||
rand.Read(random[:])
|
rand.Read(random[:])
|
||||||
fcResponse, err := c.engineAPI.forkchoiceUpdated(c.curForkchoiceState, &engine.PayloadAttributes{
|
fcResponse, err := c.engineAPI.forkchoiceUpdated(c.curForkchoiceState, &engine.PayloadAttributes{
|
||||||
|
@ -194,7 +179,7 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
Withdrawals: withdrawals,
|
Withdrawals: withdrawals,
|
||||||
Random: random,
|
Random: random,
|
||||||
BeaconRoot: &common.Hash{},
|
BeaconRoot: &common.Hash{},
|
||||||
}, version, false)
|
}, engine.PayloadV3, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -219,15 +204,8 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
blobHashes []common.Hash
|
|
||||||
beaconRoot *common.Hash
|
|
||||||
requests [][]byte
|
|
||||||
)
|
|
||||||
// Compute post-shanghai fields
|
|
||||||
if version > engine.PayloadV2 {
|
|
||||||
// Independently calculate the blob hashes from sidecars.
|
// Independently calculate the blob hashes from sidecars.
|
||||||
blobHashes = make([]common.Hash, 0)
|
blobHashes := make([]common.Hash, 0)
|
||||||
if envelope.BlobsBundle != nil {
|
if envelope.BlobsBundle != nil {
|
||||||
hasher := sha256.New()
|
hasher := sha256.New()
|
||||||
for _, commit := range envelope.BlobsBundle.Commitments {
|
for _, commit := range envelope.BlobsBundle.Commitments {
|
||||||
|
@ -239,19 +217,15 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
blobHashes = append(blobHashes, kzg4844.CalcBlobHashV1(hasher, &c))
|
blobHashes = append(blobHashes, kzg4844.CalcBlobHashV1(hasher, &c))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
beaconRoot = &common.Hash{}
|
|
||||||
requests = envelope.Requests
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark the payload as canon
|
// Mark the payload as canon
|
||||||
_, err = c.engineAPI.newPayload(*payload, blobHashes, beaconRoot, requests, false)
|
_, err = c.engineAPI.newPayload(*payload, blobHashes, &common.Hash{}, envelope.Requests, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.setCurrentState(payload.BlockHash, finalizedHash)
|
c.setCurrentState(payload.BlockHash, finalizedHash)
|
||||||
|
|
||||||
// Mark the block containing the payload as canonical
|
// Mark the block containing the payload as canonical
|
||||||
if _, err = c.engineAPI.forkchoiceUpdated(c.curForkchoiceState, nil, version, false); err != nil {
|
if _, err = c.engineAPI.ForkchoiceUpdatedV3(c.curForkchoiceState, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.lastBlockTime = payload.Timestamp
|
c.lastBlockTime = payload.Timestamp
|
||||||
|
|
Loading…
Reference in New Issue