-
Notifications
You must be signed in to change notification settings - Fork 411
OutputSweeper
: Delay pruning until monitors have likely been archived
#3559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
//! sweeping them. | ||
|
||
use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator}; | ||
use crate::chain::channelmonitor::ANTI_REORG_DELAY; | ||
use crate::chain::channelmonitor::{ANTI_REORG_DELAY, ARCHIVAL_DELAY_BLOCKS}; | ||
use crate::chain::{self, BestBlock, Confirm, Filter, Listen, WatchedOutput}; | ||
use crate::io; | ||
use crate::ln::msgs::DecodeError; | ||
|
@@ -32,6 +32,9 @@ use bitcoin::{BlockHash, Transaction, Txid}; | |
|
||
use core::ops::Deref; | ||
|
||
/// The number of blocks we wait before we prune the tracked spendable outputs. | ||
pub const PRUNE_DELAY_BLOCKS: u32 = ARCHIVAL_DELAY_BLOCKS + ANTI_REORG_DELAY; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how likely is it that 4032 blocks was insufficient, but 4038 was? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, the idea here is that we start pruning after the monitors have been archived. For that to work we need to wait at least 4032 blocks, but of course we're not super sure how soon after the threshold has been met user will actually call FWIW, I alternatively considered introducing a new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pretty unlikely, but holding onto them doesn't really cost us anything, so might as well... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I would have though max(4032, 6) would have also worked, but given that it indeed costs nothing… |
||
|
||
/// The state of a spendable output currently tracked by an [`OutputSweeper`]. | ||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub struct TrackedSpendableOutput { | ||
|
@@ -71,13 +74,7 @@ impl TrackedSpendableOutput { | |
|
||
/// Returns whether the output is spent in the given transaction. | ||
pub fn is_spent_in(&self, tx: &Transaction) -> bool { | ||
let prev_outpoint = match &self.descriptor { | ||
SpendableOutputDescriptor::StaticOutput { outpoint, .. } => *outpoint, | ||
SpendableOutputDescriptor::DelayedPaymentOutput(output) => output.outpoint, | ||
SpendableOutputDescriptor::StaticPaymentOutput(output) => output.outpoint, | ||
} | ||
.into_bitcoin_outpoint(); | ||
|
||
let prev_outpoint = self.descriptor.outpoint().into_bitcoin_outpoint(); | ||
tx.input.iter().any(|input| input.previous_output == prev_outpoint) | ||
} | ||
} | ||
|
@@ -107,7 +104,11 @@ pub enum OutputSpendStatus { | |
latest_spending_tx: Transaction, | ||
}, | ||
/// A transaction spending the output has been confirmed on-chain but will be tracked until it | ||
/// reaches [`ANTI_REORG_DELAY`] confirmations. | ||
/// reaches at least [`PRUNE_DELAY_BLOCKS`] confirmations to ensure [`Event::SpendableOutputs`] | ||
/// stemming from lingering [`ChannelMonitor`]s can safely be replayed. | ||
/// | ||
/// [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs | ||
/// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor | ||
PendingThresholdConfirmations { | ||
/// The hash of the chain tip when we first broadcast a transaction spending this output. | ||
first_broadcast_hash: BlockHash, | ||
|
@@ -530,7 +531,9 @@ where | |
// Prune all outputs that have sufficient depth by now. | ||
sweeper_state.outputs.retain(|o| { | ||
if let Some(confirmation_height) = o.status.confirmation_height() { | ||
if cur_height >= confirmation_height + ANTI_REORG_DELAY - 1 { | ||
// We wait at least `PRUNE_DELAY_BLOCKS` as before that | ||
// `Event::SpendableOutputs` from lingering monitors might get replayed. | ||
if cur_height >= confirmation_height + PRUNE_DELAY_BLOCKS - 1 { | ||
log_debug!(self.logger, | ||
"Pruning swept output as sufficiently confirmed via spend in transaction {:?}. Pruned descriptor: {:?}", | ||
o.status.latest_spending_tx().map(|t| t.compute_txid()), o.descriptor | ||
|
Uh oh!
There was an error while loading. Please reload this page.