Call flush_key

This commit is contained in:
Luke Parker
2024-08-29 16:27:00 -04:00
parent 8db76ed67c
commit 4f6d91037e
4 changed files with 68 additions and 23 deletions

View File

@@ -35,17 +35,25 @@ pub(crate) enum LifetimeStage {
Finishing,
}
impl LifetimeStage {
/// Get the stage of its lifetime this multisig is in, and the block at which we start reporting
/// outputs to it.
/// The lifetime of the multisig, including various block numbers.
pub(crate) struct Lifetime {
pub(crate) stage: LifetimeStage,
pub(crate) block_at_which_reporting_starts: u64,
// This is only Some if the next key's activation block number is passed to calculate, and the
// stage is at least `LifetimeStage::Active.`
pub(crate) block_at_which_forwarding_starts: Option<u64>,
}
impl Lifetime {
/// Get the lifetime of this multisig.
///
/// Panics if the multisig being calculated for isn't actually active and a variety of other
/// insane cases.
pub(crate) fn calculate_stage_and_reporting_start_block<S: ScannerFeed>(
pub(crate) fn calculate<S: ScannerFeed>(
block_number: u64,
activation_block_number: u64,
next_keys_activation_block_number: Option<u64>,
) -> (Self, u64) {
) -> Self {
assert!(
activation_block_number >= block_number,
"calculating lifetime stage for an inactive multisig"
@@ -55,14 +63,14 @@ impl LifetimeStage {
let active_yet_not_reporting_end_block =
activation_block_number + S::CONFIRMATIONS + S::TEN_MINUTES;
// The exclusive end block is the inclusive start block
let reporting_start_block = active_yet_not_reporting_end_block;
let block_at_which_reporting_starts = active_yet_not_reporting_end_block;
if block_number < active_yet_not_reporting_end_block {
return (LifetimeStage::ActiveYetNotReporting, reporting_start_block);
return Lifetime { stage: LifetimeStage::ActiveYetNotReporting, block_at_which_reporting_starts, block_at_which_forwarding_starts: None };
}
let Some(next_keys_activation_block_number) = next_keys_activation_block_number else {
// If there is no next multisig, this is the active multisig
return (LifetimeStage::Active, reporting_start_block);
return Lifetime { stage: LifetimeStage::Active, block_at_which_reporting_starts, block_at_which_forwarding_starts: None };
};
assert!(
@@ -70,19 +78,22 @@ impl LifetimeStage {
"next set of keys activated before this multisig activated"
);
// If the new multisig is still having its activation block finalized on-chain, this multisig
// is still active (step 3)
let new_active_yet_not_reporting_end_block =
next_keys_activation_block_number + S::CONFIRMATIONS + S::TEN_MINUTES;
let new_active_and_used_for_change_end_block =
new_active_yet_not_reporting_end_block + S::CONFIRMATIONS;
// The exclusive end block is the inclusive start block
let block_at_which_forwarding_starts = Some(new_active_and_used_for_change_end_block);
// If the new multisig is still having its activation block finalized on-chain, this multisig
// is still active (step 3)
if block_number < new_active_yet_not_reporting_end_block {
return (LifetimeStage::Active, reporting_start_block);
return Lifetime { stage: LifetimeStage::Active, block_at_which_reporting_starts, block_at_which_forwarding_starts };
}
// Step 4 details a further CONFIRMATIONS
let new_active_and_used_for_change_end_block =
new_active_yet_not_reporting_end_block + S::CONFIRMATIONS;
if block_number < new_active_and_used_for_change_end_block {
return (LifetimeStage::UsingNewForChange, reporting_start_block);
return Lifetime { stage: LifetimeStage::UsingNewForChange, block_at_which_reporting_starts, block_at_which_forwarding_starts };
}
// Step 5 details a further 6 hours
@@ -90,10 +101,10 @@ impl LifetimeStage {
let new_active_and_forwarded_to_end_block =
new_active_and_used_for_change_end_block + (6 * 6 * S::TEN_MINUTES);
if block_number < new_active_and_forwarded_to_end_block {
return (LifetimeStage::Forwarding, reporting_start_block);
return Lifetime { stage: LifetimeStage::Forwarding, block_at_which_reporting_starts, block_at_which_forwarding_starts };
}
// Step 6
(LifetimeStage::Finishing, reporting_start_block)
Lifetime { stage: LifetimeStage::Finishing, block_at_which_reporting_starts, block_at_which_forwarding_starts }
}
}