From d5d91a4e79b7bdf740ff0fb51877b269cc3fa516 Mon Sep 17 00:00:00 2001 From: pasta Date: Wed, 11 Nov 2026 13:07:11 +0000 Subject: [PATCH 1/2] test(dash-spv): drop a restored cycle with another entry hash A snapshot whose lists hold a stored cycle's quorum under the same type and quorum hash, but with a different quorum_vvec_hash and so a different entry hash, restores without that cycle and keeps the other stored cycle. Without the entry-hash comparison in the restore filter the cycle comes back and the test fails. Co-Authored-By: Claude Opus 5.5 --- dash-spv/src/sml_engine/snapshot_codec.rs | 44 ++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/dash-spv/src/sml_engine/snapshot_codec.rs b/dash-spv/src/sml_engine/snapshot_codec.rs index 7a3756142..8edf5456d 100644 --- a/dash-spv/src/sml_engine/snapshot_codec.rs +++ b/dash-spv/src/sml_engine/snapshot_codec.rs @@ -401,7 +401,7 @@ mod tests { use bincode::error::DecodeError; use dashcore::bls_sig_utils::BLSSignature; use dashcore::consensus::deserialize; - use dashcore::hash_types::MerkleRootAssetUnlocks; + use dashcore::hash_types::{MerkleRootAssetUnlocks, QuorumVVecHash}; use dashcore::network::message_qrinfo::QRInfo; use dashcore::network::message_sml::MnListDiff; use dashcore::prelude::CoreBlockHeight; @@ -619,6 +619,48 @@ mod tests { assert_eq!(restored.masternode_lists, engine.masternode_lists); } + /// A cycle whose entry the lists hold under its type and quorum hash, but + /// with another entry hash, is not restored. The other cycles are. + #[tokio::test] + async fn a_snapshot_drops_a_cycle_its_lists_hold_with_another_entry_hash() { + let mut engine = qr_info_engine().await; + let stored = engine + .rotated_quorums_per_cycle() + .values() + .flat_map(|cycle| cycle.values()) + .next() + .expect("the QRInfo stores a cycle") + .quorum_entry + .clone(); + assert_ne!(stored.quorum_vvec_hash, QuorumVVecHash::all_zeros()); + let mut altered = 0; + for list in engine.masternode_lists.values_mut() { + let listed = Arc::make_mut(&mut list.quorums) + .get_mut(&stored.llmq_type) + .and_then(|quorums| quorums.get_mut(&stored.quorum_hash)); + if let Some(listed) = listed { + let listed = Arc::make_mut(listed); + listed.quorum_entry.quorum_vvec_hash = QuorumVVecHash::all_zeros(); + listed.commitment_hash = listed.quorum_entry.calculate_commitment_hash(); + listed.entry_hash = listed.quorum_entry.calculate_entry_hash(); + altered += 1; + } + } + assert!(altered > 0, "a list holds the stored entry"); + let bytes = engine.snapshot().expect("encodes"); + + let restored = + TestEngine::from_snapshot(Network::Mainnet, engine.headers(), &bytes).expect("decodes"); + + let mut kept = engine.rotated_quorums_per_cycle().clone(); + kept.retain(|_, cycle| { + cycle.values().all(|entry| entry.quorum_entry.quorum_hash != stored.quorum_hash) + }); + assert_eq!(kept.len() + 1, engine.rotated_quorums_per_cycle().len()); + assert!(restored.rotated_quorums_per_cycle() == &kept, "only the altered cycle is dropped"); + assert_eq!(restored.masternode_lists, engine.masternode_lists); + } + #[test] fn a_full_retention_window_snapshots_to_about_one_list() { let window = TestEngine::empty(Network::Mainnet).retention_window() as usize; From 964adcddbe0bd5ea2436830c908e8d1d6529cb84 Mon Sep 17 00:00:00 2001 From: pasta Date: Wed, 11 Nov 2026 20:42:48 +0000 Subject: [PATCH 2/2] test(dash-spv): say why the restore-filter test edits lists by hand No diff or QRInfo can make a masternode list disagree with a stored rotation cycle, so the test edits the lists directly to stand in for a saved snapshot in that state. Co-Authored-By: Claude Opus 5.5 --- dash-spv/src/sml_engine/snapshot_codec.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dash-spv/src/sml_engine/snapshot_codec.rs b/dash-spv/src/sml_engine/snapshot_codec.rs index 8edf5456d..b7c05f7c1 100644 --- a/dash-spv/src/sml_engine/snapshot_codec.rs +++ b/dash-spv/src/sml_engine/snapshot_codec.rs @@ -619,8 +619,9 @@ mod tests { assert_eq!(restored.masternode_lists, engine.masternode_lists); } - /// A cycle whose entry the lists hold under its type and quorum hash, but - /// with another entry hash, is not restored. The other cycles are. + /// A cycle whose entry the lists hold under its type and quorum hash, but with another + /// entry hash, is not restored; the other cycles are. The hand-edited lists stand in for + /// a saved snapshot whose lists and cycles disagree, which no diff or `QRInfo` can produce. #[tokio::test] async fn a_snapshot_drops_a_cycle_its_lists_hold_with_another_entry_hash() { let mut engine = qr_info_engine().await;