Skip to content

Commit fbc3b7d

Browse files
committed
moved block_rejection_timeout_steps computation directly in SignerCoordinator::new()
1 parent d4171d7 commit fbc3b7d

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

testnet/stacks-node/src/nakamoto_node/signer_coordinator.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// You should have received a copy of the GNU General Public License
1414
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1515

16-
use std::collections::{BTreeMap, HashMap};
16+
use std::collections::BTreeMap;
1717
use std::ops::Bound::Included;
1818
use std::sync::atomic::AtomicBool;
1919
use std::sync::{Arc, Mutex};
@@ -72,7 +72,7 @@ pub struct SignerCoordinator {
7272
/// burn block has arrived since this thread started.
7373
burn_tip_at_start: ConsensusHash,
7474
/// 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>,
7676
}
7777

7878
impl SignerCoordinator {
@@ -108,6 +108,14 @@ impl SignerCoordinator {
108108
let miners_contract_id = boot_code_id(MINERS_NAME, is_mainnet);
109109
let miners_session = StackerDBSession::new(&rpc_socket.to_string(), miners_contract_id);
110110

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+
111119
let mut sc = Self {
112120
message_key,
113121
is_mainnet,
@@ -118,7 +126,7 @@ impl SignerCoordinator {
118126
keep_running,
119127
listener_thread: None,
120128
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,
122130
};
123131

124132
// Spawn the signer DB listener thread
@@ -279,21 +287,12 @@ impl SignerCoordinator {
279287
}
280288
}
281289

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-
290290
self.get_block_status(
291291
&block.header.signer_signature_hash(),
292292
&block.block_id(),
293293
chain_state,
294294
sortdb,
295295
counters,
296-
&block_rejection_timeout_steps,
297296
)
298297
}
299298

@@ -309,19 +308,18 @@ impl SignerCoordinator {
309308
chain_state: &mut StacksChainState,
310309
sortdb: &SortitionDB,
311310
counters: &Counters,
312-
block_rejection_timeout_steps: &BTreeMap<u64, Duration>,
313311
) -> Result<Vec<MessageSignature>, NakamotoNodeError> {
314312
// the amount of current rejections (used to eventually modify the timeout)
315313
let mut rejections: u64 = 0;
316314
// 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+
})?;
325323
// this is used for comparing block_status to identify if it has been changed from the previous event
326324
let mut block_status_tracker = BlockStatus::default();
327325

@@ -397,7 +395,8 @@ impl SignerCoordinator {
397395

398396
if rejections != block_status.total_reject_weight as u64 {
399397
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
401400
.range((Included(0), Included(rejections)))
402401
.last()
403402
.ok_or_else(|| {

0 commit comments

Comments
 (0)