Skip to content

Commit 87b6879

Browse files
committed
Drop MonitorUpdateErr in favor of opaque errors.
We don't expect users to ever change behavior based on the string contained in a `MonitorUpdateErr`, except log it, so there's little reason to not just log it ourselves and return a `()` for errors. We do so here, simplifying the callsite in `ChainMonitor` as well.
1 parent 25542b8 commit 87b6879

File tree

2 files changed

+19
-29
lines changed

2 files changed

+19
-29
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,8 @@ where C::Target: chain::Filter,
639639
let monitor = &monitor_state.monitor;
640640
log_trace!(self.logger, "Updating ChannelMonitor for channel {}", log_funding_info!(monitor));
641641
let update_res = monitor.update_monitor(&update, &self.broadcaster, &self.fee_estimator, &self.logger);
642-
if let Err(e) = &update_res {
643-
log_error!(self.logger, "Failed to update ChannelMonitor for channel {}: {:?}", log_funding_info!(monitor), e);
642+
if update_res.is_err() {
643+
log_error!(self.logger, "Failed to update ChannelMonitor for channel {}.", log_funding_info!(monitor));
644644
}
645645
// Even if updating the monitor returns an error, the monitor's state will
646646
// still be changed. So, persist the updated monitor despite the error.

lightning/src/chain/channelmonitor.rs

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,6 @@ impl Readable for ChannelMonitorUpdate {
115115
}
116116
}
117117

118-
/// General Err type for ChannelMonitor actions. Generally, this implies that the data provided is
119-
/// inconsistent with the ChannelMonitor being called. eg for ChannelMonitor::update_monitor this
120-
/// means you tried to update a monitor for a different channel or the ChannelMonitorUpdate was
121-
/// corrupted.
122-
/// Contains a developer-readable error message.
123-
#[derive(Clone, Debug)]
124-
pub struct MonitorUpdateError(pub &'static str);
125-
126118
/// An event to be processed by the ChannelManager.
127119
#[derive(Clone, PartialEq)]
128120
pub enum MonitorEvent {
@@ -1052,7 +1044,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
10521044
}
10531045

10541046
#[cfg(test)]
1055-
fn provide_secret(&self, idx: u64, secret: [u8; 32]) -> Result<(), MonitorUpdateError> {
1047+
fn provide_secret(&self, idx: u64, secret: [u8; 32]) -> Result<(), &'static str> {
10561048
self.inner.lock().unwrap().provide_secret(idx, secret)
10571049
}
10581050

@@ -1074,12 +1066,10 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
10741066

10751067
#[cfg(test)]
10761068
fn provide_latest_holder_commitment_tx(
1077-
&self,
1078-
holder_commitment_tx: HolderCommitmentTransaction,
1069+
&self, holder_commitment_tx: HolderCommitmentTransaction,
10791070
htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>,
1080-
) -> Result<(), MonitorUpdateError> {
1081-
self.inner.lock().unwrap().provide_latest_holder_commitment_tx(
1082-
holder_commitment_tx, htlc_outputs)
1071+
) -> Result<(), ()> {
1072+
self.inner.lock().unwrap().provide_latest_holder_commitment_tx(holder_commitment_tx, htlc_outputs).map_err(|_| ())
10831073
}
10841074

10851075
#[cfg(test)]
@@ -1120,7 +1110,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
11201110
broadcaster: &B,
11211111
fee_estimator: &F,
11221112
logger: &L,
1123-
) -> Result<(), MonitorUpdateError>
1113+
) -> Result<(), ()>
11241114
where
11251115
B::Target: BroadcasterInterface,
11261116
F::Target: FeeEstimator,
@@ -1695,9 +1685,9 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16951685
/// Inserts a revocation secret into this channel monitor. Prunes old preimages if neither
16961686
/// needed by holder commitment transactions HTCLs nor by counterparty ones. Unless we haven't already seen
16971687
/// counterparty commitment transaction's secret, they are de facto pruned (we can use revocation key).
1698-
fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), MonitorUpdateError> {
1688+
fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), &'static str> {
16991689
if let Err(()) = self.commitment_secrets.provide_secret(idx, secret) {
1700-
return Err(MonitorUpdateError("Previous secret did not match new one"));
1690+
return Err("Previous secret did not match new one");
17011691
}
17021692

