From 279b71832bd41d0f73c0c3be3bae89af1cb234bf Mon Sep 17 00:00:00 2001 From: Uncle Stinky Date: Thu, 19 Nov 2026 13:31:59 +0300 Subject: [PATCH] scope DKG round 5 lookup and storage cleanup to active curve/index Signed-off-by: Uncle Stinky --- pallets/exodus/Cargo.toml | 2 +- pallets/exodus/src/lib.rs | 52 ++++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/pallets/exodus/Cargo.toml b/pallets/exodus/Cargo.toml index 7345551..987ff78 100644 --- a/pallets/exodus/Cargo.toml +++ b/pallets/exodus/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ghost-exodus" -version = "0.1.7" +version = "0.1.8" description = "Threshold signature generation with DKG included" license.workspace = true authors.workspace = true diff --git a/pallets/exodus/src/lib.rs b/pallets/exodus/src/lib.rs index f56d9bd..92e5263 100644 --- a/pallets/exodus/src/lib.rs +++ b/pallets/exodus/src/lib.rs @@ -2189,7 +2189,8 @@ impl Pallet { network_curve, maybe_cursor, |cursor_slice, weight| { - let result = Round0Packages::::clear( + let result = Round0Packages::::clear_prefix( + network_curve, T::RemovalLimit::get(), cursor_slice, ); @@ -2279,15 +2280,12 @@ impl Pallet { dkg_qualification: &mut PendingDkgAuthorities, maybe_cursor: Option>, ) -> (Weight, bool) { - let dkg_index = dkg_qualification.get_dkg_index(); - Self::prepare_round_storage( network_curve, maybe_cursor, |cursor_slice, weight| { - let prev_dkg_index = dkg_index.saturating_sub(1); let result = Verifications::::clear_prefix( - (network_curve, prev_dkg_index), + (network_curve,), T::RemovalLimit::get(), cursor_slice, ); @@ -2354,17 +2352,24 @@ impl Pallet { dkg_qualification: &mut PendingDkgAuthorities, maybe_cursor: Option>, ) -> (Weight, bool) { - let dkg_index = dkg_qualification.get_dkg_index(); - Self::prepare_round_storage( network_curve, maybe_cursor, - |_, weight| { - let prev_dkg_index = dkg_index.saturating_sub(1); + |cursor_slice, weight| { + let result = VerifyingKeyConsensus::::clear_prefix( + network_curve, + T::RemovalLimit::get(), + cursor_slice, + ); - weight.saturating_accrue(T::DbWeight::get().writes(1)); - VerifyingKeyConsensus::::remove(network_curve, &prev_dkg_index); - None + weight.saturating_accrue( + T::DbWeight::get().reads_writes( + (result.backend as u64).saturating_add(1), + result.backend as u64 + ) + ); + + result.maybe_cursor }, |weight| { weight.saturating_accrue(T::DbWeight::get().reads(2)); @@ -2375,7 +2380,7 @@ impl Pallet { let mut number_of_leaked_keys = 0; let qualified_indexes = dkg_qualification.get_indexes(); - let total_authorities_len = qualified_indexes.count_ones::(); + let total_authorities_len = qualified_indexes.active_bits_count() as usize; let mut failed_authorities = ParticipantsBitmap::::empty_from( &qualified_indexes, @@ -2463,7 +2468,6 @@ impl Pallet { return None; } - let result = VerifyingShares::::clear_prefix( (network_curve, previous_dkg_index), T::RemovalLimit::get(), @@ -4574,6 +4578,7 @@ impl Pallet { ) -> ExodusResult>> { let network_curve = dkg_storage.network_curve; let authority_index = dkg_storage.authority_index; + let dkg_index = qualification_state.get_dkg_index(); if !qualification_state.contains_index(authority_index) { return Ok(ExodusOk::DkgNotPartOfRound( @@ -4584,8 +4589,10 @@ impl Pallet { } let verification_found_for_self = - VerifyingKeyConsensus::::iter_values() - .any(|consensus| consensus.state.participants.contains(authority_index)); + VerifyingKeyConsensus::::get(&network_curve, &dkg_index) + .state + .participants + .contains(authority_index); if verification_found_for_self { return Ok(ExodusOk::DkgRoundAlreadyPassed( @@ -4595,7 +4602,6 @@ impl Pallet { )); } - let dkg_index = qualification_state.get_dkg_index(); let dkg_based_prefix = Self::create_dkg_based_prefix(dkg_index); let mut round_metadata = dkg_storage.read_local_storage( @@ -5120,14 +5126,10 @@ impl Pallet { .ok() .filter(|b| b.len() == max_size); - match maybe_encoded_bytes { - Some(encoded) => { - if let Some(_) = bitmask.insert(receiver_index) { - blob.extend_from_slice(&encoded); - } - }, - None => { - blob.extend_from_slice(&vec![0u8; max_size]); + if let Some(_) = bitmask.insert(receiver_index) { + match maybe_encoded_bytes { + Some(encoded) => blob.extend_from_slice(&encoded), + None => blob.extend_from_slice(&vec![0u8; max_size]), } } }