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

Commit

Permalink
Ismp updates (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizdave97 authored Aug 7, 2023
1 parent 1ac85a6 commit ae61cc7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

28 changes: 27 additions & 1 deletion pallet-ismp/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
dispatcher::Receipt, primitives::ConsensusClientProvider, AllowedProxies, ChallengePeriod,
Config, ConsensusClientUpdateTime, ConsensusStateClient, ConsensusStates,
FrozenConsensusClients, FrozenHeights, LatestStateMachineHeight, Nonce, RequestCommitments,
RequestReceipts, ResponseReceipts, StateCommitments, UnbondingPeriod,
RequestReceipts, ResponseReceipts, StateCommitments, StateMachineUpdateTime, UnbondingPeriod,
};
use alloc::{format, string::ToString};
use core::time::Duration;
Expand Down Expand Up @@ -71,6 +71,20 @@ impl<T: Config> IsmpHost for Host<T> {
})
}

fn state_machine_update_time(
&self,
state_machine_height: StateMachineHeight,
) -> Result<Duration, Error> {
StateMachineUpdateTime::<T>::get(state_machine_height)
.map(|timestamp| Duration::from_secs(timestamp))
.ok_or_else(|| {
Error::ImplementationSpecific(format!(
"Update time not found for {:?}",
state_machine_height
))
})
}

fn consensus_state(&self, id: ConsensusClientId) -> Result<Vec<u8>, Error> {
ConsensusStates::<T>::get(id)
.ok_or_else(|| Error::ConsensusStateNotFound { consensus_state_id: id })
Expand Down Expand Up @@ -116,6 +130,18 @@ impl<T: Config> IsmpHost for Host<T> {
Ok(())
}

fn store_state_machine_update_time(
&self,
state_machine_height: StateMachineHeight,
timestamp: Duration,
) -> Result<(), Error> {
StateMachineUpdateTime::<T>::insert(
state_machine_height,
timestamp.as_secs().saturated_into::<u64>(),
);
Ok(())
}

fn store_state_machine_commitment(
&self,
height: StateMachineHeight,
Expand Down
7 changes: 7 additions & 0 deletions pallet-ismp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ pub mod pallet {
pub type ConsensusClientUpdateTime<T: Config> =
StorageMap<_, Twox64Concat, ConsensusClientId, u64, OptionQuery>;

/// Holds the timestamp at which a state machine height was updated.
/// Used in ensuring that the configured challenge period elapses.
#[pallet::storage]
#[pallet::getter(fn state_machine_update_time)]
pub type StateMachineUpdateTime<T: Config> =
StorageMap<_, Twox64Concat, StateMachineHeight, u64, OptionQuery>;

/// Commitments for outgoing requests
/// The key is the request commitment
#[pallet::storage]
Expand Down
11 changes: 7 additions & 4 deletions pallet-ismp/src/mocks/ismp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,16 @@ where
},
)
.unwrap();

set_timestamp::<T>(1000_000_000);
StateMachineHeight {
let height = StateMachineHeight {
id: StateMachineId {
state_id: StateMachine::Ethereum(Ethereum::ExecutionLayer),
consensus_state_id: MOCK_CONSENSUS_STATE_ID,
},
height: 3,
}
};
host.store_state_machine_update_time(height, core::time::Duration::from_millis(1000_000))
.unwrap();

set_timestamp::<T>(1000_000_000);
height
}

0 comments on commit ae61cc7

Please sign in to comment.