Compare commits
4 Commits
e08bca571c
...
27d0bf7cff
Author | SHA1 | Date |
---|---|---|
|
27d0bf7cff | |
|
5aa511ecf2 | |
|
dab746b3ef | |
|
992883df31 |
|
@ -33,6 +33,8 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -95,6 +97,16 @@ 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()
|
||||||
|
@ -107,7 +119,8 @@ 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 {
|
||||||
if _, err := engineAPI.ForkchoiceUpdatedV3(current, nil); err != nil {
|
version := payloadVersion(eth.BlockChain().Config(), block.Time)
|
||||||
|
if _, err := engineAPI.forkchoiceUpdated(current, nil, version, false); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,6 +184,8 @@ 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{
|
||||||
|
@ -179,7 +194,7 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
Withdrawals: withdrawals,
|
Withdrawals: withdrawals,
|
||||||
Random: random,
|
Random: random,
|
||||||
BeaconRoot: &common.Hash{},
|
BeaconRoot: &common.Hash{},
|
||||||
}, engine.PayloadV3, false)
|
}, version, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -204,28 +219,39 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Independently calculate the blob hashes from sidecars.
|
var (
|
||||||
blobHashes := make([]common.Hash, 0)
|
blobHashes []common.Hash
|
||||||
if envelope.BlobsBundle != nil {
|
beaconRoot *common.Hash
|
||||||
hasher := sha256.New()
|
requests [][]byte
|
||||||
for _, commit := range envelope.BlobsBundle.Commitments {
|
)
|
||||||
var c kzg4844.Commitment
|
// Compute post-shanghai fields
|
||||||
if len(commit) != len(c) {
|
if version > engine.PayloadV2 {
|
||||||
return errors.New("invalid commitment length")
|
// Independently calculate the blob hashes from sidecars.
|
||||||
|
blobHashes = make([]common.Hash, 0)
|
||||||
|
if envelope.BlobsBundle != nil {
|
||||||
|
hasher := sha256.New()
|
||||||
|
for _, commit := range envelope.BlobsBundle.Commitments {
|
||||||
|
var c kzg4844.Commitment
|
||||||
|
if len(commit) != len(c) {
|
||||||
|
return errors.New("invalid commitment length")
|
||||||
|
}
|
||||||
|
copy(c[:], commit)
|
||||||
|
blobHashes = append(blobHashes, kzg4844.CalcBlobHashV1(hasher, &c))
|
||||||
}
|
}
|
||||||
copy(c[:], commit)
|
|
||||||
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, &common.Hash{}, envelope.Requests, false)
|
_, err = c.engineAPI.newPayload(*payload, blobHashes, beaconRoot, 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.ForkchoiceUpdatedV3(c.curForkchoiceState, nil); err != nil {
|
if _, err = c.engineAPI.forkchoiceUpdated(c.curForkchoiceState, nil, version, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.lastBlockTime = payload.Timestamp
|
c.lastBlockTime = payload.Timestamp
|
||||||
|
|
|
@ -194,6 +194,10 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
||||||
if precompiles != nil {
|
if precompiles != nil {
|
||||||
evm.SetPrecompiles(precompiles)
|
evm.SetPrecompiles(precompiles)
|
||||||
}
|
}
|
||||||
|
if sim.chainConfig.IsPrague(header.Number, header.Time) || sim.chainConfig.IsVerkle(header.Number, header.Time) {
|
||||||
|
core.ProcessParentBlockHash(header.ParentHash, evm)
|
||||||
|
}
|
||||||
|
var allLogs []*types.Log
|
||||||
for i, call := range block.Calls {
|
for i, call := range block.Calls {
|
||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -234,9 +238,23 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
callRes.Status = hexutil.Uint64(types.ReceiptStatusSuccessful)
|
callRes.Status = hexutil.Uint64(types.ReceiptStatusSuccessful)
|
||||||
|
allLogs = append(allLogs, callRes.Logs...)
|
||||||
}
|
}
|
||||||
callResults[i] = callRes
|
callResults[i] = callRes
|
||||||
}
|
}
|
||||||
|
var requests [][]byte
|
||||||
|
// Process EIP-7685 requests
|
||||||
|
if sim.chainConfig.IsPrague(header.Number, header.Time) {
|
||||||
|
requests = [][]byte{}
|
||||||
|
// EIP-6110
|
||||||
|
if err := core.ParseDepositLogs(&requests, allLogs, sim.chainConfig); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
// EIP-7002
|
||||||
|
core.ProcessWithdrawalQueue(&requests, evm)
|
||||||
|
// EIP-7251
|
||||||
|
core.ProcessConsolidationQueue(&requests, evm)
|
||||||
|
}
|
||||||
header.Root = sim.state.IntermediateRoot(true)
|
header.Root = sim.state.IntermediateRoot(true)
|
||||||
header.GasUsed = gasUsed
|
header.GasUsed = gasUsed
|
||||||
if sim.chainConfig.IsCancun(header.Number, header.Time) {
|
if sim.chainConfig.IsCancun(header.Number, header.Time) {
|
||||||
|
@ -246,6 +264,10 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
||||||
if sim.chainConfig.IsShanghai(header.Number, header.Time) {
|
if sim.chainConfig.IsShanghai(header.Number, header.Time) {
|
||||||
withdrawals = make([]*types.Withdrawal, 0)
|
withdrawals = make([]*types.Withdrawal, 0)
|
||||||
}
|
}
|
||||||
|
if requests != nil {
|
||||||
|
reqHash := types.CalcRequestsHash(requests)
|
||||||
|
header.RequestsHash = &reqHash
|
||||||
|
}
|
||||||
b := types.NewBlock(header, &types.Body{Transactions: txes, Withdrawals: withdrawals}, receipts, trie.NewStackTrie(nil))
|
b := types.NewBlock(header, &types.Body{Transactions: txes, Withdrawals: withdrawals}, receipts, trie.NewStackTrie(nil))
|
||||||
repairLogs(callResults, b.Hash())
|
repairLogs(callResults, b.Hash())
|
||||||
return b, callResults, nil
|
return b, callResults, nil
|
||||||
|
|
Loading…
Reference in New Issue