Skip to content

Commit da9273d

Browse files
committed
f reload channels differently
1 parent 0e7c7f2 commit da9273d

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -703,12 +703,13 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
703703

704704
let mut monitors = new_hash_map();
705705
let mut old_monitors = $old_monitors.latest_monitors.lock().unwrap();
706+
let mut use_old_mons = $use_old_mons;
706707
for (channel_id, mut prev_state) in old_monitors.drain() {
707-
let serialized_mon = if $use_old_mons % 3 == 0 {
708+
let serialized_mon = if use_old_mons % 3 == 0 {
708709
// Reload with the oldest `ChannelMonitor` (the one that we already told
709710
// `ChannelManager` we finished persisting).
710711
prev_state.persisted_monitor
711-
} else if $use_old_mons % 3 == 1 {
712+
} else if use_old_mons % 3 == 1 {
712713
// Reload with the second-oldest `ChannelMonitor`
713714
let old_mon = prev_state.persisted_monitor;
714715
prev_state.pending_monitors.drain(..).next().map(|(_, v)| v).unwrap_or(old_mon)
@@ -717,6 +718,8 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
717718
let old_mon = prev_state.persisted_monitor;
718719
prev_state.pending_monitors.pop().map(|(_, v)| v).unwrap_or(old_mon)
719720
};
721+
// Use a different value of `use_old_mons` if we have another monitor (only node B)
722+
use_old_mons /= 3;
720723
let mon = <(BlockHash, ChannelMonitor<TestChannelSigner>)>::read(
721724
&mut &serialized_mon[..],
722725
(&*$keys, &*$keys),
@@ -1511,7 +1514,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
15111514
0x26 => process_ev_noret!(2, true),
15121515
0x27 => process_ev_noret!(2, false),
15131516

1514-
0x2a | 0x2b | 0x2c => {
1517+
0xb0 | 0xb1 | 0xb2 => {
15151518
// Restart node A, picking among the in-flight `ChannelMonitor`s to use based on
15161519
// the value of `v` we're matching.
15171520
if !chan_a_disconnected {
@@ -1524,14 +1527,12 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
15241527
ab_events.clear();
15251528
ba_events.clear();
15261529
}
1527-
// Note that we ensure 0x2c represents "use oldest monitor" to retain backwards
1528-
// compatibility with existing fuzz corpuses by using setting (v + 1) % 3 == 0
15291530
let (new_node_a, new_monitor_a) =
1530-
reload_node!(node_a_ser, 0, monitor_a, v + 1, keys_manager_a, fee_est_a);
1531+
reload_node!(node_a_ser, 0, monitor_a, v, keys_manager_a, fee_est_a);
15311532
nodes[0] = new_node_a;
15321533
monitor_a = new_monitor_a;
15331534
},
1534-
0x28 | 0x29 | 0x2d => {
1535+
0xb3..=0xbb => {
15351536
// Restart node B, picking among the in-flight `ChannelMonitor`s to use based on
15361537
// the value of `v` we're matching.
15371538
if !chan_a_disconnected {
@@ -1555,8 +1556,8 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
15551556
nodes[1] = new_node_b;
15561557
monitor_b = new_monitor_b;
15571558
},
1558-
0x2e | 0x2f => {
1559-
// Restart node B, picking among the in-flight `ChannelMonitor`s to use based on
1559+
0xbc | 0xbd | 0xbe => {
1560+
// Restart node C, picking among the in-flight `ChannelMonitor`s to use based on
15601561
// the value of `v` we're matching.
15611562
if !chan_b_disconnected {
15621563
nodes[1].peer_disconnected(nodes[2].get_our_node_id());
@@ -1568,10 +1569,8 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
15681569
bc_events.clear();
15691570
cb_events.clear();
15701571
}
1571-
// Note that we ensure 0x2e represents "use oldest monitor" to retain backwards
1572-
// compatibility with existing fuzz corpuses by using setting (v + 2) % 3 == 0
15731572
let (new_node_c, new_monitor_c) =
1574-
reload_node!(node_c_ser, 2, monitor_c, v + 2, keys_manager_c, fee_est_c);
1573+
reload_node!(node_c_ser, 2, monitor_c, v, keys_manager_c, fee_est_c);
15751574
nodes[2] = new_node_c;
15761575
monitor_c = new_monitor_c;
15771576
},

0 commit comments

Comments
 (0)