1
1
use clap:: Parser ;
2
+ use eyre:: Result ;
2
3
use monitoring:: Monitoring ;
3
4
use reth:: providers:: CanonStateSubscriptions ;
4
5
use reth_optimism_cli:: { chainspec:: OpChainSpecParser , Cli } ;
@@ -24,59 +25,72 @@ pub mod payload_builder;
24
25
#[ cfg( not( feature = "flashblocks" ) ) ]
25
26
mod payload_builder_vanilla;
26
27
mod primitives;
28
+ #[ cfg( feature = "telemetry" ) ]
29
+ mod telemetry;
27
30
#[ cfg( test) ]
28
31
mod tester;
29
32
mod tx_signer;
30
33
use monitor_tx_pool:: monitor_tx_pool;
31
34
32
- fn main ( ) {
33
- Cli :: < OpChainSpecParser , args:: OpRbuilderArgs > :: parse ( )
34
- . run ( |builder, builder_args| async move {
35
- let rollup_args = builder_args. rollup_args ;
35
+ fn main ( ) -> Result < ( ) > {
36
+ let cli = Cli :: < OpChainSpecParser , args:: OpRbuilderArgs > :: parse ( ) ;
37
+ cli. run ( |builder, builder_args| async move {
38
+ #[ cfg( feature = "telemetry" ) ]
39
+ let mut provider = telemetry:: TelemetryControl :: init ( & builder_args) ?;
36
40
37
- let op_node = OpNode :: new ( rollup_args. clone ( ) ) ;
38
- let handle = builder
39
- . with_types :: < OpNode > ( )
40
- . with_components ( op_node. components ( ) . payload ( CustomOpPayloadBuilder :: new (
41
- builder_args. builder_signer ,
42
- builder_args. flashblocks_ws_url ,
43
- builder_args. chain_block_time ,
44
- builder_args. flashblock_block_time ,
45
- ) ) )
46
- . with_add_ons (
47
- OpAddOnsBuilder :: default ( )
48
- . with_sequencer ( rollup_args. sequencer . clone ( ) )
49
- . with_enable_tx_conditional ( rollup_args. enable_tx_conditional )
50
- . build ( ) ,
51
- )
52
- . on_node_started ( move |ctx| {
53
- let new_canonical_blocks = ctx. provider ( ) . canonical_state_stream ( ) ;
54
- let builder_signer = builder_args. builder_signer ;
41
+ // Wrap the main execution in a span
42
+ let span = tracing:: info_span!( "op-rbuilder" ) ;
43
+ let _enter = span. enter ( ) ;
55
44
56
- if builder_args. log_pool_transactions {
57
- tracing:: info!( "Logging pool transactions" ) ;
58
- ctx. task_executor . spawn_critical (
59
- "txlogging" ,
60
- Box :: pin ( async move {
61
- monitor_tx_pool ( ctx. pool . all_transactions_event_listener ( ) ) . await ;
62
- } ) ,
63
- ) ;
64
- }
45
+ let rollup_args = builder_args. rollup_args ;
65
46
47
+ let op_node = OpNode :: new ( rollup_args. clone ( ) ) ;
48
+ let handle = builder
49
+ . with_types :: < OpNode > ( )
50
+ . with_components ( op_node. components ( ) . payload ( CustomOpPayloadBuilder :: new (
51
+ builder_args. builder_signer ,
52
+ builder_args. flashblocks_ws_url ,
53
+ builder_args. chain_block_time ,
54
+ builder_args. flashblock_block_time ,
55
+ ) ) )
56
+ . with_add_ons (
57
+ OpAddOnsBuilder :: default ( )
58
+ . with_sequencer ( rollup_args. sequencer . clone ( ) )
59
+ . with_enable_tx_conditional ( rollup_args. enable_tx_conditional )
60
+ . build ( ) ,
61
+ )
62
+ . on_node_started ( move |ctx| {
63
+ let new_canonical_blocks = ctx. provider ( ) . canonical_state_stream ( ) ;
64
+ let builder_signer = builder_args. builder_signer ;
65
+
66
+ if builder_args. log_pool_transactions {
67
+ tracing:: info!( "Logging pool transactions" ) ;
66
68
ctx. task_executor . spawn_critical (
67
- "monitoring " ,
69
+ "txlogging " ,
68
70
Box :: pin ( async move {
69
- let monitoring = Monitoring :: new ( builder_signer) ;
70
- let _ = monitoring. run_with_stream ( new_canonical_blocks) . await ;
71
+ monitor_tx_pool ( ctx. pool . all_transactions_event_listener ( ) ) . await ;
71
72
} ) ,
72
73
) ;
74
+ }
75
+
76
+ ctx. task_executor . spawn_critical (
77
+ "monitoring" ,
78
+ Box :: pin ( async move {
79
+ let monitoring = Monitoring :: new ( builder_signer) ;
80
+ let _ = monitoring. run_with_stream ( new_canonical_blocks) . await ;
81
+ } ) ,
82
+ ) ;
83
+
84
+ Ok ( ( ) )
85
+ } )
86
+ . launch ( )
87
+ . await ?;
73
88
74
- Ok ( ( ) )
75
- } )
76
- . launch ( )
77
- . await ?;
89
+ handle. node_exit_future . await ?;
90
+ #[ cfg( feature = "telemetry" ) ]
91
+ provider. shutdown ( ) ?;
92
+ Ok ( ( ) )
93
+ } ) ?;
78
94
79
- handle. node_exit_future . await
80
- } )
81
- . unwrap ( ) ;
95
+ Ok ( ( ) )
82
96
}
0 commit comments