Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion dash-spv/src/sml_engine/snapshot_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -619,6 +619,49 @@ 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. 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;
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() {
Comment thread
manki-review[bot] marked this conversation as resolved.
Resolved
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;
Expand Down
Loading