Skip to content

perf(full trace): Use on_block_build_start hook instead of on_fork_choice_updated#106

Closed
JimmyShi22 wants to merge 1 commit intodevfrom
jimmyshi/fcu-hook-instread
Closed

perf(full trace): Use on_block_build_start hook instead of on_fork_choice_updated#106
JimmyShi22 wants to merge 1 commit intodevfrom
jimmyshi/fcu-hook-instread

Conversation

@JimmyShi22
Copy link
Contributor

This pull request refactors the block tracing logic in engine_api_tracer.rs and tracer.rs to improve clarity and accuracy when tracking block build events. The main change is to trigger the tracer only when a new block is being built (i.e., when payload attributes are present), and to pass the new block number to the tracer. The tracer interface is updated to reflect this change, and supporting code is added to query the block number from the provider. Additionally, some type and field adjustments were made for better code organization.

Tracing logic improvements

  • The tracer is now called only when a new block is being built (when payload attributes are present), and the block number is passed to the tracer using the new on_block_build_start method instead of the previous on_fork_choice_updated method. This change is applied for fork choice updates v1, v2, and v3. [1] [2] [3] [4]
  • Added a helper method query_new_block_number to query the block number from the provider, which is used to determine the new block number for tracing.

API and interface changes

  • The Tracer struct and its method were updated: removed the fork choice state and payload attributes arguments from the tracing method, and replaced them with the new block number.
  • The EngineApiTracer struct now stores an optional provider for querying block information, with a setter method and updated phantom data usage. [1] [2] [3]

Miscellaneous

  • Added warn to the tracing imports to log warnings when block information cannot be queried.
  • Cleaned up unused imports in tracer.rs.

@JimmyShi22 JimmyShi22 marked this pull request as ready for review January 21, 2026 09:09
/// The inner OpEngineApi (set during build)
inner: Option<InnerOpEngineApi<Provider, EngineT, Pool, Validator, ChainSpec>>,
/// The provider to query block information
provider: Option<Provider>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR should wait for the PR #107 to be inside, and then explicitly pass the provider reference inside the engine api. We should not have the option type here, and on compile time deterministically build the engine api with the provider inside the XLayerEngineApiBuilder

info!(target: "xlayer::engine", "XLayer Engine API initialized with tracer middleware");

// Store the provider for querying block information
self.set_provider(ctx.node.provider().clone());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already going to set the provider on start up so no need for an option

{
/// Query the new block number for a fork choice update with payload attributes.
/// Returns None if provider is not set or if the head block cannot be found.
fn query_new_block_number(&self, head_block_hash: B256) -> Option<u64>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to make this function fallible

@JimmyShi22 JimmyShi22 closed this Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants