Skip to content

Commit 4d0993f

Browse files
authored
Merge pull request #361 from TheBlueMatt/2019-07-cmfc-crash
Make chanmon_fail_consistency slightly less aggressive
2 parents 4e81d8d + a9aa3c3 commit 4d0993f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

fuzz/fuzz_targets/chanmon_fail_consistency.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use secp256k1::Secp256k1;
5252

5353
use std::mem;
5454
use std::cmp::Ordering;
55-
use std::collections::{HashSet, HashMap};
55+
use std::collections::{HashSet, hash_map, HashMap};
5656
use std::sync::{Arc,Mutex};
5757
use std::sync::atomic;
5858
use std::io::Cursor;
@@ -80,6 +80,7 @@ impl Writer for VecWriter {
8080
}
8181
}
8282

83+
static mut IN_RESTORE: bool = false;
8384
pub struct TestChannelMonitor {
8485
pub simple_monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint>>,
8586
pub update_ret: Mutex<Result<(), channelmonitor::ChannelMonitorUpdateErr>>,
@@ -107,7 +108,18 @@ impl channelmonitor::ManyChannelMonitor for TestChannelMonitor {
107108
let mut ser = VecWriter(Vec::new());
108109
monitor.write_for_disk(&mut ser).unwrap();
109110
self.latest_good_update.lock().unwrap().insert(funding_txo, ser.0);
110-
self.latest_update_good.lock().unwrap().insert(funding_txo, true);
111+
match self.latest_update_good.lock().unwrap().entry(funding_txo) {
112+
hash_map::Entry::Vacant(mut e) => { e.insert(true); },
113+
hash_map::Entry::Occupied(mut e) => {
114+
if !e.get() && unsafe { IN_RESTORE } {
115+
// Technically we can't consider an update to be "good" unless we're doing
116+
// it in response to a test_restore_channel_monitor as the channel may
117+
// still be waiting on such a call, so only set us to good if we're in the
118+
// middle of a restore call.
119+
e.insert(true);
120+
}
121+
},
122+
}
111123
self.should_update_manager.store(true, atomic::Ordering::Relaxed);
112124
} else {
113125
self.latest_update_good.lock().unwrap().insert(funding_txo, false);
@@ -619,9 +631,9 @@ pub fn do_test(data: &[u8]) {
619631
0x03 => *monitor_a.update_ret.lock().unwrap() = Ok(()),
620632
0x04 => *monitor_b.update_ret.lock().unwrap() = Ok(()),
621633
0x05 => *monitor_c.update_ret.lock().unwrap() = Ok(()),
622-
0x06 => nodes[0].test_restore_channel_monitor(),
623-
0x07 => nodes[1].test_restore_channel_monitor(),
624-
0x08 => nodes[2].test_restore_channel_monitor(),
634+
0x06 => { unsafe { IN_RESTORE = true }; nodes[0].test_restore_channel_monitor(); unsafe { IN_RESTORE = false }; },
635+
0x07 => { unsafe { IN_RESTORE = true }; nodes[1].test_restore_channel_monitor(); unsafe { IN_RESTORE = false }; },
636+
0x08 => { unsafe { IN_RESTORE = true }; nodes[2].test_restore_channel_monitor(); unsafe { IN_RESTORE = false }; },
625637
0x09 => send_payment!(nodes[0], (&nodes[1], chan_a)),
626638
0x0a => send_payment!(nodes[1], (&nodes[0], chan_a)),
627639
0x0b => send_payment!(nodes[1], (&nodes[2], chan_b)),

0 commit comments

Comments
 (0)