Skip to content

Commit d5cdc5c

Browse files
committed
refactor engine api call ordering
1 parent 069028e commit d5cdc5c

File tree

7 files changed

+22
-12
lines changed

7 files changed

+22
-12
lines changed

bin/bridge/src/import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl BridgeBlockImport {
4646
.and_then(|i| Signature::from_compact(&extra_data[i..]).ok())
4747
{
4848
let block = block.block.clone();
49-
trace!(target: "scroll::bridge::import", peer_id = %peer_id, block = ?block, "Received new block from eth-wire protocol");
49+
trace!(target: "scroll::bridge::import", peer_id = %peer_id, block = ?block.hash_slow(), "Received new block from eth-wire protocol");
5050

5151
// We trigger a new block event to be sent to the rollup node's network manager. If this
5252
// results in an error it means the network manager has been dropped.

crates/engine/src/engine.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,17 @@ where
7272
pub async fn handle_execution_payload(
7373
&self,
7474
execution_payload: ExecutionPayload,
75-
mut fcs: ForkchoiceState,
75+
fcs: ForkchoiceState,
7676
) -> Result<(PayloadStatusEnum, PayloadStatusEnum), EngineDriverError> {
7777
// Convert the payload to the V1 format.
7878
let execution_payload = execution_payload.into_v1();
7979

80-
// update the fork choice state with the new block hash.
81-
fcs.head_block_hash = execution_payload.block_num_hash().hash;
80+
// Invoke the FCU with the new state.
81+
let fcu = self.forkchoice_updated(fcs, None).await?;
8282

8383
// Issue the new payload to the EN.
8484
let payload_status = self.new_payload(execution_payload).await?;
8585

86-
// Invoke the FCU with the new state.
87-
let fcu = self.forkchoice_updated(fcs, None).await?;
88-
8986
// We should never have a case where the fork choice is syncing as we have already validated
9087
// the payload and provided it to the EN.
9188
debug_assert!(fcu.is_valid());

crates/engine/src/fcs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,9 @@ impl ForkchoiceState {
6969
finalized_block_hash: self.finalized.hash,
7070
}
7171
}
72+
73+
/// Returns `true` if the fork choice state is the genesis state.
74+
pub fn is_genesis(&self) -> bool {
75+
self.unsafe_.number == 0
76+
}
7277
}

crates/network/src/manager.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl NetworkManager {
124124
fn on_scroll_wire_event(&mut self, event: ScrollWireEvent) -> Option<NetworkManagerEvent> {
125125
match event {
126126
ScrollWireEvent::NewBlock { peer_id, block, signature } => {
127-
trace!(target: "scroll::network::manager", peer_id = ?peer_id, block = ?block, signature = ?signature, "Received new block");
127+
trace!(target: "scroll::network::manager", peer_id = ?peer_id, block = ?block.hash_slow(), signature = ?signature, "Received new block");
128128
Some(NetworkManagerEvent::NewBlock(NewBlockWithPeer { peer_id, block, signature }))
129129
}
130130
// Only `NewBlock` events are expected from the scroll-wire protocol.
@@ -191,8 +191,6 @@ impl Future for NetworkManager {
191191
self: std::pin::Pin<&mut Self>,
192192
cx: &mut std::task::Context<'_>,
193193
) -> std::task::Poll<Self::Output> {
194-
trace!(target: "scroll::network::manager", "Polling network manager");
195-
196194
let this = self.get_mut();
197195

198196
// We handle the messages from the network handle.

crates/node/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ where
131131
return;
132132
}
133133

134+
// If the forkchoice state is at genesis, update the forkchoice state with the parent of the
135+
// block.
136+
if self.forkchoice_state.is_genesis() {
137+
let parent = block.parent_num_hash();
138+
self.forkchoice_state.update_unsafe_block_info(BlockInfo {
139+
number: parent.number,
140+
hash: block.parent_hash,
141+
});
142+
}
143+
134144
// Send the block to the engine to validate the correctness of the block.
135145
let fcs = self.get_alloy_fcs();
136146
let engine = self.engine.clone();

crates/scroll-wire/src/connection/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl Stream for ScrollWireConnection {
8181
match msg.payload {
8282
ScrollMessagePayload::NewBlock(new_block) => {
8383
// If the signature can be decoded then we send a new block event.
84-
trace!(target: "scroll::wire::connection", peer_id = %this.peer_id, block = ?new_block.block, "Received new block from peer");
84+
trace!(target: "scroll::wire::connection", peer_id = %this.peer_id, block = ?new_block.block.hash_slow(), "Received new block from peer");
8585
if let Ok(signature) = Signature::from_compact(&new_block.signature[..]) {
8686
this.events
8787
.send(ScrollWireEvent::NewBlock {

crates/scroll-wire/src/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Future for ScrollWireManager {
7777
match new_block {
7878
Some(ScrollWireEvent::NewBlock { peer_id, block, signature }) => {
7979
// We announce the block to the network.
80-
trace!("Received new block with signature [{signature:?}] from the network: {block:?} ");
80+
trace!(target: "scroll::wire::manager", "Received new block with signature [{signature:?}] from the network: {:?} ", block.hash_slow());
8181
return Poll::Ready(ScrollWireEvent::NewBlock { peer_id, block, signature });
8282
}
8383
Some(ScrollWireEvent::ConnectionEstablished {

0 commit comments

Comments
 (0)