Skip to content

Commit 9bd1d36

Browse files
committed
beacon/engine, eth/catalyst, miner: add engine_forkchoiceUpdatedV4
1 parent 996cf5c commit 9bd1d36

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

beacon/engine/gen_blockparams.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beacon/engine/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var (
3636
PayloadV1 PayloadVersion = 0x1
3737
PayloadV2 PayloadVersion = 0x2
3838
PayloadV3 PayloadVersion = 0x3
39+
PayloadV4 PayloadVersion = 0x4
3940
)
4041

4142
//go:generate go run github.com/fjl/gencodec -type PayloadAttributes -field-override payloadAttributesMarshaling -out gen_blockparams.go
@@ -48,6 +49,7 @@ type PayloadAttributes struct {
4849
SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient" gencodec:"required"`
4950
Withdrawals []*types.Withdrawal `json:"withdrawals"`
5051
BeaconRoot *common.Hash `json:"parentBeaconBlockRoot"`
52+
InclusionList types.InclusionList `json:"inclusionListTransactions"`
5153
}
5254

5355
// JSON type overrides for PayloadAttributes.

eth/catalyst/api.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ var caps = []string{
8787
"engine_forkchoiceUpdatedV1",
8888
"engine_forkchoiceUpdatedV2",
8989
"engine_forkchoiceUpdatedV3",
90+
"engine_forkchoiceUpdatedV4",
9091
"engine_forkchoiceUpdatedWithWitnessV1",
9192
"engine_forkchoiceUpdatedWithWitnessV2",
9293
"engine_forkchoiceUpdatedWithWitnessV3",
@@ -252,7 +253,7 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV3(update engine.ForkchoiceStateV1, pa
252253
return engine.STATUS_INVALID, attributesErr("missing withdrawals")
253254
case params.BeaconRoot == nil:
254255
return engine.STATUS_INVALID, attributesErr("missing beacon root")
255-
case !api.checkFork(params.Timestamp, forks.Cancun, forks.Prague, forks.Osaka, forks.Eip7805):
256+
case !api.checkFork(params.Timestamp, forks.Cancun, forks.Prague, forks.Osaka):
256257
return engine.STATUS_INVALID, unsupportedForkErr("fcuV3 must only be called for cancun or prague payloads")
257258
}
258259
}
@@ -263,6 +264,22 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV3(update engine.ForkchoiceStateV1, pa
263264
return api.forkchoiceUpdated(update, params, engine.PayloadV3, false)
264265
}
265266

267+
// ForkchoiceUpdatedV4 is equivalent to V3 with the addition of inclusion list
268+
// in the payload attributes. It supports only PayloadAttributesV4.
269+
func (api *ConsensusAPI) ForkchoiceUpdatedV4(update engine.ForkchoiceStateV1, params *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) {
270+
if params != nil {
271+
switch {
272+
case params.Withdrawals == nil:
273+
return engine.STATUS_INVALID, attributesErr("missing withdrawals")
274+
case params.BeaconRoot == nil:
275+
return engine.STATUS_INVALID, attributesErr("missing beacon root")
276+
case !api.checkFork(params.Timestamp, forks.Eip7805):
277+
return engine.STATUS_INVALID, unsupportedForkErr("fcuV4 must only be called for eip7805 payloads")
278+
}
279+
}
280+
return api.forkchoiceUpdated(update, params, engine.PayloadV4, false)
281+
}
282+
266283
func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes, payloadVersion engine.PayloadVersion, payloadWitness bool) (engine.ForkChoiceResponse, error) {
267284
api.forkchoiceLock.Lock()
268285
defer api.forkchoiceLock.Unlock()
@@ -390,18 +407,20 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl
390407
// will replace it arbitrarily many times in between.
391408
if payloadAttributes != nil {
392409
args := &miner.BuildPayloadArgs{
393-
Parent: update.HeadBlockHash,
394-
Timestamp: payloadAttributes.Timestamp,
395-
FeeRecipient: payloadAttributes.SuggestedFeeRecipient,
396-
Random: payloadAttributes.Random,
397-
Withdrawals: payloadAttributes.Withdrawals,
398-
BeaconRoot: payloadAttributes.BeaconRoot,
399-
Version: payloadVersion,
410+
Parent: update.HeadBlockHash,
411+
Timestamp: payloadAttributes.Timestamp,
412+
FeeRecipient: payloadAttributes.SuggestedFeeRecipient,
413+
Random: payloadAttributes.Random,
414+
Withdrawals: payloadAttributes.Withdrawals,
415+
BeaconRoot: payloadAttributes.BeaconRoot,
416+
InclusionList: payloadAttributes.InclusionList,
417+
Version: payloadVersion,
400418
}
401419
id := args.Id()
402420
// If we already are busy generating this work, then we do not need
403421
// to start a second process.
404-
if api.localBlocks.has(id) {
422+
if payload := api.localBlocks.peek(id); payload != nil {
423+
payload.UpdateInclusionList(payloadAttributes.InclusionList)
405424
return valid(&id), nil
406425
}
407426
payload, err := api.eth.Miner().BuildPayload(args, payloadWitness)

eth/catalyst/simulated_beacon.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
200200
Withdrawals: withdrawals,
201201
Random: random,
202202
BeaconRoot: &common.Hash{},
203+
InclusionList: types.InclusionList{},
203204
}, version, false)
204205
if err != nil {
205206
return err

0 commit comments

Comments
 (0)