mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-27 00:06:34 +01:00
This resolves several user complaints (and issues in the sample node) where startup is substantially delayed as we're always waiting for the chain data to sync. Further, in an upcoming PR, we'll be reloading pending payments from ChannelMonitors on restart, at which point we'll need the change here which avoids handling events until after the user has confirmed the `ChannelMonitor` has been persisted to disk. It will avoid a race where we * send a payment/HTLC (persisting the monitor to disk with the HTLC pending), * force-close the channel, removing the channel entry from the ChannelManager entirely, * persist the ChannelManager, * connect a block which contains a fulfill of the HTLC, generating a claim event, * handle the claim event while the `ChannelMonitor` is being persisted, * persist the ChannelManager (before the CHannelMonitor is persisted fully), * restart, reloading the HTLC as a pending payment in the ChannelManager, which now has no references to it except from the ChannelMonitor which still has the pending HTLC, * replay the block connection, generating a duplicate PaymentSent event.
20 lines
952 B
Rust
20 lines
952 B
Rust
use lightning::chain;
|
|
use lightning::chain::{chainmonitor, channelmonitor};
|
|
use lightning::chain::chainmonitor::MonitorUpdateId;
|
|
use lightning::chain::transaction::OutPoint;
|
|
use lightning::util::enforcing_trait_impls::EnforcingSigner;
|
|
|
|
use std::sync::Mutex;
|
|
|
|
pub struct TestPersister {
|
|
pub update_ret: Mutex<Result<(), chain::ChannelMonitorUpdateErr>>,
|
|
}
|
|
impl chainmonitor::Persist<EnforcingSigner> for TestPersister {
|
|
fn persist_new_channel(&self, _funding_txo: OutPoint, _data: &channelmonitor::ChannelMonitor<EnforcingSigner>, _update_id: MonitorUpdateId) -> Result<(), chain::ChannelMonitorUpdateErr> {
|
|
self.update_ret.lock().unwrap().clone()
|
|
}
|
|
|
|
fn update_persisted_channel(&self, _funding_txo: OutPoint, _update: &Option<channelmonitor::ChannelMonitorUpdate>, _data: &channelmonitor::ChannelMonitor<EnforcingSigner>, _update_id: MonitorUpdateId) -> Result<(), chain::ChannelMonitorUpdateErr> {
|
|
self.update_ret.lock().unwrap().clone()
|
|
}
|
|
}
|