Skip to content

Commit 6d69419

Browse files
Update chanmon fuzzer to include small payment actions.
This change should allow the fuzzer to catch more edge cases, such as channel reserve checks that cut it close when sending payments.
1 parent 0495fe5 commit 6d69419

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ pub fn do_test(data: &[u8]) {
405405

406406
loop {
407407
macro_rules! send_payment {
408-
($source: expr, $dest: expr) => { {
408+
($source: expr, $dest: expr, $amt: expr) => { {
409409
let payment_hash = Sha256::hash(&[payment_id; 1]);
410410
payment_id = payment_id.wrapping_add(1);
411411
if let Err(_) = $source.send_payment(&Route {
@@ -414,15 +414,15 @@ pub fn do_test(data: &[u8]) {
414414
node_features: NodeFeatures::empty(),
415415
short_channel_id: $dest.1,
416416
channel_features: ChannelFeatures::empty(),
417-
fee_msat: 5000000,
417+
fee_msat: $amt,
418418
cltv_expiry_delta: 200,
419419
}]],
420420
}, PaymentHash(payment_hash.into_inner()), &None) {
421421
// Probably ran out of funds
422422
test_return!();
423423
}
424424
} };
425-
($source: expr, $middle: expr, $dest: expr) => { {
425+
($source: expr, $middle: expr, $dest: expr, $amt: expr) => { {
426426
let payment_hash = Sha256::hash(&[payment_id; 1]);
427427
payment_id = payment_id.wrapping_add(1);
428428
if let Err(_) = $source.send_payment(&Route {
@@ -438,7 +438,7 @@ pub fn do_test(data: &[u8]) {
438438
node_features: NodeFeatures::empty(),
439439
short_channel_id: $dest.1,
440440
channel_features: ChannelFeatures::empty(),
441-
fee_msat: 5000000,
441+
fee_msat: $amt,
442442
cltv_expiry_delta: 200,
443443
}]],
444444
}, PaymentHash(payment_hash.into_inner()), &None) {
@@ -688,12 +688,12 @@ pub fn do_test(data: &[u8]) {
688688
nodes[2].channel_monitor_updated(&chan_2_funding, *id);
689689
}
690690
},
691-
0x09 => send_payment!(nodes[0], (&nodes[1], chan_a)),
692-
0x0a => send_payment!(nodes[1], (&nodes[0], chan_a)),
693-
0x0b => send_payment!(nodes[1], (&nodes[2], chan_b)),
694-
0x0c => send_payment!(nodes[2], (&nodes[1], chan_b)),
695-
0x0d => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b)),
696-
0x0e => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a)),
691+
0x09 => send_payment!(nodes[0], (&nodes[1], chan_a), 5_000_000),
692+
0x0a => send_payment!(nodes[1], (&nodes[0], chan_a), 5_000_000),
693+
0x0b => send_payment!(nodes[1], (&nodes[2], chan_b), 5_000_000),
694+
0x0c => send_payment!(nodes[2], (&nodes[1], chan_b), 5_000_000),
695+
0x0d => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 5_000_000),
696+
0x0e => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 5_000_000),
697697
0x0f => {
698698
if !chan_a_disconnected {
699699
nodes[0].peer_disconnected(&nodes[1].get_our_node_id(), false);
@@ -776,8 +776,26 @@ pub fn do_test(data: &[u8]) {
776776
nodes[2] = node_c.clone();
777777
monitor_c = new_monitor_c;
778778
},
779-
0x22 => send_payment_with_secret!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b)),
780-
0x23 => send_payment_with_secret!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a)),
779+
0x22 => send_payment!(nodes[0], (&nodes[1], chan_a), 10),
780+
0x23 => send_payment!(nodes[1], (&nodes[0], chan_a), 10),
781+
0x25 => send_payment!(nodes[1], (&nodes[2], chan_b), 10),
782+
0x26 => send_payment!(nodes[2], (&nodes[1], chan_b), 10),
783+
0x27 => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 10),
784+
0x28 => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 10),
785+
0x29 => send_payment!(nodes[0], (&nodes[1], chan_a), 1_000),
786+
0x2a => send_payment!(nodes[1], (&nodes[0], chan_a), 1_000),
787+
0x2b => send_payment!(nodes[1], (&nodes[2], chan_b), 1_000),
788+
0x2c => send_payment!(nodes[2], (&nodes[1], chan_b), 1_000),
789+
0x2d => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 1_000),
790+
0x2e => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 1_000),
791+
0x2f => send_payment!(nodes[0], (&nodes[1], chan_a), 100_000),
792+
0x30 => send_payment!(nodes[1], (&nodes[0], chan_a), 100_000),
793+
0x31 => send_payment!(nodes[1], (&nodes[2], chan_b), 100_000),
794+
0x32 => send_payment!(nodes[2], (&nodes[1], chan_b), 100_000),
795+
0x33 => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 100_000),
796+
0x34 => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 100_000),
797+
0x35 => send_payment_with_secret!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b)),
798+
0x36 => send_payment_with_secret!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a)),
781799
// 0x24 defined above
782800
_ => test_return!(),
783801
}

0 commit comments

Comments
 (0)