Skip to content

Commit daedbbe

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 e7a4908 commit daedbbe

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
@@ -748,23 +748,27 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
748748
0x06 => *monitor_c.update_ret.lock().unwrap() = Ok(()),
749749

750750
0x08 => {
751-
if let Some((id, _)) = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding) {
752-
nodes[0].channel_monitor_updated(&chan_1_funding, *id);
751+
let mon_id = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id);
752+
if let Some(id) = mon_id {
753+
nodes[0].channel_monitor_updated(&chan_1_funding, id);
753754
}
754755
},
755756
0x09 => {
756-
if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding) {
757-
nodes[1].channel_monitor_updated(&chan_1_funding, *id);
757+
let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id);
758+
if let Some(id) = mon_id {
759+
nodes[1].channel_monitor_updated(&chan_1_funding, id);
758760
}
759761
},
760762
0x0a => {
761-
if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding) {
762-
nodes[1].channel_monitor_updated(&chan_2_funding, *id);
763+
let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id);
764+
if let Some(id) = mon_id {
765+
nodes[1].channel_monitor_updated(&chan_2_funding, id);
763766
}
764767
},
765768
0x0b => {
766-
if let Some((id, _)) = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding) {
767-
nodes[2].channel_monitor_updated(&chan_2_funding, *id);
769+
let mon_id = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id);
770+
if let Some(id) = mon_id {
771+
nodes[2].channel_monitor_updated(&chan_2_funding, id);
768772
}
769773
},
770774

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

922-
if let Some((id, _)) = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding) {
923-
nodes[0].channel_monitor_updated(&chan_1_funding, *id);
926+
{
927+
let mon_id = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id);
928+
if let Some(id) = mon_id {
929+
nodes[0].channel_monitor_updated(&chan_1_funding, id);
930+
}
924931
}
925-
if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding) {
926-
nodes[1].channel_monitor_updated(&chan_1_funding, *id);
932+
{
933+
let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id);
934+
if let Some(id) = mon_id {
935+
nodes[1].channel_monitor_updated(&chan_1_funding, id);
936+
}
927937
}
928-
if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding) {
929-
nodes[1].channel_monitor_updated(&chan_2_funding, *id);
938+
{
939+
let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id);
940+
if let Some(id) = mon_id {
941+
nodes[1].channel_monitor_updated(&chan_2_funding, id);
942+
}
930943
}
931-
if let Some((id, _)) = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding) {
932-
nodes[2].channel_monitor_updated(&chan_2_funding, *id);
944+
{
945+
let mon_id = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id);
946+
if let Some(id) = mon_id {
947+
nodes[2].channel_monitor_updated(&chan_2_funding, id);
948+
}
933949
}
934950

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

0 commit comments

Comments
 (0)