Skip to content

Commit e82e6b1

Browse files
committed
[fuzz] fix deadlock in chanmon_consistency due to new reentrancy
60d83ef introduced reentrancy when calling channel_monitor_updated. This commit fixes the chanmon_consistency fuzzer to no longer deadlock as a result of this reentrancy.
1 parent 09154b5 commit e82e6b1

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -750,23 +750,27 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
750750
0x06 => *monitor_c.update_ret.lock().unwrap() = Ok(()),
751751

752752
0x08 => {
753-
if let Some((id, _)) = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding) {
754-
nodes[0].channel_monitor_updated(&chan_1_funding, *id);
753+
let mon_id = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id);
754+
if let Some(id) = mon_id {
755+
nodes[0].channel_monitor_updated(&chan_1_funding, id);
755756
}
756757
},
757758
0x09 => {
758-
if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding) {
759-
nodes[1].channel_monitor_updated(&chan_1_funding, *id);
759+
let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id);
760+
if let Some(id) = mon_id {
761+
nodes[1].channel_monitor_updated(&chan_1_funding, id);
760762
}
761763
},
762764
0x0a => {
763-
if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding) {
764-
nodes[1].channel_monitor_updated(&chan_2_funding, *id);
765+
let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id);
766+
if let Some(id) = mon_id {
767+
nodes[1].channel_monitor_updated(&chan_2_funding, id);
765768
}
766769
},
767770
0x0b => {
768-
if let Some((id, _)) = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding) {
769-
nodes[2].channel_monitor_updated(&chan_2_funding, *id);
771+
let mon_id = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id);
772+
if let Some(id) = mon_id {
773+
nodes[2].channel_monitor_updated(&chan_2_funding, id);
770774
}
771775
},
772776

@@ -921,17 +925,29 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
921925
*monitor_b.update_ret.lock().unwrap() = Ok(());
922926
*monitor_c.update_ret.lock().unwrap() = Ok(());
923927

924-
if let Some((id, _)) = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding) {
925-
nodes[0].channel_monitor_updated(&chan_1_funding, *id);
928+
{
929+
let mon_id = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id);
930+
if let Some(id) = mon_id {
931+
nodes[0].channel_monitor_updated(&chan_1_funding, id);
932+
}
926933
}
927-
if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding) {
928-
nodes[1].channel_monitor_updated(&chan_1_funding, *id);
934+
{
935+
let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id);
936+
if let Some(id) = mon_id {
937+
nodes[1].channel_monitor_updated(&chan_1_funding, id);
938+
}
929939
}
930-
if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding) {
931-
nodes[1].channel_monitor_updated(&chan_2_funding, *id);
940+
{
941+
let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id);
942+
if let Some(id) = mon_id {
943+
nodes[1].channel_monitor_updated(&chan_2_funding, id);
944+
}
932945
}
933-
if let Some((id, _)) = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding) {
934-
nodes[2].channel_monitor_updated(&chan_2_funding, *id);
946+
{
947+
let mon_id = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id);
948+
if let Some(id) = mon_id {
949+
nodes[2].channel_monitor_updated(&chan_2_funding, id);
950+
}
935951
}
936952

937953
// Next, make sure peers are all connected to each other

0 commit comments

Comments
 (0)