mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 15:02:20 +01:00
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.
This commit is contained in:
parent
db41b87d31
commit
13eac47ed9
2 changed files with 27 additions and 14 deletions
|
@ -47,23 +47,35 @@ use core::ops::Deref;
|
|||
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
use bitcoin::secp256k1::PublicKey;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
||||
/// A specific update's ID stored in a `MonitorUpdateId`, separated out to make the contents
|
||||
/// entirely opaque.
|
||||
enum UpdateOrigin {
|
||||
/// An update that was generated by the `ChannelManager` (via our `chain::Watch`
|
||||
/// implementation). This corresponds to an actual [`ChannelMonitorUpdate::update_id`] field
|
||||
/// and [`ChannelMonitor::get_latest_update_id`].
|
||||
OffChain(u64),
|
||||
/// An update that was generated during blockchain processing. The ID here is specific to the
|
||||
/// generating [`ChainMonitor`] and does *not* correspond to any on-disk IDs.
|
||||
ChainSync(u64),
|
||||
mod update_origin {
|
||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
||||
/// A specific update's ID stored in a `MonitorUpdateId`, separated out to make the contents
|
||||
/// entirely opaque.
|
||||
pub(crate) enum UpdateOrigin {
|
||||
/// An update that was generated by the `ChannelManager` (via our [`crate::chain::Watch`]
|
||||
/// implementation). This corresponds to an actual [ChannelMonitorUpdate::update_id] field
|
||||
/// and [ChannelMonitor::get_latest_update_id].
|
||||
///
|
||||
/// [ChannelMonitor::get_latest_update_id]: crate::chain::channelmonitor::ChannelMonitor::get_latest_update_id
|
||||
/// [ChannelMonitorUpdate::update_id]: crate::chain::channelmonitor::ChannelMonitorUpdate::update_id
|
||||
OffChain(u64),
|
||||
/// An update that was generated during blockchain processing. The ID here is specific to the
|
||||
/// generating [ChannelMonitor] and does *not* correspond to any on-disk IDs.
|
||||
///
|
||||
/// [ChannelMonitor]: crate::chain::channelmonitor::ChannelMonitor
|
||||
ChainSync(u64),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "_test_utils", test))]
|
||||
pub(crate) use update_origin::UpdateOrigin;
|
||||
#[cfg(not(any(feature = "_test_utils", test)))]
|
||||
use update_origin::UpdateOrigin;
|
||||
|
||||
/// An opaque identifier describing a specific [`Persist`] method call.
|
||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
||||
pub struct MonitorUpdateId {
|
||||
contents: UpdateOrigin,
|
||||
pub(crate) contents: UpdateOrigin,
|
||||
}
|
||||
|
||||
impl MonitorUpdateId {
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::chain::chaininterface;
|
|||
use crate::chain::chaininterface::ConfirmationTarget;
|
||||
use crate::chain::chaininterface::FEERATE_FLOOR_SATS_PER_KW;
|
||||
use crate::chain::chainmonitor;
|
||||
use crate::chain::chainmonitor::MonitorUpdateId;
|
||||
use crate::chain::chainmonitor::{MonitorUpdateId, UpdateOrigin};
|
||||
use crate::chain::channelmonitor;
|
||||
use crate::chain::channelmonitor::MonitorEvent;
|
||||
use crate::chain::transaction::OutPoint;
|
||||
|
@ -419,7 +419,8 @@ impl<Signer: sign::WriteableEcdsaChannelSigner> chainmonitor::Persist<Signer> fo
|
|||
if let Some(update_ret) = self.update_rets.lock().unwrap().pop_front() {
|
||||
ret = update_ret;
|
||||
}
|
||||
if update.is_none() {
|
||||
let is_chain_sync = if let UpdateOrigin::ChainSync(_) = update_id.contents { true } else { false };
|
||||
if is_chain_sync {
|
||||
self.chain_sync_monitor_persistences.lock().unwrap().entry(funding_txo).or_insert(HashSet::new()).insert(update_id);
|
||||
} else {
|
||||
self.offchain_monitor_updates.lock().unwrap().entry(funding_txo).or_insert(HashSet::new()).insert(update_id);
|
||||
|
|
Loading…
Add table
Reference in a new issue