stagger DKG offchain submissions using adaptive probability

Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
Uncle Stinky 2026-11-19 14:41:41 +03:00
parent 279b71832b
commit ad4c712fbf
Signed by: st1nky
GPG Key ID: 016064BD97603B40
3 changed files with 79 additions and 4 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "ghost-exodus"
version = "0.1.8"
version = "0.1.9"
description = "Threshold signature generation with DKG included"
license.workspace = true
authors.workspace = true

View File

@ -20,8 +20,8 @@ use sp_runtime::{
storage::StorageValueRef,
storage_lock::{StorageLock, Time},
},
traits::UniqueSaturatedInto,
Saturating, Perbill,
traits::{One, TrailingZeroInput, UniqueSaturatedInto},
Saturating, Perbill, PerThing,
};
use sp_std::{vec, vec::Vec, collections::btree_map::BTreeMap};
@ -30,7 +30,8 @@ use sp_runtime::traits::BlockNumberProvider;
use sp_io::hashing::blake2_256;
use ghost_helpers::{
get_byzantium_quorum_threshold, SubstrateBlake2Hasher,
get_byzantium_quorum_threshold, get_submission_probability,
SubstrateBlake2Hasher,
lcg::PerfectSlotMapperU128,
hash_chain::cumulative_hash,
networks::{NetworkData, NetworkCurve, NetworkType},
@ -3786,6 +3787,68 @@ impl<T: Config> Pallet<T> {
Ok(results)
}
fn should_skip_submission(
network_curve: NetworkCurve,
current_block: BlockNumberFor<T>,
qualification_authorities: &PendingDkgAuthorities<T>,
) -> bool {
let dkg_phase = qualification_authorities.get_phase();
let dkg_index = qualification_authorities.get_dkg_index();
let dkg_round_period: BlockNumberFor<T> = T::DkgRoundPeriod::get()
.unique_saturated_into();
let blocks_remaining = qualification_authorities
.get_release_block()
.saturating_sub(current_block);
if blocks_remaining <= 2u32.into() {
return false;
}
let elapsed_blocks = dkg_round_period
.saturating_sub(blocks_remaining)
.saturating_add(One::one());
let total_authorities = if dkg_phase == DkgPhase::Round0 {
let indexes = qualification_authorities.get_indexes();
indexes.active_bits_count() as usize
} else {
qualification_authorities.count_ones::<usize>()
};
let values_count = match dkg_phase {
DkgPhase::Round0 => qualification_authorities.count_ones::<usize>(),
DkgPhase::Round1 => Round1Packages::<T>::get(network_curve).count_ones::<usize>(),
DkgPhase::Round2 => Round2Packages::<T>::get(network_curve).count_ones::<usize>(),
DkgPhase::Round3 => Complaints::<T>::get(network_curve).len(),
DkgPhase::Round4 => Justifications::<T>::get(network_curve).len(),
DkgPhase::Round5 => {
let consensus = VerifyingKeyConsensus::<T>::get(network_curve, dkg_index);
consensus.state.participants.count_ones::<usize>()
},
DkgPhase::Round6 => {
let shares = VerifyingSharesParticipants::<T>::get(network_curve, dkg_index);
shares.count_ones::<usize>()
},
_ => return false,
};
let submission_probability = get_submission_probability(
total_authorities,
values_count,
dkg_round_period,
elapsed_blocks
);
let seed = sp_io::offchain::random_seed();
let randomness = <u32>::decode(&mut TrailingZeroInput::new(seed.as_ref()))
.expect("input is padded with zeroes; qed");
let random_roll = Perbill::from_parts(randomness % Perbill::ACCURACY);
random_roll >= submission_probability
}
fn dkg_run_process(
authority_index: AuthIndex,
authority_key: T::AuthorityId,
@ -3796,6 +3859,16 @@ impl<T: Config> Pallet<T> {
let block_longevity: BlockNumberFor<T> =
T::UnsignedLongevity::get().unique_saturated_into();
if Self::should_skip_submission(
network_curve,
current_block,
qualification_authorities,
) {
return Ok(ExodusOk::DkgRoundSubmissionSkipped(
authority_index, network_curve,
));
}
let dkg_storage = DkgStorage::default()
.with_network_curve(network_curve)
.with_current_block(current_block)

View File

@ -10,6 +10,7 @@ pub enum ExodusOk<NetworkCurve, NetworkId> {
ExodusSignedPartially(ExodusSession, NetworkId, RoastSession, AuthIndex, NetworkCurve),
ExodusVerifyingShareMissed(AuthIndex, DkgIndex, NetworkCurve),
DkgRoundSubmissionSkipped(AuthIndex, NetworkCurve),
DkgNotPartOfRound(u8, AuthIndex, NetworkCurve),
DkgRoundRegistered(u8, AuthIndex, NetworkCurve),
DkgPreviousPurged(AuthIndex, NetworkCurve, u32),
@ -47,6 +48,7 @@ where
},
ExodusOk::ExodusVerifyingShareMissed(auth_index, dkg_index, curve) => write!(fmt, "No verifying share found for authority #{auth_index} in EXODUS round based on DKG session #{dkg_index} for curve {curve}."),
ExodusOk::DkgRoundSubmissionSkipped(auth_index, curve) => write!(fmt, "DKG authority #{auth_index} skipped submission for network curve {curve} temporarily."),
ExodusOk::DkgNotPartOfRound(round, auth_index, curve) => write!(fmt, "DKG authority #{auth_index} is not part of Round {round} for network curve {curve}."),
ExodusOk::DkgRoundRegistered(round, auth_index, curve) => write!(fmt, "DKG Round {round} registered by authority #{auth_index} for network curve {curve}."),
ExodusOk::DkgPreviousPurged(auth_index, curve, removed_count) => write!(fmt, "Storage prepared for a new DKG session by authority #{auth_index} for network curve {curve}. {removed_count} entries removed."),