Skip to content

Commit e0cb071

Browse files
committed
fuzz: Add cross-version ChannelMonitor roundtrip coverage
1 parent 2af4096 commit e0cb071

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

fuzz/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ lightning-invoice = { path = "../lightning-invoice" }
1111
lightning-liquidity = { path = "../lightning-liquidity" }
1212
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" }
1313
lightning-persister = { path = "../lightning-persister", features = ["tokio"]}
14+
lightning_0_2 = { package = "lightning", version = "0.2.0", features = ["_test_utils"] }
1415
bech32 = "0.11.0"
1516
bitcoin = { version = "0.32.4", features = ["secp-lowmemory"] }
1617
tokio = { version = "~1.35", default-features = false, features = ["rt-multi-thread"] }

fuzz/src/chanmon_consistency.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,9 +971,25 @@ impl<'a> HarnessNode<'a> {
971971
};
972972
// Use a different value of `use_old_mons` if we have another monitor
973973
// (only for node B) by shifting `use_old_mons` one in base-3.
974-
use_old_mons /= 3;
974+
let mut monitor_bytes = serialized_mon.clone();
975+
if use_old_mons % 3 == 2 {
976+
let keys_manager_0_2 = lightning_0_2::sign::KeysManager::new(&[0u8; 32], 0, 0, false);
977+
let read_res: Result<(
978+
bitcoin::BlockHash,
979+
lightning_0_2::chain::channelmonitor::ChannelMonitor<lightning_0_2::sign::InMemorySigner>
980+
), _> = lightning_0_2::util::ser::ReadableArgs::read(
981+
&mut &monitor_bytes[..],
982+
(&keys_manager_0_2, &keys_manager_0_2)
983+
);
984+
985+
if let Ok((block_hash_0_2, old_monitor)) = read_res {
986+
let mut reserialized = Vec::new();
987+
lightning_0_2::util::ser::Writeable::write(&(block_hash_0_2, &old_monitor), &mut reserialized).unwrap();
988+
monitor_bytes = reserialized;
989+
}
990+
}
975991
let mon = <(BlockLocator, ChannelMonitor<TestChannelSigner>)>::read(
976-
&mut &serialized_mon[..],
992+
&mut &monitor_bytes[..],
977993
(&*self.keys_manager, &*self.keys_manager),
978994
)
979995
.expect("Failed to read monitor");

0 commit comments

Comments
 (0)