From: Matt Corallo Date: Thu, 19 Nov 2020 21:16:50 +0000 (-0500) Subject: [fuzz] fix deadlock in chanmon_consistency due to new reentrancy X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=daedbbe714e56a155e089f6c6b14a25b480d9c25;p=rust-lightning [fuzz] fix deadlock in chanmon_consistency due to new reentrancy 60d83efcd9825bed3e9490c7d1479533efd399ec introduced reentrancy when calling channel_monitor_updated. This commit fixes the chanmon_consistency fuzzer to no longer deadlock as a result of this reentrancy. --- diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index e180805f2..dbc14ce1d 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -748,23 +748,27 @@ pub fn do_test(data: &[u8], out: Out) { 0x06 => *monitor_c.update_ret.lock().unwrap() = Ok(()), 0x08 => { - if let Some((id, _)) = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding) { - nodes[0].channel_monitor_updated(&chan_1_funding, *id); + let mon_id = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[0].channel_monitor_updated(&chan_1_funding, id); } }, 0x09 => { - if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding) { - nodes[1].channel_monitor_updated(&chan_1_funding, *id); + let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[1].channel_monitor_updated(&chan_1_funding, id); } }, 0x0a => { - if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding) { - nodes[1].channel_monitor_updated(&chan_2_funding, *id); + let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[1].channel_monitor_updated(&chan_2_funding, id); } }, 0x0b => { - if let Some((id, _)) = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding) { - nodes[2].channel_monitor_updated(&chan_2_funding, *id); + let mon_id = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[2].channel_monitor_updated(&chan_2_funding, id); } }, @@ -919,17 +923,29 @@ pub fn do_test(data: &[u8], out: Out) { *monitor_b.update_ret.lock().unwrap() = Ok(()); *monitor_c.update_ret.lock().unwrap() = Ok(()); - if let Some((id, _)) = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding) { - nodes[0].channel_monitor_updated(&chan_1_funding, *id); + { + let mon_id = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[0].channel_monitor_updated(&chan_1_funding, id); + } } - if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding) { - nodes[1].channel_monitor_updated(&chan_1_funding, *id); + { + let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[1].channel_monitor_updated(&chan_1_funding, id); + } } - if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding) { - nodes[1].channel_monitor_updated(&chan_2_funding, *id); + { + let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[1].channel_monitor_updated(&chan_2_funding, id); + } } - if let Some((id, _)) = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding) { - nodes[2].channel_monitor_updated(&chan_2_funding, *id); + { + let mon_id = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[2].channel_monitor_updated(&chan_2_funding, id); + } } // Next, make sure peers are all connected to each other