Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
challenge period
Browse files Browse the repository at this point in the history
  • Loading branch information
dharjeezy committed Jul 14, 2023
1 parent 2123a05 commit a5a70fb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
19 changes: 10 additions & 9 deletions pallet-ismp/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

//! Host implementation for ISMP
use crate::{
dispatcher::Receipt, primitives::ConsensusClientProvider, Config, ConsensusClientUpdateTime,
ConsensusStateClient, ConsensusStates, FrozenConsensusClients, FrozenHeights,
LatestStateMachineHeight, Nonce, RequestCommitments, RequestReceipts, ResponseReceipts,
StateCommitments, UnbondingPeriod,
dispatcher::Receipt, primitives::ConsensusClientProvider, ChallengePeriod, Config,
ConsensusClientUpdateTime, ConsensusStateClient, ConsensusStates, FrozenConsensusClients,
FrozenHeights, LatestStateMachineHeight, Nonce, RequestCommitments, RequestReceipts,
ResponseReceipts, StateCommitments, UnbondingPeriod,
};
use alloc::{format, string::ToString};
use core::time::Duration;
Expand Down Expand Up @@ -162,8 +162,8 @@ where
sp_io::hashing::keccak_256(bytes).into()
}

fn challenge_period(&self, id: ConsensusClientId) -> Option<Duration> {
<T as Config>::ConsensusClientProvider::challenge_period(id)
fn challenge_period(&self, id: ConsensusStateId) -> Option<Duration> {
UnbondingPeriod::<T>::get(&id).map(Duration::from_secs)
}

fn ismp_router(&self) -> Box<dyn IsmpRouter> {
Expand Down Expand Up @@ -244,9 +244,10 @@ where

fn store_challenge_period(
&self,
_consensus_state_id: ConsensusStateId,
_period: u64,
consensus_state_id: ConsensusStateId,
period: u64,
) -> Result<(), Error> {
todo!()
ChallengePeriod::<T>::insert(consensus_state_id, period);
Ok(())
}
}
5 changes: 5 additions & 0 deletions pallet-ismp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ pub mod pallet {
pub type UnbondingPeriod<T: Config> =
StorageMap<_, Blake2_128Concat, ConsensusStateId, u64, OptionQuery>;

/// A mapping of ConsensusStateId to Challenge periods
#[pallet::storage]
pub type ChallengePeriod<T: Config> =
StorageMap<_, Blake2_128Concat, ConsensusStateId, u64, OptionQuery>;

/// Holds a map of consensus clients frozen due to byzantine
/// behaviour
#[pallet::storage]
Expand Down
8 changes: 6 additions & 2 deletions pallet-ismp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ use crate::*;
use crate::primitives::ConsensusClientProvider;
use frame_support::traits::{ConstU32, ConstU64, Get};
use frame_system::EnsureRoot;
use ismp_rs::{consensus::ConsensusClient, module::IsmpModule, router::IsmpRouter};
use ismp_rs::{
consensus::{ConsensusClient, ConsensusStateId},
module::IsmpModule,
router::IsmpRouter,
};

use crate::ismp_mocks::{MockConsensusClient, MockModule};
use sp_core::H256;
Expand Down Expand Up @@ -60,7 +64,7 @@ impl ConsensusClientProvider for ConsensusProvider {
Ok(Box::new(MockConsensusClient))
}

fn challenge_period(_id: ConsensusClientId) -> Option<Duration> {
fn challenge_period(_id: ConsensusStateId) -> Option<Duration> {
Some(Duration::from_secs(60 * 60))
}
}
Expand Down
6 changes: 3 additions & 3 deletions pallet-ismp/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use core::time::Duration;
use frame_support::{PalletId, RuntimeDebug};
use ismp_primitives::mmr::{LeafIndex, NodeIndex};
use ismp_rs::consensus::{ConsensusClient, ConsensusClientId};
use ismp_rs::consensus::{ConsensusClient, ConsensusClientId, ConsensusStateId};
use scale_info::TypeInfo;
use sp_core::{crypto::AccountId32, H160};
use sp_std::prelude::*;
Expand Down Expand Up @@ -60,8 +60,8 @@ pub trait ConsensusClientProvider {
id: ConsensusClientId,
) -> Result<Box<dyn ConsensusClient>, ismp_rs::error::Error>;

/// Returns the challenge period configured for a consensus client
fn challenge_period(id: ConsensusClientId) -> Option<Duration>;
/// Returns the challenge period configured for a consensus state
fn challenge_period(id: ConsensusStateId) -> Option<Duration>;
}

/// Module identification types supported by ismp
Expand Down

0 comments on commit a5a70fb

Please sign in to comment.