Skip to content

Commit de13216

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 279ae3d commit de13216

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

fuzz/src/chanmon_consistency.rs

+30-12
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
408408

409409
loop {
410410
macro_rules! send_payment {
411-
($source: expr, $dest: expr) => { {
411+
($source: expr, $dest: expr, $amt: expr) => { {
412412
let payment_hash = Sha256::hash(&[payment_id; 1]);
413413
payment_id = payment_id.wrapping_add(1);
414414
if let Err(_) = $source.send_payment(&Route {
@@ -417,15 +417,15 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
417417
node_features: NodeFeatures::empty(),
418418
short_channel_id: $dest.1,
419419
channel_features: ChannelFeatures::empty(),
420-
fee_msat: 5000000,
420+
fee_msat: $amt,
421421
cltv_expiry_delta: 200,
422422
}]],
423423
}, PaymentHash(payment_hash.into_inner()), &None) {
424424
// Probably ran out of funds
425425
test_return!();
426426
}
427427
} };
428-
($source: expr, $middle: expr, $dest: expr) => { {
428+
($source: expr, $middle: expr, $dest: expr, $amt: expr) => { {
429429
let payment_hash = Sha256::hash(&[payment_id; 1]);
430430
payment_id = payment_id.wrapping_add(1);
431431
if let Err(_) = $source.send_payment(&Route {
@@ -441,7 +441,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
441441
node_features: NodeFeatures::empty(),
442442
short_channel_id: $dest.1,
443443
channel_features: ChannelFeatures::empty(),
444-
fee_msat: 5000000,
444+
fee_msat: $amt,
445445
cltv_expiry_delta: 200,
446446
}]],
447447
}, PaymentHash(payment_hash.into_inner()), &None) {
@@ -644,12 +644,12 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
644644
});
645645
for event in events.drain(..) {
646646
match event {
647-
events::Event::PaymentReceived { payment_hash, payment_secret, .. } => {
647+
events::Event::PaymentReceived { payment_hash, payment_secret, amt } => {
648648
if claim_set.insert(payment_hash.0) {
649649
if $fail {
650650
assert!(nodes[$node].fail_htlc_backwards(&payment_hash, &payment_secret));
651651
} else {
652-
assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0), &payment_secret, 5_000_000));
652+
assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0), &payment_secret, amt));
653653
}
654654
}
655655
},
@@ -691,12 +691,12 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
691691
nodes[2].channel_monitor_updated(&chan_2_funding, *id);
692692
}
693693
},
694-
0x09 => send_payment!(nodes[0], (&nodes[1], chan_a)),
695-
0x0a => send_payment!(nodes[1], (&nodes[0], chan_a)),
696-
0x0b => send_payment!(nodes[1], (&nodes[2], chan_b)),
697-
0x0c => send_payment!(nodes[2], (&nodes[1], chan_b)),
698-
0x0d => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b)),
699-
0x0e => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a)),
694+
0x09 => send_payment!(nodes[0], (&nodes[1], chan_a), 5_000_000),
695+
0x0a => send_payment!(nodes[1], (&nodes[0], chan_a), 5_000_000),
696+
0x0b => send_payment!(nodes[1], (&nodes[2], chan_b), 5_000_000),
697+
0x0c => send_payment!(nodes[2], (&nodes[1], chan_b), 5_000_000),
698+
0x0d => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 5_000_000),
699+
0x0e => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 5_000_000),
700700
0x0f => {
701701
if !chan_a_disconnected {
702702
nodes[0].peer_disconnected(&nodes[1].get_our_node_id(), false);
@@ -781,6 +781,24 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
781781
},
782782
0x22 => send_payment_with_secret!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b)),
783783
0x23 => send_payment_with_secret!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a)),
784+
0x25 => send_payment!(nodes[0], (&nodes[1], chan_a), 10),
785+
0x26 => send_payment!(nodes[1], (&nodes[0], chan_a), 10),
786+
0x27 => send_payment!(nodes[1], (&nodes[2], chan_b), 10),
787+
0x28 => send_payment!(nodes[2], (&nodes[1], chan_b), 10),
788+
0x29 => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 10),
789+
0x2a => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 10),
790+
0x2b => send_payment!(nodes[0], (&nodes[1], chan_a), 1_000),
791+
0x2c => send_payment!(nodes[1], (&nodes[0], chan_a), 1_000),
792+
0x2d => send_payment!(nodes[1], (&nodes[2], chan_b), 1_000),
793+
0x2e => send_payment!(nodes[2], (&nodes[1], chan_b), 1_000),
794+
0x2f => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 1_000),
795+
0x30 => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 1_000),
796+
0x31 => send_payment!(nodes[0], (&nodes[1], chan_a), 100_000),
797+
0x32 => send_payment!(nodes[1], (&nodes[0], chan_a), 100_000),
798+
0x33 => send_payment!(nodes[1], (&nodes[2], chan_b), 100_000),
799+
0x34 => send_payment!(nodes[2], (&nodes[1], chan_b), 100_000),
800+
0x35 => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 100_000),
801+
0x36 => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 100_000),
784802
// 0x24 defined above
785803
_ => test_return!(),
786804
}

0 commit comments

Comments
 (0)