17031693
// Prune HTLCs from the previous counterparty commitment tx so we don't generate failure/fulfill
@@ -1789,7 +1779,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
17891779
/// is important that any clones of this channel monitor (including remote clones) by kept
17901780
/// up-to-date as our holder commitment transaction is updated.
17911781
/// Panics if set_on_holder_tx_csv has never been called.
1792-
fn provide_latest_holder_commitment_tx(&mut self, holder_commitment_tx: HolderCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>) -> Result<(), MonitorUpdateError> {
1782+
fn provide_latest_holder_commitment_tx(&mut self, holder_commitment_tx: HolderCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>) -> Result<(), &'static str> {
17931783
// block for Rust 1.34 compat
17941784
let mut new_holder_commitment_tx = {
17951785
let trusted_tx = holder_commitment_tx.trust();
@@ -1812,7 +1802,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18121802
mem::swap(&mut new_holder_commitment_tx, &mut self.current_holder_commitment_tx);
18131803
self.prev_holder_signed_commitment_tx = Some(new_holder_commitment_tx);
18141804
if self.holder_tx_signed {
1815-
return Err(MonitorUpdateError("Latest holder commitment signed has already been signed, update is rejected"));
1805+
return Err("Latest holder commitment signed has already been signed, update is rejected");
18161806
}
18171807
Ok(())
18181808
}
@@ -1876,7 +1866,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18761866
self.pending_monitor_events.push(MonitorEvent::CommitmentTxConfirmed(self.funding_info.0));
18771867
}
18781868

1879-
pub fn update_monitor<B: Deref, F: Deref, L: Deref>(&mut self, updates: &ChannelMonitorUpdate, broadcaster: &B, fee_estimator: &F, logger: &L) -> Result<(), MonitorUpdateError>
1869+
pub fn update_monitor<B: Deref, F: Deref, L: Deref>(&mut self, updates: &ChannelMonitorUpdate, broadcaster: &B, fee_estimator: &F, logger: &L) -> Result<(), ()>
18801870
where B::Target: BroadcasterInterface,
18811871
F::Target: FeeEstimator,
18821872
L::Target: Logger,
@@ -1902,8 +1892,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
19021892
if self.lockdown_from_offchain { panic!(); }
19031893
if let Err(e) = self.provide_latest_holder_commitment_tx(commitment_tx.clone(), htlc_outputs.clone()) {
19041894
log_error!(logger, "Providing latest holder commitment transaction failed/was refused:");
1905-
log_error!(logger, " {}", e.0);
1906-
ret = Err(e);
1895+
log_error!(logger, " {}", e);
1896+
ret = Err(());
19071897
}
19081898
}
19091899
ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo { commitment_txid, htlc_outputs, commitment_number, their_revocation_point } => {
@@ -1918,8 +1908,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
19181908
log_trace!(logger, "Updating ChannelMonitor with commitment secret");
19191909
if let Err(e) = self.provide_secret(*idx, *secret) {
19201910
log_error!(logger, "Providing latest counterparty commitment secret failed/was refused:");
1921-
log_error!(logger, " {}", e.0);
1922-
ret = Err(e);
1911+
log_error!(logger, " {}", e);
1912+
ret = Err(());
19231913
}
19241914
},
19251915
ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast } => {
@@ -1947,9 +1937,9 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
19471937
self.latest_update_id = updates.update_id;
19481938

19491939
if ret.is_ok() && self.funding_spend_seen {
1950-
ret = Err(MonitorUpdateError("Counterparty attempted to update commitment after funding was spent"));
1951-
}
1952-
ret
1940+
log_error!(logger, "Refusing Channel Monitor Update as counterparty attempted to update commitment after funding was spent");
1941+
Err(())
1942+
} else { ret }
19531943
}
19541944

19551945
pub fn get_latest_update_id(&self) -> u64 {

0 commit comments

Comments
 (0)