Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions eth/catalyst/simulated_beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ type SimulatedBeacon struct {

func payloadVersion(config *params.ChainConfig, time uint64) engine.PayloadVersion {
switch config.LatestFork(time) {
case forks.Amsterdam:
return engine.PayloadV4
case forks.BPO5, forks.BPO4, forks.BPO3, forks.BPO2, forks.BPO1, forks.Osaka, forks.Prague, forks.Cancun:
return engine.PayloadV3
case forks.Paris, forks.Shanghai:
Expand All @@ -111,6 +113,21 @@ func payloadVersion(config *params.ChainConfig, time uint64) engine.PayloadVersi
panic("invalid fork, simulated beacon needs to be started post-merge")
}

func payloadAttributes(version engine.PayloadVersion, timestamp uint64, feeRecipient common.Address, withdrawals []*types.Withdrawal, random [32]byte) *engine.PayloadAttributes {
attributes := &engine.PayloadAttributes{
Timestamp: timestamp,
SuggestedFeeRecipient: feeRecipient,
Withdrawals: withdrawals,
Random: random,
BeaconRoot: &common.Hash{},
}
if version == engine.PayloadV4 {
slotNumber := uint64(0)
attributes.SlotNumber = &slotNumber
}
return attributes
}

// NewSimulatedBeacon constructs a new simulated beacon chain.
func NewSimulatedBeacon(period uint64, feeRecipient common.Address, eth *eth.Ethereum) (*SimulatedBeacon, error) {
block := eth.BlockChain().CurrentBlock()
Expand Down Expand Up @@ -198,13 +215,7 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u

var random [32]byte
rand.Read(random[:])
fcResponse, err := c.engineAPI.forkchoiceUpdated(c.curForkchoiceState, &engine.PayloadAttributes{
Timestamp: timestamp,
SuggestedFeeRecipient: feeRecipient,
Withdrawals: withdrawals,
Random: random,
BeaconRoot: &common.Hash{},
}, version, false)
fcResponse, err := c.engineAPI.forkchoiceUpdated(c.curForkchoiceState, payloadAttributes(version, timestamp, feeRecipient, withdrawals, random), version, false)
if err != nil {
return err
}
Expand Down
20 changes: 20 additions & 0 deletions eth/catalyst/simulated_beacon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -70,6 +71,25 @@ func startSimulatedBeaconEthService(t *testing.T, genesis *core.Genesis, period
return n, ethservice, simBeacon
}

func TestPayloadVersionAmsterdam(t *testing.T) {
amsterdamTime := uint64(1)
cfg := &params.ChainConfig{
LondonBlock: big.NewInt(0),
AmsterdamTime: &amsterdamTime,
}
if got := payloadVersion(cfg, amsterdamTime); got != engine.PayloadV4 {
t.Fatalf("unexpected payload version: have %v want %v", got, engine.PayloadV4)
}
}

func TestPayloadAttributesAmsterdamSlotNumber(t *testing.T) {
var random [32]byte
attrs := payloadAttributes(engine.PayloadV4, 1, common.Address{}, nil, random)
if attrs.SlotNumber == nil {
t.Fatal("missing slot number for payload v4")
}
}

// send 20 transactions, >10 withdrawals and ensure they are included in order
// send enough transactions to fill multiple blocks
func TestSimulatedBeaconSendWithdrawals(t *testing.T) {
Expand Down