Skip to content

Commit

Permalink
feat(kreivo-runtime): Relax BlockHashChallenger to accept challenge…
Browse files Browse the repository at this point in the history
…s for blocks up to `P` back in the past.
  • Loading branch information
pandres95 committed Dec 16, 2024
1 parent a70fe96 commit 55f8c30
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions runtime/kreivo/src/configuration/system_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,23 @@ parameter_types! {
pub NeverPays: Option<pallet_pass::DepositInformation<Runtime>> = None;
}

pub struct UnincludedBlockHashChallenger;
pub struct BlockHashChallenger<const P: BlockNumber>;

impl Challenger for UnincludedBlockHashChallenger {
impl<const P: BlockNumber> Challenger for BlockHashChallenger<P> {
type Context = BlockNumber;

fn generate(cx: &Self::Context) -> Challenge {
System::block_hash(cx).0
}

fn check_challenge(cx: &Self::Context, challenge: &[u8]) -> Option<()> {
(*cx >= System::block_number().saturating_sub(3)).then_some(())?;
(*cx >= System::block_number().saturating_sub(P)).then_some(())?;
Self::generate(cx).eq(challenge).then_some(())
}
}

pub type WebAuthn = pass_webauthn::Authenticator<UnincludedBlockHashChallenger, AuthorityFromPalletId<PassPalletId>>;
pub type WebAuthn =
pass_webauthn::Authenticator<BlockHashChallenger<{ 30 * MINUTES }>, AuthorityFromPalletId<PassPalletId>>;
pub type Dummy = fc_traits_authn::util::dummy::Dummy<AuthorityFromPalletId<PassPalletId>>;

#[cfg(not(feature = "runtime-benchmarks"))]
Expand Down

0 comments on commit 55f8c30

Please sign in to comment.