Skip to content

Commit d808581

Browse files
committed
Add APIError::IncompatibleShutdownScript
1 parent 93cd3a5 commit d808581

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ fn check_api_err(api_err: APIError) {
253253
APIError::MonitorUpdateFailed => {
254254
// We can (obviously) temp-fail a monitor update
255255
},
256+
APIError::IncompatibleShutdownScript { .. } => panic!("Cannot send an incompatible shutdown script"),
256257
}
257258
}
258259
#[inline]

lightning/src/ln/channel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ impl<Signer: Sign> Channel<Signer> {
601601
} else { None };
602602

603603
if let Some(shutdown_scriptpubkey) = &shutdown_scriptpubkey {
604-
if !shutdown_scriptpubkey.is_compatible(their_features) {
605-
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey) });
604+
if !shutdown_scriptpubkey.is_compatible(&their_features) {
605+
return Err(APIError::IncompatibleShutdownScript { script: shutdown_scriptpubkey.clone() });
606606
}
607607
}
608608

@@ -4474,7 +4474,7 @@ impl<Signer: Sign> Channel<Signer> {
44744474
None => {
44754475
let shutdown_scriptpubkey = keys_provider.get_shutdown_scriptpubkey();
44764476
if !shutdown_scriptpubkey.is_compatible(their_features) {
4477-
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey) });
4477+
return Err(APIError::IncompatibleShutdownScript { script: shutdown_scriptpubkey.clone() });
44784478
}
44794479
self.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
44804480
true

lightning/src/util/errors.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
//! Error types live here.
1111
12+
use ln::script::ShutdownScript;
13+
1214
use alloc::string::String;
1315
use core::fmt;
1416

@@ -47,6 +49,15 @@ pub enum APIError {
4749
/// An attempt to call watch/update_channel returned an Err (ie you did this!), causing the
4850
/// attempted action to fail.
4951
MonitorUpdateFailed,
52+
/// [`KeysInterface::get_shutdown_scriptpubkey`] returned a shutdown scriptpubkey incompatible
53+
/// with the channel counterparty as negotiated in [`InitFeatures`].
54+
///
55+
/// [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey
56+
/// [`InitFeatures`]: crate::ln::features::InitFeatures
57+
IncompatibleShutdownScript {
58+
/// The incompatible shutdown script.
59+
script: ShutdownScript,
60+
},
5061
}
5162

5263
impl fmt::Debug for APIError {
@@ -57,6 +68,9 @@ impl fmt::Debug for APIError {
5768
APIError::RouteError {ref err} => f.write_str(err),
5869
APIError::ChannelUnavailable {ref err} => f.write_str(err),
5970
APIError::MonitorUpdateFailed => f.write_str("Client indicated a channel monitor update failed"),
71+
APIError::IncompatibleShutdownScript { ref script } => {
72+
write!(f, "Provided a scriptpubkey format not accepted by peer: {}", script)
73+
},
6074
}
6175
}
6276
}

0 commit comments

Comments
 (0)