Skip to content

Commit

Permalink
Merge branch 'master' into polkadot-v0.9.42
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov authored Mar 21, 2024
2 parents d740cb1 + 64052a5 commit a6676af
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 321 deletions.
64 changes: 32 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions crates/humanode-runtime/src/deauthentication_reason.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! `DeauthenticationReason` implementation to define reasons by which authentication is removed
//! before expected time expiration.
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_std::prelude::*;

/// Define a possible deauthentication reason.
#[derive(Clone, PartialEq, Debug, Encode, Decode, TypeInfo)]
pub enum DeauthenticationReason {
/// Some offence has been recevied.
Offence,
}
21 changes: 18 additions & 3 deletions crates/humanode-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ use frontier_precompiles::{precompiles_constants, FrontierPrecompiles};
mod benchmarking;
pub mod constants;
mod currency_swap;
mod deauthentication_reason;
#[cfg(test)]
mod dev_utils;
mod display_moment;
Expand All @@ -107,6 +108,7 @@ pub use constants::{
ethereum::EXTRA_DATA_LENGTH,
im_online::{MAX_KEYS, MAX_PEER_DATA_ENCODING_SIZE, MAX_PEER_IN_HEARTBEATS},
};
use deauthentication_reason::DeauthenticationReason;
use static_assertions::const_assert;

/// An index to a block.
Expand Down Expand Up @@ -539,6 +541,7 @@ impl pallet_bioauth::Config for Runtime {
type MaxNonces = ConstU32<MAX_NONCES>;
type BeforeAuthHook = ();
type AfterAuthHook = ();
type DeauthenticationReason = DeauthenticationReason;
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -589,19 +592,31 @@ impl
}
let mut weight: Weight = Weight::zero();
let weights = <Runtime as frame_system::Config>::DbWeight::get();
let mut should_be_deauthenticated = Vec::with_capacity(offenders.len());
for details in offenders {
let (_offender, identity) = &details.offender;
match identity {
pallet_humanode_session::Identification::Bioauth(authentication) => {
let has_deauthenticated = Bioauth::deauthenticate(&authentication.public_key);
weight = weight
.saturating_add(weights.reads_writes(1, u64::from(has_deauthenticated)));
should_be_deauthenticated.push(authentication.public_key.clone());
}
pallet_humanode_session::Identification::Bootnode(..) => {
// Never slash the bootnodes.
}
}
}
if !should_be_deauthenticated.is_empty() {
let deauthenticated_public_keys =
Bioauth::deauthenticate(should_be_deauthenticated, DeauthenticationReason::Offence);
weight = weight.saturating_add(
weights.reads_writes(
1,
deauthenticated_public_keys
.len()
.try_into()
.expect("casting usize to u64 never fails in 64bit and 32bit word cpus"),
),
);
}
weight
}
}
Expand Down
Loading

0 comments on commit a6676af

Please # to comment.