Skip to content

Commit 4a8bec0

Browse files
committed
avoid deadlock in chanmon_consistency with new holding-cell-clear
1 parent cee6221 commit 4a8bec0

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

720720
0x08 => {
721-
if let Some((id, _)) = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding) {
722-
nodes[0].channel_monitor_updated(&chan_1_funding, *id);
721+
let mon_id = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id);
722+
if let Some(id) = mon_id {
723+
nodes[0].channel_monitor_updated(&chan_1_funding, id);
723724
}
724725
},
725726
0x09 => {
726-
if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding) {
727-
nodes[1].channel_monitor_updated(&chan_1_funding, *id);
727+
let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id);
728+
if let Some(id) = mon_id {
729+
nodes[1].channel_monitor_updated(&chan_1_funding, id);
728730
}
729731
},
730732
0x0a => {
731-
if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding) {
732-
nodes[1].channel_monitor_updated(&chan_2_funding, *id);
733+
let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id);
734+
if let Some(id) = mon_id {
735+
nodes[1].channel_monitor_updated(&chan_2_funding, id);
733736
}
734737
},
735738
0x0b => {
736-
if let Some((id, _)) = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding) {
737-
nodes[2].channel_monitor_updated(&chan_2_funding, *id);
739+
let mon_id = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id);
740+
if let Some(id) = mon_id {
741+
nodes[2].channel_monitor_updated(&chan_2_funding, id);
738742
}
739743
},
740744

@@ -889,17 +893,29 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
889893
*monitor_b.update_ret.lock().unwrap() = Ok(());
890894
*monitor_c.update_ret.lock().unwrap() = Ok(());
891895

892-
if let Some((id, _)) = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding) {
893-
nodes[0].channel_monitor_updated(&chan_1_funding, *id);
896+
{
897+
let mon_id = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id);
898+
if let Some(id) = mon_id {
899+
nodes[0].channel_monitor_updated(&chan_1_funding, id);
900+
}
894901
}
895-
if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding) {
896-
nodes[1].channel_monitor_updated(&chan_1_funding, *id);
902+
{
903+
let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id);
904+
if let Some(id) = mon_id {
905+
nodes[1].channel_monitor_updated(&chan_1_funding, id);
906+
}
897907
}
898-
if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding) {
899-
nodes[1].channel_monitor_updated(&chan_2_funding, *id);
908+
{
909+
let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id);
910+
if let Some(id) = mon_id {
911+
nodes[1].channel_monitor_updated(&chan_2_funding, id);
912+
}
900913
}
901-
if let Some((id, _)) = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding) {
902-
nodes[2].channel_monitor_updated(&chan_2_funding, *id);
914+
{
915+
let mon_id = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id);
916+
if let Some(id) = mon_id {
917+
nodes[2].channel_monitor_updated(&chan_2_funding, id);
918+
}
903919
}
904920

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

0 commit comments

Comments
 (0)