Skip to content

Commit 897d45f

Browse files
committed
Add fuzzing coverage for quiescence
1 parent 85108dd commit 897d45f

File tree

1 file changed

+70
-34
lines changed

1 file changed

+70
-34
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 70 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,9 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
977977
lock_fundings!(nodes);
978978

979979
let chan_a = nodes[0].list_usable_channels()[0].short_channel_id.unwrap();
980+
let chan_a_id = nodes[0].list_usable_channels()[0].channel_id;
980981
let chan_b = nodes[2].list_usable_channels()[0].short_channel_id.unwrap();
982+
let chan_b_id = nodes[2].list_usable_channels()[0].channel_id;
981983

982984
let mut p_id: u8 = 0;
983985
let mut p_idx: u64 = 0;
@@ -1038,6 +1040,10 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
10381040
if Some(*node_id) == expect_drop_id { panic!("peer_disconnected should drop msgs bound for the disconnected peer"); }
10391041
*node_id == a_id
10401042
},
1043+
events::MessageSendEvent::SendStfu { ref node_id, .. } => {
1044+
if Some(*node_id) == expect_drop_id { panic!("peer_disconnected should drop msgs bound for the disconnected peer"); }
1045+
*node_id == a_id
1046+
},
10411047
events::MessageSendEvent::SendChannelReady { .. } => continue,
10421048
events::MessageSendEvent::SendAnnouncementSignatures { .. } => continue,
10431049
events::MessageSendEvent::SendChannelUpdate { ref node_id, ref msg } => {
@@ -1100,7 +1106,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11001106
for (idx, dest) in nodes.iter().enumerate() {
11011107
if dest.get_our_node_id() == node_id {
11021108
for update_add in update_add_htlcs.iter() {
1103-
out.locked_write(format!("Delivering update_add_htlc to node {}.\n", idx).as_bytes());
1109+
out.locked_write(format!("Delivering update_add_htlc from node {} to node {}.\n", $node, idx).as_bytes());
11041110
if !$corrupt_forward {
11051111
dest.handle_update_add_htlc(nodes[$node].get_our_node_id(), update_add);
11061112
} else {
@@ -1115,19 +1121,19 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11151121
}
11161122
}
11171123
for update_fulfill in update_fulfill_htlcs.iter() {
1118-
out.locked_write(format!("Delivering update_fulfill_htlc to node {}.\n", idx).as_bytes());
1124+
out.locked_write(format!("Delivering update_fulfill_htlc from node {} to node {}.\n", $node, idx).as_bytes());
11191125
dest.handle_update_fulfill_htlc(nodes[$node].get_our_node_id(), update_fulfill);
11201126
}
11211127
for update_fail in update_fail_htlcs.iter() {
1122-
out.locked_write(format!("Delivering update_fail_htlc to node {}.\n", idx).as_bytes());
1128+
out.locked_write(format!("Delivering update_fail_htlc from node {} to node {}.\n", $node, idx).as_bytes());
11231129
dest.handle_update_fail_htlc(nodes[$node].get_our_node_id(), update_fail);
11241130
}
11251131
for update_fail_malformed in update_fail_malformed_htlcs.iter() {
1126-
out.locked_write(format!("Delivering update_fail_malformed_htlc to node {}.\n", idx).as_bytes());
1132+
out.locked_write(format!("Delivering update_fail_malformed_htlc from node {} to node {}.\n", $node, idx).as_bytes());
11271133
dest.handle_update_fail_malformed_htlc(nodes[$node].get_our_node_id(), update_fail_malformed);
11281134
}
11291135
if let Some(msg) = update_fee {
1130-
out.locked_write(format!("Delivering update_fee to node {}.\n", idx).as_bytes());
1136+
out.locked_write(format!("Delivering update_fee from node {} to node {}.\n", $node, idx).as_bytes());
11311137
dest.handle_update_fee(nodes[$node].get_our_node_id(), &msg);
11321138
}
11331139
let processed_change = !update_add_htlcs.is_empty() || !update_fulfill_htlcs.is_empty() ||
@@ -1144,7 +1150,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11441150
} });
11451151
break;
11461152
}
1147-
out.locked_write(format!("Delivering commitment_signed to node {}.\n", idx).as_bytes());
1153+
out.locked_write(format!("Delivering commitment_signed from node {} to node {}.\n", $node, idx).as_bytes());
11481154
dest.handle_commitment_signed(nodes[$node].get_our_node_id(), &commitment_signed);
11491155
break;
11501156
}
@@ -1153,19 +1159,27 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11531159
events::MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
11541160
for (idx, dest) in nodes.iter().enumerate() {
11551161
if dest.get_our_node_id() == *node_id {
1156-
out.locked_write(format!("Delivering revoke_and_ack to node {}.\n", idx).as_bytes());
1162+
out.locked_write(format!("Delivering revoke_and_ack from node {} to node {}.\n", $node, idx).as_bytes());
11571163
dest.handle_revoke_and_ack(nodes[$node].get_our_node_id(), msg);
11581164
}
11591165
}
11601166
},
11611167
events::MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } => {
11621168
for (idx, dest) in nodes.iter().enumerate() {
11631169
if dest.get_our_node_id() == *node_id {
1164-
out.locked_write(format!("Delivering channel_reestablish to node {}.\n", idx).as_bytes());
1170+
out.locked_write(format!("Delivering channel_reestablish from node {} to node {}.\n", $node, idx).as_bytes());
11651171
dest.handle_channel_reestablish(nodes[$node].get_our_node_id(), msg);
11661172
}
11671173
}
11681174
},
1175+
events::MessageSendEvent::SendStfu { ref node_id, ref msg } => {
1176+
for (idx, dest) in nodes.iter().enumerate() {
1177+
if dest.get_our_node_id() == *node_id {
1178+
out.locked_write(format!("Delivering stfu from node {} to node {}.\n", $node, idx).as_bytes());
1179+
dest.handle_stfu(nodes[$node].get_our_node_id(), msg);
1180+
}
1181+
}
1182+
}
11691183
events::MessageSendEvent::SendChannelReady { .. } => {
11701184
// Can be generated as a reestablish response
11711185
},
@@ -1218,6 +1232,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
12181232
events::MessageSendEvent::UpdateHTLCs { .. } => {},
12191233
events::MessageSendEvent::SendRevokeAndACK { .. } => {},
12201234
events::MessageSendEvent::SendChannelReestablish { .. } => {},
1235+
events::MessageSendEvent::SendStfu { .. } => {},
12211236
events::MessageSendEvent::SendChannelReady { .. } => {},
12221237
events::MessageSendEvent::SendAnnouncementSignatures { .. } => {},
12231238
events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => {
@@ -1244,6 +1259,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
12441259
events::MessageSendEvent::UpdateHTLCs { .. } => {},
12451260
events::MessageSendEvent::SendRevokeAndACK { .. } => {},
12461261
events::MessageSendEvent::SendChannelReestablish { .. } => {},
1262+
events::MessageSendEvent::SendStfu { .. } => {},
12471263
events::MessageSendEvent::SendChannelReady { .. } => {},
12481264
events::MessageSendEvent::SendAnnouncementSignatures { .. } => {},
12491265
events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => {
@@ -1687,6 +1703,11 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
16871703
nodes[2].maybe_update_chan_fees();
16881704
},
16891705

1706+
0xa0 => nodes[0].maybe_propose_quiescence(&nodes[1].get_our_node_id(), &chan_a_id),
1707+
0xa1 => nodes[1].maybe_propose_quiescence(&nodes[0].get_our_node_id(), &chan_a_id),
1708+
0xa2 => nodes[1].maybe_propose_quiescence(&nodes[2].get_our_node_id(), &chan_b_id),
1709+
0xa3 => nodes[2].maybe_propose_quiescence(&nodes[1].get_our_node_id(), &chan_b_id),
1710+
16901711
0xf0 => complete_monitor_update(&monitor_a, &chan_1_id, &complete_first),
16911712
0xf1 => complete_monitor_update(&monitor_a, &chan_1_id, &complete_second),
16921713
0xf2 => complete_monitor_update(&monitor_a, &chan_1_id, &Vec::pop),
@@ -1752,34 +1773,49 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
17521773
chan_b_disconnected = false;
17531774
}
17541775

