align with updated probability signature and skip logic
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
07b222468f
commit
2a6e31db57
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ghost-weaver"
|
||||
version = "0.0.27"
|
||||
version = "0.0.28"
|
||||
description = "Weaving a secure cryptographic tapestry across different external chains."
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
|
||||
@ -7,7 +7,7 @@ pub enum WeavingError<NetworkId> {
|
||||
UnknownWeavingPhase(NetworkId),
|
||||
OffchainLockPeriod(NetworkId),
|
||||
NoEndpointsAvailable(NetworkId),
|
||||
ContradictoryHashes(NetworkId),
|
||||
ContradictoryHashes(NetworkId, u32),
|
||||
ContradictoryBlocks(u32, ExternalBlockNumber, NetworkId),
|
||||
}
|
||||
|
||||
@ -34,9 +34,9 @@ impl<NetworkId: core::fmt::Debug> core::fmt::Debug for WeavingError<NetworkId> {
|
||||
"No RPC URLs configured for network #{:?}.",
|
||||
network_id
|
||||
),
|
||||
Self::ContradictoryHashes(network_id) => write!(
|
||||
Self::ContradictoryHashes(network_id, len) => write!(
|
||||
fmt,
|
||||
"Divergence among reported hashes for network #{:?}.",
|
||||
"Divergence among {len} reported hashes for network #{:?}.",
|
||||
network_id
|
||||
),
|
||||
Self::ContradictoryBlocks(len, deviation, network_id) => {
|
||||
|
||||
@ -830,12 +830,13 @@ impl<T: Config> Pallet<T> {
|
||||
return Err(WeavingError::NoEndpointsAvailable(network_id));
|
||||
}
|
||||
|
||||
let check_probability = |values_count: usize, blocks_left: BlockNumberFor<T>| -> bool {
|
||||
let check_probability = |values_count: usize, block_until: BlockNumberFor<T>| -> bool {
|
||||
let total_authorities = Authorities::<T>::decode_len().unwrap_or(1);
|
||||
let submission_probability = get_submission_probability(
|
||||
total_authorities,
|
||||
values_count,
|
||||
blocks_left,
|
||||
block_until,
|
||||
current_block,
|
||||
);
|
||||
|
||||
let seed = sp_io::offchain::random_seed();
|
||||
@ -843,7 +844,7 @@ impl<T: Config> Pallet<T> {
|
||||
.expect("input is padded with zeroes; qed");
|
||||
let random_roll = Perbill::from_parts(randomness % Perbill::ACCURACY);
|
||||
|
||||
random_roll > submission_probability
|
||||
random_roll >= submission_probability
|
||||
};
|
||||
|
||||
match TapestryDrafts::<T>::get(&network_id) {
|
||||
@ -915,9 +916,13 @@ impl<T: Config> Pallet<T> {
|
||||
.then(|| (*first_hash, *first_next_session))
|
||||
})
|
||||
.ok_or(WeavingError::<NetworkIdOf<T>>::ContradictoryHashes(
|
||||
network_id,
|
||||
network_id, hashes_and_next_sessions.len() as u32
|
||||
))?;
|
||||
|
||||
if LoomStates::<T>::get(&network_id, &weaving_session).root_hash == first_hash {
|
||||
return Ok(WeavingOk::HashUnchanged(network_id));
|
||||
}
|
||||
|
||||
let next_session_bytes = first_next_session.to_be_bytes();
|
||||
let weaving_session_bytes = weaving_session.to_be_bytes();
|
||||
|
||||
|
||||
@ -37,6 +37,7 @@ const PROTOCOL_PREFIX: [u8; 7] = [0x47, 0x48, 0x53, 0x54, 0x74, 0x6F, 0x3A];
|
||||
|
||||
pub enum WeavingOk<NetworkId> {
|
||||
Skipped(NetworkId),
|
||||
HashUnchanged(NetworkId),
|
||||
Block(ExternalBlockNumber, u32, NetworkId),
|
||||
Hash(ExternalBlockNumber, H256, WeavingSession, NetworkId),
|
||||
}
|
||||
@ -47,9 +48,10 @@ where
|
||||
{
|
||||
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
match self {
|
||||
Self::Skipped(network_id) => write!(fmt, "Submission step skipped for network: {:?} based on probability distribution.", network_id),
|
||||
Self::Block(block, count, network_id) => write!(fmt, "Verified block height #{:?} for network: {:?} based on {} parsed requests.", block, network_id, count),
|
||||
Self::Hash(block, hash, next_session, network_id) => write!(fmt, "Extracted Merkle Root {:?} (next session is {:?}) from block #{:?} for network: {:?}.", hash, next_session, block, network_id),
|
||||
Self::Skipped(network_id) => write!(fmt, "Submission step skipped for network: #{:?} based on probability distribution.", network_id),
|
||||
Self::HashUnchanged(network_id) => write!(fmt, "Merkle Root unchanged for network: #{:?}, skipping submission.", network_id),
|
||||
Self::Block(block, count, network_id) => write!(fmt, "Verified block height #{:?} for network: #{:?} based on {} parsed requests.", block, network_id, count),
|
||||
Self::Hash(block, hash, next_session, network_id) => write!(fmt, "Extracted Merkle Root {:?} (next session is {:?}) from block #{:?} for network: #{:?}.", hash, next_session, block, network_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user