@@ -102,17 +102,29 @@ pub fn get_bitcoin_stacks_epochs(network_id: BitcoinNetworkType) -> EpochList {
102
102
103
103
#[ derive( Debug , Clone , PartialEq ) ]
104
104
pub struct BitcoinIndexerConfig {
105
- // config fields
105
+ /// Hostname or IP address of the Bitcoin node
106
106
pub peer_host : String ,
107
+ /// Port number of the Bitcoin node
107
108
pub peer_port : u16 ,
109
+ /// Port number of the Bitcoin RPC interface
108
110
pub rpc_port : u16 ,
111
+ /// Whether to use SSL for the RPC interface
109
112
pub rpc_ssl : bool ,
113
+ /// Username for the RPC interface
110
114
pub username : Option < String > ,
115
+ /// Password for the RPC interface
111
116
pub password : Option < String > ,
112
- pub timeout : u32 ,
117
+ /// Timeout for high-level message operations
118
+ pub timeout : u64 ,
119
+ /// Timeout for socket read/write operations
120
+ pub socket_timeout : u64 ,
121
+ /// Path to the SPV headers database
113
122
pub spv_headers_path : String ,
123
+ /// The first block to index
114
124
pub first_block : u64 ,
125
+ /// Magic bytes for Stacks operations
115
126
pub magic_bytes : MagicBytes ,
127
+ /// The epochs for this network
116
128
pub epochs : Option < EpochList > ,
117
129
}
118
130
@@ -144,7 +156,8 @@ impl BitcoinIndexerConfig {
144
156
rpc_ssl : false ,
145
157
username : Some ( "blockstack" . to_string ( ) ) ,
146
158
password : Some ( "blockstacksystem" . to_string ( ) ) ,
147
- timeout : 30 ,
159
+ timeout : 300 ,
160
+ socket_timeout : 30 ,
148
161
spv_headers_path : "./headers.sqlite" . to_string ( ) ,
149
162
first_block,
150
163
magic_bytes : BLOCKSTACK_MAGIC_MAINNET . clone ( ) ,
@@ -160,7 +173,8 @@ impl BitcoinIndexerConfig {
160
173
rpc_ssl : false ,
161
174
username : Some ( "blockstack" . to_string ( ) ) ,
162
175
password : Some ( "blockstacksystem" . to_string ( ) ) ,
163
- timeout : 30 ,
176
+ timeout : 300 ,
177
+ socket_timeout : 30 ,
164
178
spv_headers_path,
165
179
first_block : 0 ,
166
180
magic_bytes : BLOCKSTACK_MAGIC_MAINNET . clone ( ) ,
@@ -177,7 +191,8 @@ impl BitcoinIndexerConfig {
177
191
rpc_ssl : false ,
178
192
username : Some ( "blockstack" . to_string ( ) ) ,
179
193
password : Some ( "blockstacksystem" . to_string ( ) ) ,
180
- timeout : 30 ,
194
+ timeout : 300 ,
195
+ socket_timeout : 30 ,
181
196
spv_headers_path,
182
197
first_block : 0 ,
183
198
magic_bytes : BLOCKSTACK_MAGIC_MAINNET . clone ( ) ,
@@ -187,7 +202,7 @@ impl BitcoinIndexerConfig {
187
202
}
188
203
189
204
impl BitcoinIndexerRuntime {
190
- pub fn new ( network_id : BitcoinNetworkType ) -> BitcoinIndexerRuntime {
205
+ pub fn new ( network_id : BitcoinNetworkType , timeout : u64 ) -> BitcoinIndexerRuntime {
191
206
let mut rng = thread_rng ( ) ;
192
207
BitcoinIndexerRuntime {
193
208
sock : None ,
@@ -198,7 +213,7 @@ impl BitcoinIndexerRuntime {
198
213
block_height : 0 ,
199
214
last_getdata_send_time : 0 ,
200
215
last_getheaders_send_time : 0 ,
201
- timeout : 300 ,
216
+ timeout,
202
217
}
203
218
}
204
219
}
@@ -237,19 +252,23 @@ impl BitcoinIndexer {
237
252
)
238
253
. unwrap_or_else ( |_| panic ! ( "Failed to open {working_dir_path:?}" ) ) ;
239
254
255
+ let config =
256
+ BitcoinIndexerConfig :: default_regtest ( working_dir_path. to_str ( ) . unwrap ( ) . to_string ( ) ) ;
257
+ let timeout = config. timeout ;
240
258
BitcoinIndexer {
241
- config : BitcoinIndexerConfig :: default_regtest (
242
- working_dir_path. to_str ( ) . unwrap ( ) . to_string ( ) ,
243
- ) ,
244
- runtime : BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Regtest ) ,
259
+ config,
260
+ runtime : BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Regtest , timeout) ,
245
261
should_keep_running : None ,
246
262
}
247
263
}
248
264
249
265
pub fn dup ( & self ) -> BitcoinIndexer {
250
266
BitcoinIndexer {
251
267
config : self . config . clone ( ) ,
252
- runtime : BitcoinIndexerRuntime :: new ( self . runtime . network_id ) ,
268
+ runtime : BitcoinIndexerRuntime :: new (
269
+ self . runtime . network_id ,
270
+ self . config . timeout . into ( ) ,
271
+ ) ,
253
272
should_keep_running : self . should_keep_running . clone ( ) ,
254
273
}
255
274
}
@@ -268,13 +287,13 @@ impl BitcoinIndexer {
268
287
} ) ?;
269
288
270
289
// set timeout
271
- s. set_read_timeout ( Some ( Duration :: from_secs ( self . runtime . timeout ) ) )
290
+ s. set_read_timeout ( Some ( Duration :: from_secs ( self . config . socket_timeout ) ) )
272
291
. map_err ( |_e| {
273
292
test_debug ! ( "Failed to set TCP read timeout: {_e:?}" ) ;
274
293
btc_error:: ConnectionError
275
294
} ) ?;
276
295
277
- s. set_write_timeout ( Some ( Duration :: from_secs ( self . runtime . timeout ) ) )
296
+ s. set_write_timeout ( Some ( Duration :: from_secs ( self . config . socket_timeout ) ) )
278
297
. map_err ( |_e| {
279
298
test_debug ! ( "Failed to set TCP write timeout: {_e:?}" ) ;
280
299
btc_error:: ConnectionError
@@ -1334,9 +1353,11 @@ mod test {
1334
1353
1335
1354
assert_eq ! ( spv_client_reorg. read_block_headers( 2 , 10 ) . unwrap( ) . len( ) , 2 ) ;
1336
1355
1356
+ let config = BitcoinIndexerConfig :: test_default ( path_1. to_string ( ) ) ;
1357
+ let timeout = config. timeout ;
1337
1358
let mut indexer = BitcoinIndexer :: new (
1338
- BitcoinIndexerConfig :: test_default ( path_1 . to_string ( ) ) ,
1339
- BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Regtest ) ,
1359
+ config ,
1360
+ BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Regtest , timeout ) ,
1340
1361
None ,
1341
1362
) ;
1342
1363
let common_ancestor_height = indexer
@@ -1507,9 +1528,11 @@ mod test {
1507
1528
1508
1529
assert_eq ! ( spv_client_reorg. read_block_headers( 2 , 10 ) . unwrap( ) . len( ) , 2 ) ;
1509
1530
1531
+ let config = BitcoinIndexerConfig :: test_default ( path_1. to_string ( ) ) ;
1532
+ let timeout = config. timeout ;
1510
1533
let mut indexer = BitcoinIndexer :: new (
1511
- BitcoinIndexerConfig :: test_default ( path_1 . to_string ( ) ) ,
1512
- BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Regtest ) ,
1534
+ config ,
1535
+ BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Regtest , timeout ) ,
1513
1536
None ,
1514
1537
) ;
1515
1538
let common_ancestor_height = indexer
@@ -1583,7 +1606,8 @@ mod test {
1583
1606
rpc_ssl : false ,
1584
1607
username : Some ( "blockstack" . to_string ( ) ) ,
1585
1608
password : Some ( "blockstacksystem" . to_string ( ) ) ,
1586
- timeout : 30 ,
1609
+ timeout : 300 ,
1610
+ socket_timeout : 30 ,
1587
1611
spv_headers_path : db_path. to_string ( ) ,
1588
1612
first_block : 0 ,
1589
1613
magic_bytes : MagicBytes ( [ 105 , 100 ] ) ,
@@ -1594,7 +1618,12 @@ mod test {
1594
1618
fs:: remove_file ( & indexer_conf. spv_headers_path ) . unwrap ( ) ;
1595
1619
}
1596
1620
1597
- let mut indexer = BitcoinIndexer :: new ( indexer_conf, BitcoinIndexerRuntime :: new ( mode) , None ) ;
1621
+ let timeout = indexer_conf. timeout ;
1622
+ let mut indexer = BitcoinIndexer :: new (
1623
+ indexer_conf,
1624
+ BitcoinIndexerRuntime :: new ( mode, timeout) ,
1625
+ None ,
1626
+ ) ;
1598
1627
let last_block = indexer. sync_headers ( 0 , None ) . unwrap ( ) ;
1599
1628
eprintln ! ( "sync'ed to block {}" , last_block) ;
1600
1629
@@ -3162,9 +3191,11 @@ mod test {
3162
3191
} ,
3163
3192
] ;
3164
3193
3194
+ let config = BitcoinIndexerConfig :: test_default ( db_path. to_string ( ) ) ;
3195
+ let timeout = config. timeout ;
3165
3196
let mut indexer = BitcoinIndexer :: new (
3166
- BitcoinIndexerConfig :: test_default ( db_path . to_string ( ) ) ,
3167
- BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Mainnet ) ,
3197
+ config ,
3198
+ BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Mainnet , timeout ) ,
3168
3199
None ,
3169
3200
) ;
3170
3201
@@ -3323,9 +3354,11 @@ mod test {
3323
3354
let total_work_before_idempotent = spv_client. update_chain_work ( ) . unwrap ( ) ;
3324
3355
assert_eq ! ( total_work_before, total_work_before_idempotent) ;
3325
3356
3357
+ let config = BitcoinIndexerConfig :: test_default ( db_path. to_string ( ) ) ;
3358
+ let timeout = config. timeout ;
3326
3359
let mut indexer = BitcoinIndexer :: new (
3327
- BitcoinIndexerConfig :: test_default ( db_path . to_string ( ) ) ,
3328
- BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Mainnet ) ,
3360
+ config ,
3361
+ BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Mainnet , timeout ) ,
3329
3362
None ,
3330
3363
) ;
3331
3364
@@ -3462,9 +3495,11 @@ mod test {
3462
3495
spv_client. test_write_block_headers ( 0 , headers) . unwrap ( ) ;
3463
3496
assert_eq ! ( spv_client. get_highest_header_height( ) . unwrap( ) , 2 ) ;
3464
3497
3498
+ let config = BitcoinIndexerConfig :: test_default ( db_path. to_string ( ) ) ;
3499
+ let timeout = config. timeout ;
3465
3500
let mut indexer = BitcoinIndexer :: new (
3466
- BitcoinIndexerConfig :: test_default ( db_path . to_string ( ) ) ,
3467
- BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Regtest ) ,
3501
+ config ,
3502
+ BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Regtest , timeout ) ,
3468
3503
None ,
3469
3504
) ;
3470
3505
@@ -3489,9 +3524,11 @@ mod test {
3489
3524
}
3490
3525
3491
3526
let should_keep_running = Arc :: new ( AtomicBool :: new ( true ) ) ;
3527
+ let config = BitcoinIndexerConfig :: test_default ( db_path) ;
3528
+ let timeout = config. timeout ;
3492
3529
let mut indexer = BitcoinIndexer :: new (
3493
- BitcoinIndexerConfig :: test_default ( db_path ) ,
3494
- BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Mainnet ) ,
3530
+ config ,
3531
+ BitcoinIndexerRuntime :: new ( BitcoinNetworkType :: Mainnet , timeout ) ,
3495
3532
Some ( should_keep_running. clone ( ) ) ,
3496
3533
) ;
3497
3534
0 commit comments