Skip to content

Commit cdba25f

Browse files
committed
Assert peer supports splicing before splicing channel
1 parent 109f715 commit cdba25f

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4774,8 +4774,17 @@ where
47744774
Err(e) => return Err(e),
47754775
};
47764776

4777-
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
4778-
let peer_state = &mut *peer_state_lock;
4777+
let mut peer_state = peer_state_mutex.lock().unwrap();
4778+
if !peer_state.latest_features.supports_splicing() {
4779+
return Err(APIError::ChannelUnavailable {
4780+
err: "Peer does not support splicing".to_owned(),
4781+
});
4782+
}
4783+
if !peer_state.latest_features.supports_quiescence() {
4784+
return Err(APIError::ChannelUnavailable {
4785+
err: "Peer does not support quiescence, a splicing prerequisite".to_owned(),
4786+
});
4787+
}
47794788

47804789
// Look for the channel
47814790
match peer_state.channel_by_id.entry(*channel_id) {

lightning/src/ln/splicing_tests.rs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use crate::events::bump_transaction::sync::WalletSourceSync;
1717
use crate::events::{ClosureReason, Event, FundingInfo, HTLCHandlingFailureType};
1818
use crate::ln::chan_utils;
1919
use crate::ln::channel::CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY;
20-
use crate::ln::channelmanager::{PaymentId, RecipientOnionFields, BREAKDOWN_TIMEOUT};
20+
use crate::ln::channelmanager::{
21+
provided_init_features, PaymentId, RecipientOnionFields, BREAKDOWN_TIMEOUT,
22+
};
2123
use crate::ln::functional_test_utils::*;
2224
use crate::ln::funding::{FundingTxInput, SpliceContribution};
2325
use crate::ln::msgs::{self, BaseMessageHandler, ChannelMessageHandler, MessageSendEvent};
@@ -30,6 +32,69 @@ use crate::util::test_channel_signer::SignerOp;
3032
use bitcoin::secp256k1::PublicKey;
3133
use bitcoin::{Amount, OutPoint as BitcoinOutPoint, ScriptBuf, Transaction, TxOut};
3234

35+
#[test]
36+
fn test_splicing_not_supported_api_error() {
37+
let chanmon_cfgs = create_chanmon_cfgs(2);
38+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
39+
let mut features = provided_init_features(&test_default_channel_config());
40+
features.clear_splicing();
41+
*node_cfgs[0].override_init_features.borrow_mut() = Some(features);
42+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
43+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
44+
45+
let node_id_0 = nodes[0].node.get_our_node_id();
46+
let node_id_1 = nodes[1].node.get_our_node_id();
47+
48+
let (_, _, channel_id, _) = create_announced_chan_between_nodes(&nodes, 0, 1);
49+
50+
let bs_contribution = SpliceContribution::SpliceIn {
51+
value: Amount::ZERO,
52+
inputs: Vec::new(),
53+
change_script: None,
54+
};
55+
56+
let res = nodes[1].node.splice_channel(
57+
&channel_id,
58+
&node_id_0,
59+
bs_contribution.clone(),
60+
0, // funding_feerate_per_kw,
61+
None, // locktime
62+
);
63+
match res {
64+
Err(APIError::ChannelUnavailable { err }) => {
65+
assert!(err.contains("Peer does not support splicing"))
66+
},
67+
_ => panic!("Wrong error {:?}", res.err().unwrap()),
68+
}
69+
70+
nodes[0].node.peer_disconnected(node_id_1);
71+
nodes[1].node.peer_disconnected(node_id_0);
72+
73+
let mut features = nodes[0].node.init_features();
74+
features.set_splicing_optional();
75+
features.clear_quiescence();
76+
*nodes[0].override_init_features.borrow_mut() = Some(features);
77+
78+
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
79+
reconnect_args.send_channel_ready = (true, true);
80+
reconnect_args.send_announcement_sigs = (true, true);
81+
reconnect_nodes(reconnect_args);
82+
83+
let res = nodes[1].node.splice_channel(
84+
&channel_id,
85+
&node_id_0,
86+
bs_contribution,
87+
0, // funding_feerate_per_kw,
88+
None, // locktime
89+
);
90+
match res {
91+
Err(APIError::ChannelUnavailable { err }) => {
92+
assert!(err.contains("Peer does not support quiescence, a splicing prerequisite"))
93+
},
94+
_ => panic!("Wrong error {:?}", res.err().unwrap()),
95+
}
96+
}
97+
3398
#[test]
3499
fn test_v1_splice_in_negative_insufficient_inputs() {
35100
let chanmon_cfgs = create_chanmon_cfgs(2);

0 commit comments

Comments
 (0)