Skip to content

Commit 2f43dfd

Browse files
committed
refactor(engine): *IMPORTANT* streamline payload submission and forkchoice updates
- Simplified the process of submitting new payloads to the execution layer by removing the redundant forkchoice update to the parent block. - Enhanced error logging to include block numbers for better traceability during payload submission and forkchoice updates. - Updated debug messages to provide clearer context regarding the block number during operations.
1 parent 192fa46 commit 2f43dfd

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

app/src/engine.rs

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -189,51 +189,36 @@ impl Engine {
189189
block_number, parent_hash, finalized
190190
);
191191

192-
// Update forkchoice to parent before submitting new payload
193-
// This ensures the execution client knows about the parent block
194-
self.api
195-
.forkchoice_updated(
196-
ForkchoiceState {
197-
head_block_hash: parent_hash,
198-
safe_block_hash: finalized,
199-
finalized_block_hash: finalized,
200-
},
201-
None,
202-
)
203-
.await
204-
.map_err(|err| {
205-
ENGINE_COMMIT_BLOCK_CALLS
206-
.with_label_values(&["engine_api_forkchoice_parent_error"])
207-
.inc();
208-
Error::EngineApiError(format!(
209-
"Failed to update forkchoice to parent (block={}, parent={:?}): {:?}",
210-
block_number, parent_hash, err
211-
))
212-
})?;
213-
214-
// we need to push the payload back to geth
192+
// Submit new payload directly to execution layer
193+
// The parent is already known from build_block's forkchoice_updated call
215194
// https://github.com/ethereum/go-ethereum/blob/577be37e0e7a69564224e0a15e49d648ed461ac5/eth/catalyst/api.go#L259
216195
let response = self
217196
.api
218-
.new_payload::<MainnetEthSpec>(execution_payload)
197+
.new_payload::<MainnetEthSpec>(execution_payload.clone())
219198
.await
220199
.map_err(|err| {
221200
ENGINE_COMMIT_BLOCK_CALLS
222201
.with_label_values(&["engine_api_new_payload_error"])
223202
.inc();
224-
Error::EngineApiError(format!("{:?}", err))
203+
Error::EngineApiError(format!(
204+
"Failed to submit new payload (block={}, parent={:?}): {:?}",
205+
block_number, parent_hash, err
206+
))
225207
})?;
208+
226209
let head = response.latest_valid_hash.ok_or_else(|| {
227210
ENGINE_COMMIT_BLOCK_CALLS
228211
.with_label_values(&["engine_api_invalid_block_hash_error"])
229212
.inc();
230213
Error::InvalidBlockHash
231214
})?;
232215

233-
debug!("New payload accepted, head={:?}", head);
216+
debug!(
217+
"New payload accepted, head={:?}, block_number={}",
218+
head, block_number
219+
);
234220

235-
// update now to the new head so we can fetch the txs and
236-
// receipts from the ethereum rpc
221+
// Update forkchoice to the new block as the canonical head
237222
self.api
238223
.forkchoice_updated(
239224
ForkchoiceState {
@@ -249,12 +234,15 @@ impl Engine {
249234
.with_label_values(&["engine_api_forkchoice_head_error"])
250235
.inc();
251236
Error::EngineApiError(format!(
252-
"Failed to update forkchoice to new head (head={:?}): {:?}",
253-
head, err
237+
"Failed to update forkchoice to new head (block={}, head={:?}): {:?}",
238+
block_number, head, err
254239
))
255240
})?;
256241

257-
debug!("Forkchoice updated to new head successfully");
242+
debug!(
243+
"Forkchoice updated to new head successfully, block_number={}",
244+
block_number
245+
);
258246

259247
ENGINE_COMMIT_BLOCK_CALLS
260248
.with_label_values(&["success"])

0 commit comments

Comments
 (0)