11use {
22 super :: traits,
33 crate :: {
4+ alloy,
45 pipelines:: { exec:: PipelineExecutor , service:: ServiceContext } ,
56 prelude:: * ,
6- reth:: {
7- api:: PayloadBuilderAttributes ,
8- payload:: builder:: { PayloadJob as RethPayloadJobTrait , * } ,
9- } ,
7+ reth,
108 } ,
9+ alloy:: consensus:: BlockHeader ,
1110 core:: {
1211 pin:: Pin ,
1312 task:: { Context , Poll } ,
1413 } ,
1514 futures:: { FutureExt , future:: Shared } ,
16- reth_node_builder:: BuiltPayload ,
17- std:: sync:: Arc ,
15+ reth:: {
16+ api:: PayloadBuilderAttributes ,
17+ node:: builder:: { BlockBody , BuiltPayload } ,
18+ payload:: builder:: { PayloadJob as RethPayloadJobTrait , * } ,
19+ } ,
20+ std:: { fmt:: Write as _, sync:: Arc , time:: Instant } ,
1821 tracing:: { debug, warn} ,
1922} ;
2023
@@ -146,6 +149,7 @@ where
146149 Provider : traits:: ProviderBounds < P > ,
147150{
148151 payload_id : PayloadId ,
152+ started_at : Instant ,
149153 state : ExecutorFutureState < P , Provider > ,
150154}
151155
@@ -173,10 +177,58 @@ where
173177{
174178 pub fn new ( executor : PipelineExecutor < P , Provider > ) -> Self {
175179 Self {
180+ started_at : Instant :: now ( ) ,
176181 payload_id : executor. payload_id ( ) ,
177182 state : ExecutorFutureState :: Future ( executor. shared ( ) ) ,
178183 }
179184 }
185+
186+ fn log_payload_job_result (
187+ & self ,
188+ result : & Result < types:: BuiltPayload < P > , Arc < PayloadBuilderError > > ,
189+ ) -> core:: fmt:: Result {
190+ match & result {
191+ Ok ( built_payload) => {
192+ let built_block = built_payload. block ( ) ;
193+ let fees = built_payload. fees ( ) ;
194+
195+ let mut out = String :: new ( ) ;
196+ writeln ! ( & mut out, "Payload job {}:" , self . payload_id) ?;
197+ writeln ! ( & mut out, " Status: Success" ) ?;
198+ writeln ! ( & mut out, " Duration: {:?}" , self . started_at. elapsed( ) ) ?;
199+ writeln ! ( & mut out, " Fees: {fees}" ) ?;
200+ writeln ! ( & mut out, " Built Block:" ) ?;
201+ writeln ! ( & mut out, " Number: {:?}" , built_block. number( ) ) ?;
202+ writeln ! ( & mut out, " Hash: {:?}" , built_block. hash( ) ) ?;
203+ writeln ! ( & mut out, " Parent: {:?}" , built_block. parent_hash( ) ) ?;
204+ writeln ! ( & mut out, " Timestamp: {:?}" , built_block. timestamp( ) ) ?;
205+ writeln ! (
206+ & mut out,
207+ " Gas: {}/{} ({}%)" ,
208+ built_block. gas_used( ) ,
209+ built_block. gas_limit( ) ,
210+ built_block. gas_used( ) * 100 / built_block. gas_limit( )
211+ ) ?;
212+ writeln ! (
213+ & mut out,
214+ " Transactions: {}" ,
215+ built_block. body( ) . transactions( ) . len( )
216+ ) ?;
217+
218+ debug ! ( "{out}" ) ;
219+ }
220+ Err ( error) => {
221+ let mut out = String :: new ( ) ;
222+ writeln ! ( & mut out, "Payload job {}:" , self . payload_id) ?;
223+ writeln ! ( & mut out, " Status: Failed" ) ?;
224+ writeln ! ( & mut out, " Duration: {:?}" , self . started_at. elapsed( ) ) ?;
225+ writeln ! ( & mut out, " Error: {error:#?}" ) ?;
226+ warn ! ( "{out}" ) ;
227+ }
228+ }
229+
230+ Ok ( ( ) )
231+ }
180232}
181233
182234impl < P , Provider > Future for ExecutorFuture < P , Provider >
@@ -202,7 +254,7 @@ where
202254 Poll :: Ready ( result) => {
203255 // got a result. All future polls will return the result directly
204256 // without polling the executor again.
205- log_payload_job_result :: < P > ( this. payload_id , & result) ;
257+ let _ = this. log_payload_job_result ( & result) ;
206258
207259 this. state = ExecutorFutureState :: Ready ( result. clone ( ) ) ;
208260 Poll :: Ready (
@@ -230,6 +282,7 @@ where
230282 fn clone ( & self ) -> Self {
231283 Self {
232284 payload_id : self . payload_id ,
285+ started_at : self . started_at ,
233286 state : match & self . state {
234287 ExecutorFutureState :: Ready ( result) => {
235288 ExecutorFutureState :: Ready ( result. clone ( ) )
@@ -241,22 +294,3 @@ where
241294 }
242295 }
243296}
244-
245- fn log_payload_job_result < P : Platform > (
246- payload_id : PayloadId ,
247- result : & Result < types:: BuiltPayload < P > , Arc < PayloadBuilderError > > ,
248- ) {
249- match & result {
250- Ok ( built_payload) => {
251- let built_block = built_payload. block ( ) ;
252- let fees = built_payload. fees ( ) ;
253-
254- debug ! (
255- "Payload job {payload_id} completed: {built_block:#?}, fees: {fees}"
256- ) ;
257- }
258- Err ( error) => {
259- warn ! ( "Payload job {payload_id} failed: {error:#?}" ) ;
260- }
261- }
262- }
0 commit comments