Skip to content

Commit 090e09f

Browse files
authored
Merge pull request #4634 from wpaulino/restore-splicing-fuzzing
Restore splice coverage in chanmon_consistency fuzz target
2 parents b7f58cd + f0ce340 commit 090e09f

7 files changed

Lines changed: 56 additions & 47 deletions

File tree

fuzz/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,5 @@ check-cfg = [
4343
"cfg(fuzzing)",
4444
"cfg(secp256k1_fuzz)",
4545
"cfg(hashes_fuzz)",
46-
"cfg(splicing)",
4746
"cfg(chacha20_poly1305_fuzz)"
4847
]

fuzz/src/chanmon_consistency.rs

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -720,10 +720,11 @@ impl SignerProvider for KeyProvider {
720720

721721
// Since this fuzzer is only concerned with live-channel operations, we don't need to worry about
722722
// any signer operations that come after a force close.
723-
const SUPPORTED_SIGNER_OPS: [SignerOp; 3] = [
723+
const SUPPORTED_SIGNER_OPS: [SignerOp; 4] = [
724724
SignerOp::SignCounterpartyCommitment,
725725
SignerOp::GetPerCommitmentPoint,
726726
SignerOp::ReleaseCommitmentSecret,
727+
SignerOp::SignSpliceSharedInput,
727728
];
728729

729730
impl KeyProvider {
@@ -769,19 +770,19 @@ type ChanMan<'a> = ChannelManager<
769770
>;
770771

771772
#[inline]
772-
fn assert_action_timeout_awaiting_response(action: &msgs::ErrorAction) {
773+
fn assert_disconnect_action(action: &msgs::ErrorAction) -> (&msgs::WarningMessage, bool) {
773774
// Since sending/receiving messages may be delayed, `timer_tick_occurred` may cause a node to
774775
// disconnect their counterparty if they're expecting a timely response.
775-
assert!(
776-
matches!(
777-
action,
778-
msgs::ErrorAction::DisconnectPeerWithWarning { msg }
779-
if msg.data.contains("Disconnecting due to timeout awaiting response")
780-
|| msg.data.contains("already sent splice_locked, cannot RBF")
781-
),
782-
"Expected timeout disconnect, got: {:?}",
783-
action,
784-
);
776+
if let msgs::ErrorAction::DisconnectPeerWithWarning { ref msg } = action {
777+
let is_quiescent_msg = msg.data.contains("already sent splice_locked, cannot RBF");
778+
if !msg.data.contains("Disconnecting due to timeout awaiting response") && !is_quiescent_msg
779+
{
780+
panic!("Unexpected disconnect case: {}", msg.data);
781+
}
782+
(msg, is_quiescent_msg)
783+
} else {
784+
panic!("Expected disconnect, got: {:?}", action);
785+
}
785786
}
786787

787788
#[derive(Clone, Copy, PartialEq)]
@@ -1286,7 +1287,7 @@ impl EventQueues {
12861287
*node_id == a_id
12871288
},
12881289
MessageSendEvent::HandleError { ref action, ref node_id } => {
1289-
assert_action_timeout_awaiting_response(action);
1290+
assert_disconnect_action(action);
12901291
if Some(*node_id) == expect_drop_id {
12911292
panic!(
12921293
"peer_disconnected should drop msgs bound for the disconnected peer"
@@ -1335,7 +1336,7 @@ impl EventQueues {
13351336
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
13361337
MessageSendEvent::SendChannelUpdate { .. } => {},
13371338
MessageSendEvent::HandleError { ref action, .. } => {
1338-
assert_action_timeout_awaiting_response(action);
1339+
assert_disconnect_action(action);
13391340
},
13401341
_ => panic!("Unhandled message event"),
13411342
}
@@ -1354,7 +1355,7 @@ impl EventQueues {
13541355
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
13551356
MessageSendEvent::SendChannelUpdate { .. } => {},
13561357
MessageSendEvent::HandleError { ref action, .. } => {
1357-
assert_action_timeout_awaiting_response(action);
1358+
assert_disconnect_action(action);
13581359
},
13591360
_ => panic!("Unhandled message event"),
13601361
}
@@ -2645,8 +2646,16 @@ impl<'a, Out: Output + MaybeSend + MaybeSync> Harness<'a, Out> {
26452646
nodes[dest_idx].handle_splice_locked(source_node_id, msg);
26462647
None
26472648
},
2648-
MessageSendEvent::HandleError { ref action, .. } => {
2649-
assert_action_timeout_awaiting_response(action);
2649+
MessageSendEvent::HandleError { ref action, ref node_id, .. } => {
2650+
let (msg, is_quiescent) = assert_disconnect_action(action);
2651+
let dest_idx = log_peer_message(node_idx, node_id, nodes, out, "warning");
2652+
if is_quiescent {
2653+
nodes[node_idx].node.exit_quiescence(node_id, &msg.channel_id).unwrap();
2654+
nodes[dest_idx]
2655+
.node
2656+
.exit_quiescence(&source_node_id, &msg.channel_id)
2657+
.unwrap();
2658+
}
26502659
None
26512660
},
26522661
MessageSendEvent::SendChannelReady { .. }
@@ -3117,59 +3126,35 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], out: Out) {
31173126
0x89 => harness.nodes[2].reset_fee_estimate(),
31183127

31193128
0xa0 => {
3120-
if !cfg!(splicing) {
3121-
break 'fuzz_loop;
3122-
}
31233129
let cp_node_id = harness.nodes[1].get_our_node_id();
31243130
harness.nodes[0].splice_in(&cp_node_id, &harness.chan_a_id());
31253131
},
31263132
0xa1 => {
3127-
if !cfg!(splicing) {
3128-
break 'fuzz_loop;
3129-
}
31303133
let cp_node_id = harness.nodes[0].get_our_node_id();
31313134
harness.nodes[1].splice_in(&cp_node_id, &harness.chan_a_id());
31323135
},
31333136
0xa2 => {
3134-
if !cfg!(splicing) {
3135-
break 'fuzz_loop;
3136-
}
31373137
let cp_node_id = harness.nodes[2].get_our_node_id();
31383138
harness.nodes[1].splice_in(&cp_node_id, &harness.chan_b_id());
31393139
},
31403140
0xa3 => {
3141-
if !cfg!(splicing) {
3142-
break 'fuzz_loop;
3143-
}
31443141
let cp_node_id = harness.nodes[1].get_our_node_id();
31453142
harness.nodes[2].splice_in(&cp_node_id, &harness.chan_b_id());
31463143
},
31473144

31483145
0xa4 => {
3149-
if !cfg!(splicing) {
3150-
break 'fuzz_loop;
3151-
}
31523146
let cp_node_id = harness.nodes[1].get_our_node_id();
31533147
harness.nodes[0].splice_out(&cp_node_id, &harness.chan_a_id());
31543148
},
31553149
0xa5 => {
3156-
if !cfg!(splicing) {
3157-
break 'fuzz_loop;
3158-
}
31593150
let cp_node_id = harness.nodes[0].get_our_node_id();
31603151
harness.nodes[1].splice_out(&cp_node_id, &harness.chan_a_id());
31613152
},
31623153
0xa6 => {
3163-
if !cfg!(splicing) {
3164-
break 'fuzz_loop;
3165-
}
31663154
let cp_node_id = harness.nodes[2].get_our_node_id();
31673155
harness.nodes[1].splice_out(&cp_node_id, &harness.chan_b_id());
31683156
},
31693157
0xa7 => {
3170-
if !cfg!(splicing) {
3171-
break 'fuzz_loop;
3172-
}
31733158
let cp_node_id = harness.nodes[1].get_our_node_id();
31743159
harness.nodes[2].splice_out(&cp_node_id, &harness.chan_b_id());
31753160
},
@@ -3298,6 +3283,32 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], out: Out) {
32983283
.enable_op_for_all_signers(SignerOp::ReleaseCommitmentSecret);
32993284
harness.nodes[2].signer_unblocked(None);
33003285
},
3286+
0xcf => {
3287+
harness.nodes[0]
3288+
.keys_manager
3289+
.enable_op_for_all_signers(SignerOp::SignSpliceSharedInput);
3290+
harness.nodes[0].signer_unblocked(None);
3291+
},
3292+
0xd0 => {
3293+
harness.nodes[1]
3294+
.keys_manager
3295+
.enable_op_for_all_signers(SignerOp::SignSpliceSharedInput);
3296+
let filter = Some((harness.nodes[0].get_our_node_id(), harness.chan_a_id()));
3297+
harness.nodes[1].signer_unblocked(filter);
3298+
},
3299+
0xd1 => {
3300+
harness.nodes[1]
3301+
.keys_manager
3302+
.enable_op_for_all_signers(SignerOp::SignSpliceSharedInput);
3303+
let filter = Some((harness.nodes[2].get_our_node_id(), harness.chan_b_id()));
3304+
harness.nodes[1].signer_unblocked(filter);
3305+
},
3306+
0xd2 => {
3307+
harness.nodes[2]
3308+
.keys_manager
3309+
.enable_op_for_all_signers(SignerOp::SignSpliceSharedInput);
3310+
harness.nodes[2].signer_unblocked(None);
3311+
},
33013312

33023313
0xf0 => harness.ab_link.complete_monitor_updates_for_node(
33033314
0,

fuzz/src/lsps_message.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use bitcoin::hashes::{sha256, Hash};
55
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
66
use bitcoin::Network;
77

8-
use lightning::chain::Filter;
98
use lightning::chain::{chainmonitor, BlockLocator};
109
use lightning::ln::channelmanager::{ChainParameters, ChannelManager};
1110
use lightning::ln::peer_handler::CustomMessageHandler;

lightning/src/ln/outbound_payment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
3838
use crate::util::errors::APIError;
3939
use crate::util::logger::{Logger, WithContext};
4040
use crate::util::ser::ReadableArgs;
41-
#[cfg(feature = "std")]
41+
#[cfg(all(feature = "std", not(fuzzing)))]
4242
use crate::util::time::Instant;
4343

4444
use core::fmt::{self, Display, Formatter};

lightning/src/ln/peer_channel_encryptor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ impl PeerChannelEncryptor {
556556
/// Encrypts the given message, returning the encrypted version.
557557
/// panics if the length of `message`, once encoded, is greater than 65535 or if the Noise
558558
/// handshake has not finished.
559-
pub fn encrypt_message<T: wire::Type>(&mut self, message: wire::Message<T>) -> Vec<u8> {
559+
pub(crate) fn encrypt_message<T: wire::Type>(&mut self, message: wire::Message<T>) -> Vec<u8> {
560560
// Allocate a buffer with 2KB, fitting most common messages. Reserve the first 16+2 bytes
561561
// for the 2-byte message type prefix and its MAC.
562562
let mut res = VecWriter(Vec::with_capacity(MSG_BUF_ALLOC_SIZE));

lightning/src/routing/gossip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use core::{cmp, fmt};
5757

5858
pub use lightning_types::routing::RoutingFees;
5959

60-
#[cfg(feature = "std")]
60+
#[cfg(all(feature = "std", not(fuzzing)))]
6161
use std::time::{SystemTime, UNIX_EPOCH};
6262

6363
/// We remove stale channel directional info two weeks after the last update, per BOLT 7's

lightning/src/util/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! A simple module which either re-exports [`std::time::Instant`] or a mocked version of it for
88
//! tests.
99
10-
#[cfg(not(test))]
10+
#[cfg(all(not(test), not(fuzzing)))]
1111
pub use std::time::Instant;
1212
#[cfg(test)]
1313
pub use test::Instant;

0 commit comments

Comments
 (0)