Skip to content

Commit

Permalink
Merge pull request ethereum#46 from MariusVanDerWijden/prague-payload…
Browse files Browse the repository at this point in the history
…-fix

eth/catalyst: fix deposit requests
  • Loading branch information
MariusVanDerWijden authored May 14, 2024
2 parents ce8886c + 704d0f2 commit d0d5d53
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 36 deletions.
80 changes: 46 additions & 34 deletions beacon/engine/gen_ed.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,12 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash,
requests types.Requests
)
if params.Deposits != nil {
requests = make(types.Requests, 0)
requests = append(requests, params.Deposits.Requests()...)
}
if params.WithdrawalRequests != nil {
// We assume that withdrawal reqs are non-nil only if deposits are non-nil
// (both can be empty)
requests = append(requests, params.WithdrawalRequests.Requests()...)
}
if requests != nil {
Expand Down
6 changes: 5 additions & 1 deletion eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV3(update engine.ForkchoiceStateV1, pa
// hash, even if params are wrong. To do this we need to split up
// forkchoiceUpdate into a function that only updates the head and then a
// function that kicks off block construction.
return api.forkchoiceUpdated(update, params, engine.PayloadV3, false)
payloadVersion := engine.PayloadV3
if params != nil && api.eth.BlockChain().Config().LatestFork(params.Timestamp) == forks.Prague {
payloadVersion = engine.PayloadV4
}
return api.forkchoiceUpdated(update, params, payloadVersion, false)
}

func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes, payloadVersion engine.PayloadVersion, simulatorMode bool) (engine.ForkChoiceResponse, error) {
Expand Down
2 changes: 1 addition & 1 deletion eth/catalyst/simulated_beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
Withdrawals: withdrawals,
Random: random,
BeaconRoot: &common.Hash{},
}, engine.PayloadV3, true)
}, engine.PayloadV4, true)
if err != nil {
return err
}
Expand Down
19 changes: 19 additions & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,26 @@ func (miner *Miner) generateWork(params *generateParams) *newPayloadResult {
log.Warn("Block building is interrupted", "allowance", common.PrettyDuration(miner.config.Recommit))
}
}

body := types.Body{Transactions: work.txs, Withdrawals: params.withdrawals}
allLogs := make([]*types.Log, 0)
for _, r := range work.receipts {
allLogs = append(allLogs, r.Logs...)
}
// Read requests if Prague is enabled.
if miner.chainConfig.IsPrague(work.header.Number, work.header.Time) {
requests := make(types.Requests, 0)
reqs, err := core.ParseDepositLogs(allLogs)
if err != nil {
return &newPayloadResult{err: err}
}
requests = append(requests, reqs...)
context := core.NewEVMBlockContext(work.header, miner.chain, nil)
vmenv := vm.NewEVM(context, vm.TxContext{}, work.state, miner.chainConfig, vm.Config{})
wxs := core.ProcessDequeueWithdrawalRequests(vmenv, work.state)
requests = append(requests, wxs...)
body.Requests = requests
}
block, err := miner.engine.FinalizeAndAssemble(miner.chain, work.header, work.state, &body, work.receipts)
if err != nil {
return &newPayloadResult{err: err}
Expand Down

0 comments on commit d0d5d53

Please sign in to comment.