Skip to content

Commit

Permalink
cleanup & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed May 15, 2024
1 parent 29574a8 commit aa0352e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 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.

7 changes: 5 additions & 2 deletions pallets/regions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ pub mod pallet {
NotUnavailable,
/// The given region id is not valid.
InvalidRegionId,
/// Failed to get the latest height of the Coretime chain.
LatestHeightInaccessible,
}

#[pallet::call]
Expand Down Expand Up @@ -238,10 +240,11 @@ pub mod pallet {
let key = [pallet_hash, storage_hash, region_id_hash, region_id_encoded].concat();

let coretime_chain_height =
T::StateMachineHeightProvider::get_latest_state_machine_height(StateMachineId {
T::StateMachineHeightProvider::latest_state_machine_height(StateMachineId {
state_id: T::CoretimeChain::get(),
consensus_state_id: PARACHAIN_CONSENSUS_ID,
});
})
.ok_or(Error::<T>::LatestHeightInaccessible)?;

// TODO: should requests be coupled in the future?
let get = DispatchGet {
Expand Down
4 changes: 2 additions & 2 deletions pallets/regions/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ parameter_types! {

pub struct MockStateMachineHeightProvider;
impl StateMachineHeightProvider for MockStateMachineHeightProvider {
fn get_latest_state_machine_height(_id: StateMachineId) -> u64 {
0
fn latest_state_machine_height(_id: StateMachineId) -> Option<u64> {
Some(0)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/regions/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ use ismp::consensus::StateMachineId;

pub trait StateMachineHeightProvider {
/// Return the latest height of the state machine
fn get_latest_state_machine_height(id: StateMachineId) -> u64;
fn latest_state_machine_height(id: StateMachineId) -> Option<u64>;
}
2 changes: 1 addition & 1 deletion pallets/regions/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ fn on_timeout_works() {
invalid_get_req.keys.push(vec![0u8; 15]);
assert_err!(
module.on_timeout(Timeout::Request(Request::Get(invalid_get_req.clone()))),
IsmpCustomError::DecodeFailed
IsmpCustomError::KeyDecodeFailed
);

// invalid id: region not found
Expand Down
4 changes: 2 additions & 2 deletions runtime/regionx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ impl pallet_collator_selection::Config for Runtime {

pub struct StateMachineHeightProvider;
impl StateMachineHeightProviderT for StateMachineHeightProvider {
fn get_latest_state_machine_height(id: StateMachineId) -> u64 {
Ismp::latest_state_machine_height(id).unwrap_or(0) // TODO
fn latest_state_machine_height(id: StateMachineId) -> Option<u64> {
Ismp::latest_state_machine_height(id)
}
}

Expand Down

0 comments on commit aa0352e

Please sign in to comment.