fix: Remove engine api, add monitor handle and refactor full link monitor logic#107
fix: Remove engine api, add monitor handle and refactor full link monitor logic#107
Conversation
crates/monitor/src/payload.rs
Outdated
| let provider = self.provider; | ||
|
|
||
| // Listen to both Attributes and BuiltPayload events in a single task | ||
| task_executor.spawn_critical( |
There was a problem hiding this comment.
I think we should reduce the number of tasks being spawned for the monitor logic, into just a single task
bin/node/src/add_ons.rs
Outdated
| async fn launch_add_ons(self, ctx: AddOnsContext<'_, N>) -> eyre::Result<Self::Handle> { | ||
| // Initialize consensus engine events listener to track block received and canonical chain events | ||
| let consensus_listener = ConsensusListener::new(self.monitor.clone()); | ||
| consensus_listener.listen(ctx.engine_events.new_listener(), ctx.node.task_executor()); |
There was a problem hiding this comment.
Dont think we should spawn another worker task here, now we are essentially running 2 tasks for not much reason (engine and payload listeners).
Also, running the task here doesnt make sense since this is nested inside an add on wrapper struct? This logic doesnt quite fit launch_add_ons functionality and i suggest we completely do away with this design. we should put this instantiation of a single monitor handle task, that uses tokio runtime to async await both from the engine event and payload receivers.
bin/node/src/add_ons.rs
Outdated
There was a problem hiding this comment.
I dont really see a point in creating a custom struct for this. We just need the engine event receiver? Why create another nested level of custom add on definition here
There was a problem hiding this comment.
We do not need to create a custom XLayerAddOns to retrieve the engine_event by wrapping the launch_add_ons. A more elegant solution is resolved in 3ea6d22, where we can obtain the engine event listener after the node is contructed inside the NodeHandle.add_ons_handle
crates/monitor/src/monitor.rs
Outdated
|
|
||
| /// Handle transaction commits to the canonical chain. | ||
| pub fn on_tx_commit(&self, _block_info: &BlockInfo, _tx_hash: B256) { | ||
| info!(target: "xlayer::monitor", "monitor: Transaction committed to canonical chain"); |
There was a problem hiding this comment.
Do not spam the node with so much info level loggings. Setting the target to xlayer::monitor is sufficient, and we should set these to debug level.
crates/monitor/src/monitor.rs
Outdated
| /// Handle block building start event (when payload attributes are received). | ||
| /// This is triggered when forkchoiceUpdated contains payload attributes. | ||
| pub fn on_block_build_start(&self, block_number: u64) { | ||
| info!(target: "xlayer::monitor", block_number, "monitor: Block building started"); |
crates/monitor/src/payload.rs
Outdated
| if let Ok(payload_events) = payload_builder.subscribe().await { | ||
| // Use built_payload_stream to get accurate block numbers | ||
| let mut built_payload_stream = payload_events.into_built_payload_stream(); | ||
| info!(target: "xlayer::monitor", "monitor: Payload events listener started"); |
There was a problem hiding this comment.
Same here. Is there a need to even log this out also actually? Lets change all of these to debug level.
crates/monitor/src/consensus.rs
Outdated
| task_executor.spawn_critical( | ||
| "xlayer-monitor-consensus-events", | ||
| Box::pin(async move { | ||
| info!(target: "xlayer::monitor", "monitor: Consensus engine events listener started"); |
There was a problem hiding this comment.
Note that you dont need to prefix your logs with a monitor: since we already set the target to xlayer::monitor. thats what the rust log targets help us with, together with allowing us to specify log target levels when running.
crates/monitor/src/payload.rs
Outdated
| Ok(None) => { | ||
| warn!( | ||
| target: "xlayer::monitor", | ||
| payload_id = %payload_id, | ||
| parent_hash = %parent_hash, | ||
| "monitor: Parent block not found for payload attributes" | ||
| ); | ||
| } | ||
| Err(e) => { | ||
| warn!( | ||
| target: "xlayer::monitor", | ||
| payload_id = %payload_id, | ||
| parent_hash = %parent_hash, | ||
| error = %e, | ||
| "monitor: Failed to get parent block number" | ||
| ); |
There was a problem hiding this comment.
Both are handled as logging, we can simply handle the match arm with _ =>
There was a problem hiding this comment.
In addition I dont think we should spam the node logs here if somehow there is a state provider failure. We should set this to debug level - since if the parent hash cant be found, the engine state tree itself will already report error logs already.
crates/monitor/src/payload.rs
Outdated
| // Call on_block_build_start with the block number | ||
| monitor.on_block_build_start(block_number); | ||
|
|
||
| info!( |
There was a problem hiding this comment.
Why need to log again when monitor.on_block_build_start already adds a log?
crates/monitor/src/payload.rs
Outdated
| // Call on_block_send_start with the accurate block number | ||
| monitor.on_block_send_start(block_number); | ||
|
|
||
| info!( |
There was a problem hiding this comment.
Same for this? on_block_send_start already adds a log?
20c3e69 to
3ea6d22
Compare
crates/monitor/src/monitor.rs
Outdated
| pub struct BlockInfo { | ||
| /// The block number | ||
| pub block_number: u64, | ||
| /// The block hash | ||
| pub block_hash: B256, | ||
| } |
There was a problem hiding this comment.
Use alloy NumHash instead
crates/monitor/src/rpc.rs
Outdated
| trace!( | ||
| target: "xlayer::monitor::rpc", | ||
| "Transaction submission intercepted: method={}", | ||
| method_owned | ||
| ); |
There was a problem hiding this comment.
trace log for transaction interception on the RPC layer is shifted inside the async task
|
lgtm, I see these improvements:
|
* dev: fix: remove engine api, and simplify monitor logic (#107)
* upgrade to v1.10.0 (#98) * perf(builder): use XLayerPayloadServiceBuilder to simplify main codes (#95) Co-authored-by: Vui-Chee <vuicheesiew@gmail.com> Co-authored-by: Niven <sieniven@gmail.com> * drop unused dep * chore: better rename, fix unused variable warning (#99) * Better refactor, fix unused var warn * Better rename * Remove xlayer suffix * Align cargo chef base image with latest rust toolchain version (#100) * Update builder version (#101) * feat(full trace): Add full trace hook framework (#103) * add engine api hook for full trace * rm comment * fix clippy * add send tx hook * add blockchain tracer * cargo lock * fix review issues * simplify to tracer to avoid nasty type bonanza * renamed `TracerConfig` to `Tracer` * more renames * EngineApiTracer derive clone over manual impl * handle middleware overwrite problem * reorder * drop clone * no box on middleware rpc tracer * impl `EngineApiBuilder` directly to tracer --------- Co-authored-by: Vui-Chee <vuicheesiew@gmail.com> * fix: remove engine api, and simplify monitor logic (#107) * remove unused reth-node-api (#108) * fix: resolve audit issues related to flashblocks subscription (#113) * Fix unnecessary clone * Fix incomplete documentation of subscribe addrs filter * Better desc * chore(flashblocks): update builder version to v0.2.5 (#114) * Update builder version to v0.2.5 with full link monitor updates * Fix wspub init * feat: Add Transaction Trace Monitoring Support (#115) * add trace logic * optimize * fix ut * fix ut * fix * fix * optimize code * optimize code * fix * chore: fix rust formatter (#132) * Fix fmt * Remove unused dep * Fix nested if else clippy check * Update dependencies, use reth v1.10.2 and builder v0.3.0 (#133) * fix: upgrade reth v1.10.2 version with bug fixes (#134) * Fix revm dep * Update reth version, use merge fixes version * Add audit report (#135) * add audit report * add audit report --------- Co-authored-by: chunsheng.wang <chunsheng.wang@okg.com> * feat: add flashblocks enabled RPC method (#136) * feat: add flashblocks enabled RPC method * chore: clippy * chore: add unit tests * chore: reword documentation * remove min gas rpc (#138) --------- Co-authored-by: jimmyshi <417711026@qq.com> Co-authored-by: Niven <sieniven@gmail.com> Co-authored-by: Leo <335209779@qq.com> Co-authored-by: wangchunsheng-ops <13614269216@163.com> Co-authored-by: chunsheng.wang <chunsheng.wang@okg.com> Co-authored-by: lucas <66681646+limyeechern@users.noreply.github.com>
* upgrade to v1.10.0 (#98) * perf(builder): use XLayerPayloadServiceBuilder to simplify main codes (#95) Co-authored-by: Vui-Chee <vuicheesiew@gmail.com> Co-authored-by: Niven <sieniven@gmail.com> * drop unused dep * chore: better rename, fix unused variable warning (#99) * Better refactor, fix unused var warn * Better rename * Remove xlayer suffix * Align cargo chef base image with latest rust toolchain version (#100) * Update builder version (#101) * feat(full trace): Add full trace hook framework (#103) * add engine api hook for full trace * rm comment * fix clippy * add send tx hook * add blockchain tracer * cargo lock * fix review issues * simplify to tracer to avoid nasty type bonanza * renamed `TracerConfig` to `Tracer` * more renames * EngineApiTracer derive clone over manual impl * handle middleware overwrite problem * reorder * drop clone * no box on middleware rpc tracer * impl `EngineApiBuilder` directly to tracer --------- Co-authored-by: Vui-Chee <vuicheesiew@gmail.com> * fix: remove engine api, and simplify monitor logic (#107) * remove unused reth-node-api (#108) * fix: resolve audit issues related to flashblocks subscription (#113) * Fix unnecessary clone * Fix incomplete documentation of subscribe addrs filter * Better desc * chore(flashblocks): update builder version to v0.2.5 (#114) * Update builder version to v0.2.5 with full link monitor updates * Fix wspub init * feat: Add Transaction Trace Monitoring Support (#115) * add trace logic * optimize * fix ut * fix ut * fix * fix * optimize code * optimize code * fix * chore: fix rust formatter (#132) * Fix fmt * Remove unused dep * Fix nested if else clippy check * Update dependencies, use reth v1.10.2 and builder v0.3.0 (#133) * fix: upgrade reth v1.10.2 version with bug fixes (#134) * Fix revm dep * Update reth version, use merge fixes version * Add audit report (#135) * add audit report * add audit report --------- Co-authored-by: chunsheng.wang <chunsheng.wang@okg.com> * feat: add flashblocks enabled RPC method (#136) * feat: add flashblocks enabled RPC method * chore: clippy * chore: add unit tests * chore: reword documentation * remove min gas rpc (#138) --------- Co-authored-by: jimmyshi <417711026@qq.com> Co-authored-by: Niven <sieniven@gmail.com> Co-authored-by: Leo <335209779@qq.com> Co-authored-by: wangchunsheng-ops <13614269216@163.com> Co-authored-by: chunsheng.wang <chunsheng.wang@okg.com> Co-authored-by: lucas <66681646+limyeechern@users.noreply.github.com>
Summary
This PR refactors and resolves the issues mentioned in PR #103.