13
13
// You should have received a copy of the GNU General Public License
14
14
// along with this program. If not, see <http://www.gnu.org/licenses/>.
15
15
16
- use std:: collections:: { BTreeMap , HashMap } ;
16
+ use std:: collections:: BTreeMap ;
17
17
use std:: ops:: Bound :: Included ;
18
18
use std:: sync:: atomic:: AtomicBool ;
19
19
use std:: sync:: { Arc , Mutex } ;
@@ -72,7 +72,7 @@ pub struct SignerCoordinator {
72
72
/// burn block has arrived since this thread started.
73
73
burn_tip_at_start : ConsensusHash ,
74
74
/// The timeout configuration based on the percentage of rejections
75
- block_rejection_timeout_steps : HashMap < u32 , Duration > ,
75
+ block_rejection_timeout_steps : BTreeMap < u64 , Duration > ,
76
76
}
77
77
78
78
impl SignerCoordinator {
@@ -108,6 +108,14 @@ impl SignerCoordinator {
108
108
let miners_contract_id = boot_code_id ( MINERS_NAME , is_mainnet) ;
109
109
let miners_session = StackerDBSession :: new ( & rpc_socket. to_string ( ) , miners_contract_id) ;
110
110
111
+ // build a BTreeMap of the various timeout steps
112
+ let mut block_rejection_timeout_steps = BTreeMap :: < u64 , Duration > :: new ( ) ;
113
+ for ( percentage, duration) in config. miner . block_rejection_timeout_steps . iter ( ) {
114
+ let rejections_amount =
115
+ ( ( f64:: from ( listener. total_weight ) / 100.0 ) * f64:: from ( * percentage) ) as u64 ;
116
+ block_rejection_timeout_steps. insert ( rejections_amount, * duration) ;
117
+ }
118
+
111
119
let mut sc = Self {
112
120
message_key,
113
121
is_mainnet,
@@ -118,7 +126,7 @@ impl SignerCoordinator {
118
126
keep_running,
119
127
listener_thread : None ,
120
128
burn_tip_at_start : burn_tip_at_start. clone ( ) ,
121
- block_rejection_timeout_steps : config . miner . block_rejection_timeout_steps . clone ( ) ,
129
+ block_rejection_timeout_steps,
122
130
} ;
123
131
124
132
// Spawn the signer DB listener thread
@@ -279,21 +287,12 @@ impl SignerCoordinator {
279
287
}
280
288
}
281
289
282
- // build a BTreeMap of the various timeout steps
283
- let mut block_rejection_timeout_steps = BTreeMap :: < u64 , Duration > :: new ( ) ;
284
- for ( percentage, duration) in self . block_rejection_timeout_steps . iter ( ) {
285
- let rejections_amount =
286
- ( ( f64:: from ( self . total_weight ) / 100.0 ) * f64:: from ( * percentage) ) as u64 ;
287
- block_rejection_timeout_steps. insert ( rejections_amount, * duration) ;
288
- }
289
-
290
290
self . get_block_status (
291
291
& block. header . signer_signature_hash ( ) ,
292
292
& block. block_id ( ) ,
293
293
chain_state,
294
294
sortdb,
295
295
counters,
296
- & block_rejection_timeout_steps,
297
296
)
298
297
}
299
298
@@ -309,19 +308,18 @@ impl SignerCoordinator {
309
308
chain_state : & mut StacksChainState ,
310
309
sortdb : & SortitionDB ,
311
310
counters : & Counters ,
312
- block_rejection_timeout_steps : & BTreeMap < u64 , Duration > ,
313
311
) -> Result < Vec < MessageSignature > , NakamotoNodeError > {
314
312
// the amount of current rejections (used to eventually modify the timeout)
315
313
let mut rejections: u64 = 0 ;
316
314
// default timeout (the 0 entry must be always present)
317
- let mut rejections_timeout =
318
- block_rejection_timeout_steps
319
- . get ( & rejections)
320
- . ok_or_else ( || {
321
- NakamotoNodeError :: SigningCoordinatorFailure (
322
- "Invalid rejection timeout step function definition" . into ( ) ,
323
- )
324
- } ) ?;
315
+ let mut rejections_timeout = self
316
+ . block_rejection_timeout_steps
317
+ . get ( & rejections)
318
+ . ok_or_else ( || {
319
+ NakamotoNodeError :: SigningCoordinatorFailure (
320
+ "Invalid rejection timeout step function definition" . into ( ) ,
321
+ )
322
+ } ) ?;
325
323
// this is used for comparing block_status to identify if it has been changed from the previous event
326
324
let mut block_status_tracker = BlockStatus :: default ( ) ;
327
325
@@ -397,7 +395,8 @@ impl SignerCoordinator {
397
395
398
396
if rejections != block_status. total_reject_weight as u64 {
399
397
rejections = block_status. total_reject_weight as u64 ;
400
- let rejections_timeout_tuple = block_rejection_timeout_steps
398
+ let rejections_timeout_tuple = self
399
+ . block_rejection_timeout_steps
401
400
. range ( ( Included ( 0 ) , Included ( rejections) ) )
402
401
. last ( )
403
402
. ok_or_else ( || {
0 commit comments