1755-
for i in 0..std::usize::MAX {
1756-
if i == 100 {
1757-
panic!("It may take may iterations to settle the state, but it should not take forever");
1758-
}
1759-
// Then, make sure any current forwards make their way to their destination
1760-
if process_msg_events!(0, false, ProcessMessages::AllMessages) {
1761-
continue;
1762-
}
1763-
if process_msg_events!(1, false, ProcessMessages::AllMessages) {
1764-
continue;
1765-
}
1766-
if process_msg_events!(2, false, ProcessMessages::AllMessages) {
1767-
continue;
1768-
}
1769-
// ...making sure any pending PendingHTLCsForwardable events are handled and
1770-
// payments claimed.
1771-
if process_events!(0, false) {
1772-
continue;
1773-
}
1774-
if process_events!(1, false) {
1775-
continue;
1776-
}
1777-
if process_events!(2, false) {
1778-
continue;
1779-
}
1780-
break;
1776+
macro_rules! process_all_events {
1777+
() => {
1778+
for i in 0..std::usize::MAX {
1779+
if i == 100 {
1780+
panic!("It may take may iterations to settle the state, but it should not take forever");
1781+
}
1782+
// Then, make sure any current forwards make their way to their destination
1783+
if process_msg_events!(0, false, ProcessMessages::AllMessages) {
1784+
continue;
1785+
}
1786+
if process_msg_events!(1, false, ProcessMessages::AllMessages) {
1787+
continue;
1788+
}
1789+
if process_msg_events!(2, false, ProcessMessages::AllMessages) {
1790+
continue;
1791+
}
1792+
// ...making sure any pending PendingHTLCsForwardable events are handled and
1793+
// payments claimed.
1794+
if process_events!(0, false) {
1795+
continue;
1796+
}
1797+
if process_events!(1, false) {
1798+
continue;
1799+
}
1800+
if process_events!(2, false) {
1801+
continue;
1802+
}
1803+
break;
1804+
}
1805+
};
17811806
}
17821807

1808+
// At this point, we may be pending quiescence, so we'll process all messages to
1809+
// ensure we can complete its handshake. We'll then exit quiescence and process all
1810+
// messages again, to resolve any pending HTLCs (only irrevocably committed ones)
1811+
// before attempting to send more payments.
1812+
process_all_events!();
1813+
nodes[0].exit_quiescence(&nodes[1].get_our_node_id(), &chan_a_id).unwrap();
1814+
nodes[1].exit_quiescence(&nodes[0].get_our_node_id(), &chan_a_id).unwrap();
1815+
nodes[1].exit_quiescence(&nodes[2].get_our_node_id(), &chan_b_id).unwrap();
1816+
nodes[2].exit_quiescence(&nodes[1].get_our_node_id(), &chan_b_id).unwrap();
1817+
process_all_events!();
1818+
17831819
// Finally, make sure that at least one end of each channel can make a substantial payment
17841820
assert!(
17851821
send_payment(&nodes[0], &nodes[1], chan_a, 10_000_000, &mut p_id, &mut p_idx)

0 commit comments

Comments
 (0)