From 854242ee167e6a6ce536d090b091d1de0a1bd4c6 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Fri, 10 May 2024 12:25:00 +0200 Subject: [PATCH 1/2] eth/catalyst: core: add changes for prague dev mode --- core/types/block.go | 3 ++- eth/catalyst/api.go | 4 ++-- eth/catalyst/simulated_beacon.go | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/types/block.go b/core/types/block.go index 7c70bd0f700a..f6947efedc6f 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -365,7 +365,8 @@ func (b *Block) Withdrawals() Withdrawals { return b.withdrawals } func (b *Block) Requests() Requests { return b.requests } func (b *Block) Deposits() Deposits { - var deps Deposits + // need to make here, otherwise Deposits will return nil instead of empty slice + deps := make(Deposits, 0) for _, r := range b.requests { if d, ok := r.inner.(*Deposit); ok { deps = append(deps, d) diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go index 62c6e5e6d95f..0a674ba27b71 100644 --- a/eth/catalyst/api.go +++ b/eth/catalyst/api.go @@ -553,8 +553,8 @@ func (api *ConsensusAPI) NewPayloadV4(params engine.ExecutableData, versionedHas return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("nil beaconRoot post-cancun")) } - if api.eth.BlockChain().Config().LatestFork(params.Timestamp) != forks.Cancun { - return engine.PayloadStatusV1{Status: engine.INVALID}, engine.UnsupportedFork.With(errors.New("newPayloadV3 must only be called for cancun payloads")) + if api.eth.BlockChain().Config().LatestFork(params.Timestamp) != forks.Prague { + return engine.PayloadStatusV1{Status: engine.INVALID}, engine.UnsupportedFork.With(errors.New("newPayloadV4 must only be called for prague payloads")) } return api.newPayload(params, versionedHashes, beaconRoot) } diff --git a/eth/catalyst/simulated_beacon.go b/eth/catalyst/simulated_beacon.go index fecd83f2762c..77aeba336af4 100644 --- a/eth/catalyst/simulated_beacon.go +++ b/eth/catalyst/simulated_beacon.go @@ -101,7 +101,7 @@ func NewSimulatedBeacon(period uint64, eth *eth.Ethereum) (*SimulatedBeacon, err // if genesis block, send forkchoiceUpdated to trigger transition to PoS if block.Number.Sign() == 0 { - if _, err := engineAPI.ForkchoiceUpdatedV2(current, nil); err != nil { + if _, err := engineAPI.ForkchoiceUpdatedV3(current, nil); err != nil { return nil, err } } @@ -202,13 +202,13 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u } } // Mark the payload as canon - if _, err = c.engineAPI.NewPayloadV3(*payload, blobHashes, &common.Hash{}); err != nil { + if _, err = c.engineAPI.NewPayloadV4(*payload, blobHashes, &common.Hash{}); err != nil { return err } c.setCurrentState(payload.BlockHash, finalizedHash) // Mark the block containing the payload as canonical - if _, err = c.engineAPI.ForkchoiceUpdatedV2(c.curForkchoiceState, nil); err != nil { + if _, err = c.engineAPI.ForkchoiceUpdatedV3(c.curForkchoiceState, nil); err != nil { return err } c.lastBlockTime = payload.Timestamp From dcdb0f3afd97b37a017be34fb1d6edf926ddc551 Mon Sep 17 00:00:00 2001 From: lightclient Date: Mon, 13 May 2024 09:31:58 +0300 Subject: [PATCH 2/2] core/types: return nil only if overall requests is nil --- core/types/block.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/types/block.go b/core/types/block.go index f6947efedc6f..bb9d547c75f4 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -365,8 +365,12 @@ func (b *Block) Withdrawals() Withdrawals { return b.withdrawals } func (b *Block) Requests() Requests { return b.requests } func (b *Block) Deposits() Deposits { - // need to make here, otherwise Deposits will return nil instead of empty slice - deps := make(Deposits, 0) + var deps Deposits + if b.requests != nil { + // If requests is non-nil, it means deposits are available in block and we + // should return an empty slice instead of nil if there are no deposits. + deps = make(Deposits, 0) + } for _, r := range b.requests { if d, ok := r.inner.(*Deposit); ok { deps = append(deps, d) @@ -376,6 +380,11 @@ func (b *Block) Deposits() Deposits { } func (b *Block) WithdrawalRequests() WithdrawalRequests { var wxs WithdrawalRequests + if b.requests != nil { + // If requests is non-nil, it means wx requests are available in block and + // we should return an empty slice instead of nil if there are no wxs. + wxs = make(WithdrawalRequests, 0) + } for _, r := range b.requests { if w, ok := r.inner.(*WithdrawalRequest); ok { wxs = append(wxs, w)