1
1
mod blocks_pool;
2
2
3
+ use std:: thread:: JoinHandle ;
3
4
use std:: time:: Duration ;
4
5
5
6
use crate :: chainhooks:: types:: {
@@ -106,29 +107,46 @@ pub async fn retrieve_full_block(
106
107
Ok ( ( block_height, block) )
107
108
}
108
109
109
- pub async fn standardize_bitcoin_block (
110
+ pub fn standardize_bitcoin_block (
110
111
indexer_config : & IndexerConfig ,
111
112
block_height : u64 ,
112
113
block : Block ,
113
114
bitcoin_context : & mut BitcoinChainContext ,
114
115
ctx : & Context ,
115
116
) -> Result < BitcoinBlockData , String > {
116
117
let mut transactions = vec ! [ ] ;
117
-
118
118
ctx. try_log ( |logger| slog:: info!( logger, "Updating ordinal index" , ) ) ;
119
- match OrdinalIndexUpdater :: update ( & mut bitcoin_context. ordinal_index ) . await {
120
- Ok ( _) => {
121
- ctx. try_log ( |logger| {
122
- slog:: info!(
123
- logger,
124
- "Ordinal index updated (block count: {:?})" ,
125
- bitcoin_context. ordinal_index. block_count( )
126
- )
127
- } ) ;
128
- }
129
- Err ( e) => {
130
- ctx. try_log ( |logger| slog:: error!( logger, "{}" , e. to_string( ) ) ) ;
119
+
120
+ let ordinal_index = bitcoin_context. ordinal_index . take ( ) ;
121
+ let ctx_ = ctx. clone ( ) ;
122
+ let handle: JoinHandle < Result < _ , String > > =
123
+ hiro_system_kit:: thread_named ( "Ordinal index update" )
124
+ . spawn ( move || {
125
+ if let Some ( ref ordinal_index) = ordinal_index {
126
+ match hiro_system_kit:: nestable_block_on ( OrdinalIndexUpdater :: update (
127
+ & ordinal_index,
128
+ ) ) {
129
+ Ok ( _) => {
130
+ ctx_. try_log ( |logger| {
131
+ slog:: info!( logger, "Ordinal index successfully updated" , )
132
+ } ) ;
133
+ }
134
+ Err ( e) => {
135
+ ctx_. try_log ( |logger| {
136
+ slog:: error!( logger, "Error updating ordinal index" , )
137
+ } ) ;
138
+ }
139
+ } ;
140
+ }
141
+ Ok ( ordinal_index)
142
+ } )
143
+ . expect ( "unable to detach thread" ) ;
144
+
145
+ match handle. join ( ) {
146
+ Ok ( Ok ( ordinal_index) ) => {
147
+ bitcoin_context. ordinal_index = ordinal_index;
131
148
}
149
+ _ => { }
132
150
}
133
151
134
152
let expected_magic_bytes = get_stacks_canonical_magic_bytes ( & indexer_config. bitcoin_network ) ;
@@ -153,10 +171,10 @@ pub async fn standardize_bitcoin_block(
153
171
}
154
172
155
173
let mut ordinal_operations = vec ! [ ] ;
156
- if let Some ( op ) =
157
- try_parse_ordinal_operation ( & tx, block_height, & bitcoin_context . ordinal_index , ctx)
158
- {
159
- ordinal_operations . push ( op ) ;
174
+ if let Some ( ref ordinal_index ) = bitcoin_context . ordinal_index {
175
+ if let Some ( op ) = try_parse_ordinal_operation ( & tx, block_height, & ordinal_index, ctx) {
176
+ ordinal_operations . push ( op ) ;
177
+ }
160
178
}
161
179
162
180
let mut inputs = vec ! [ ] ;
0 commit comments