@@ -53,13 +53,32 @@ impl BlockchainParser {
53
53
tracing:: debug!( target: "parser" , "Starting worker ..." ) ;
54
54
55
55
self . on_start ( self . cur_height ) ;
56
+ let block_buffer_size = 2 ;
57
+ let mut blocks = Vec :: with_capacity ( block_buffer_size) ;
56
58
while let Some ( header) = self . chain_storage . get_header ( self . cur_height ) {
57
59
Self :: on_header ( & header, self . cur_height ) ;
58
60
let block = self . chain_storage . get_block ( self . cur_height ) . unwrap ( ) ;
59
- self . on_block ( & block, self . cur_height ) ?;
61
+
62
+ tracing:: trace!( target: "parser" , "on_block(height={}) called" , self . cur_height) ;
63
+ blocks. push ( crate :: db:: Block {
64
+ height : self . cur_height . try_into ( ) ?,
65
+ version : block. header . version . to_consensus ( ) ,
66
+ time : block. header . time . try_into ( ) ?,
67
+ encoded_target : block. header . bits . to_consensus ( ) . try_into ( ) ?,
68
+ nonce : block. header . nonce . try_into ( ) ?,
69
+ tx_count : block. txdata . len ( ) . try_into ( ) ?,
70
+ size : block. size ( ) . try_into ( ) ?,
71
+ weight : block. weight ( ) . to_wu ( ) . try_into ( ) ?,
72
+ } ) ;
73
+ if blocks. len ( ) == block_buffer_size {
74
+ self . db . insert_blocks ( blocks) ?;
75
+ blocks = Vec :: with_capacity ( block_buffer_size) ;
76
+ }
60
77
self . print_progress ( self . cur_height ) ;
61
78
self . cur_height += 1 ;
62
79
}
80
+
81
+ self . db . insert_blocks ( blocks) ?;
63
82
self . on_complete ( self . cur_height . saturating_sub ( 1 ) ) ;
64
83
Ok ( ( ) )
65
84
}
@@ -83,25 +102,6 @@ impl BlockchainParser {
83
102
tracing:: trace!( target: "parser" , "on_header(height={}) called" , height) ;
84
103
}
85
104
86
- fn on_block (
87
- & mut self ,
88
- block : & bitcoin:: Block ,
89
- height : u64 ,
90
- ) -> anyhow:: Result < ( ) > {
91
- tracing:: trace!( target: "parser" , "on_block(height={}) called" , height) ;
92
- self . db . insert_block ( crate :: db:: Block {
93
- height : self . cur_height . try_into ( ) ?,
94
- version : block. header . version . to_consensus ( ) ,
95
- time : block. header . time . try_into ( ) ?,
96
- encoded_target : block. header . bits . to_consensus ( ) . try_into ( ) ?,
97
- nonce : block. header . nonce . try_into ( ) ?,
98
- tx_count : block. txdata . len ( ) . try_into ( ) ?,
99
- size : block. size ( ) . try_into ( ) ?,
100
- weight : block. weight ( ) . to_wu ( ) . try_into ( ) ?,
101
- } ) ?;
102
- Ok ( ( ) )
103
- }
104
-
105
105
fn on_complete ( & mut self , height : u64 ) {
106
106
tracing:: info!( target: "parser" , "Done. Processed blocks up to height {} in {:.2} minutes." ,
107
107
height, self . stats. started_at. elapsed( ) . as_secs_f32( ) / 60.0 ) ;
0 commit comments