Skip to content

Commit 8119244

Browse files
committed
Correctly mark chain_sync updates in test_utils
We were incorrectly marking updates as chain_sync or not in test_utils based on whether monitor_update is None or not. Instead, use UpdateOrigin to determine it.
1 parent 1eec961 commit 8119244

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,30 @@ use core::ops::Deref;
4747
use core::sync::atomic::{AtomicUsize, Ordering};
4848
use bitcoin::secp256k1::PublicKey;
4949

50-
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
51-
/// A specific update's ID stored in a `MonitorUpdateId`, separated out to make the contents
52-
/// entirely opaque.
53-
enum UpdateOrigin {
54-
/// An update that was generated by the `ChannelManager` (via our `chain::Watch`
55-
/// implementation). This corresponds to an actual [`ChannelMonitorUpdate::update_id`] field
56-
/// and [`ChannelMonitor::get_latest_update_id`].
57-
OffChain(u64),
58-
/// An update that was generated during blockchain processing. The ID here is specific to the
59-
/// generating [`ChainMonitor`] and does *not* correspond to any on-disk IDs.
60-
ChainSync(u64),
50+
mod update_origin {
51+
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
52+
/// A specific update's ID stored in a `MonitorUpdateId`, separated out to make the contents
53+
/// entirely opaque.
54+
pub(crate) enum UpdateOrigin {
55+
/// An update that was generated by the `ChannelManager` (via our `chain::Watch`
56+
/// implementation). This corresponds to an actual [`ChannelMonitorUpdate::update_id`] field
57+
/// and [`ChannelMonitor::get_latest_update_id`].
58+
OffChain(u64),
59+
/// An update that was generated during blockchain processing. The ID here is specific to the
60+
/// generating [`ChainMonitor`] and does *not* correspond to any on-disk IDs.
61+
ChainSync(u64),
62+
}
6163
}
6264

65+
#[cfg(any(feature = "_test_utils", test))]
66+
pub(crate) use update_origin::UpdateOrigin;
67+
#[cfg(not(any(feature = "_test_utils", test)))]
68+
use update_origin::UpdateOrigin;
69+
6370
/// An opaque identifier describing a specific [`Persist`] method call.
6471
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
6572
pub struct MonitorUpdateId {
66-
contents: UpdateOrigin,
73+
pub(crate) contents: UpdateOrigin,
6774
}
6875

6976
impl MonitorUpdateId {

lightning/src/util/test_utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::chain::chaininterface;
1313
use crate::chain::chaininterface::ConfirmationTarget;
1414
use crate::chain::chaininterface::FEERATE_FLOOR_SATS_PER_KW;
1515
use crate::chain::chainmonitor;
16-
use crate::chain::chainmonitor::MonitorUpdateId;
16+
use crate::chain::chainmonitor::{MonitorUpdateId, UpdateOrigin};
1717
use crate::chain::channelmonitor;
1818
use crate::chain::channelmonitor::MonitorEvent;
1919
use crate::chain::transaction::OutPoint;
@@ -419,7 +419,8 @@ impl<Signer: sign::WriteableEcdsaChannelSigner> chainmonitor::Persist<Signer> fo
419419
if let Some(update_ret) = self.update_rets.lock().unwrap().pop_front() {
420420
ret = update_ret;
421421
}
422-
if update.is_none() {
422+
let is_chain_sync = if let UpdateOrigin::ChainSync(_) = update_id.contents { true } else { false };
423+
if is_chain_sync {
423424
self.chain_sync_monitor_persistences.lock().unwrap().entry(funding_txo).or_insert(HashSet::new()).insert(update_id);
424425
} else {
425426
self.offchain_monitor_updates.lock().unwrap().entry(funding_txo).or_insert(HashSet::new()).insert(update_id);

0 commit comments

Comments
 (0)