diff --git a/Cargo.lock b/Cargo.lock index 27361705..8f764512 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4233,9 +4233,9 @@ dependencies = [ [[package]] name = "ismp-parachain-inherent" -version = "1.6.2" +version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01640c48d57c367289df9d4e60ff838569ff7fd7efa7807f28fa0ec01eb6bf42" +checksum = "1d14a368b3bac5430c081e386d732f463d3c6af47541a29a02eaacd1ea71053d" dependencies = [ "anyhow", "async-trait", diff --git a/pallets/regions/src/lib.rs b/pallets/regions/src/lib.rs index e0eb431c..88b8ba9d 100644 --- a/pallets/regions/src/lib.rs +++ b/pallets/regions/src/lib.rs @@ -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] @@ -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::::LatestHeightInaccessible)?; // TODO: should requests be coupled in the future? let get = DispatchGet { diff --git a/pallets/regions/src/mock.rs b/pallets/regions/src/mock.rs index 07c91acf..58b86b93 100644 --- a/pallets/regions/src/mock.rs +++ b/pallets/regions/src/mock.rs @@ -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 { + Some(0) } } diff --git a/pallets/regions/src/primitives.rs b/pallets/regions/src/primitives.rs index 17f251fa..ef046d1c 100644 --- a/pallets/regions/src/primitives.rs +++ b/pallets/regions/src/primitives.rs @@ -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; } diff --git a/pallets/regions/src/tests.rs b/pallets/regions/src/tests.rs index fdf04117..4ee136f6 100644 --- a/pallets/regions/src/tests.rs +++ b/pallets/regions/src/tests.rs @@ -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 diff --git a/runtime/regionx/src/lib.rs b/runtime/regionx/src/lib.rs index 5a8c40a6..9e9c4745 100644 --- a/runtime/regionx/src/lib.rs +++ b/runtime/regionx/src/lib.rs @@ -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 { + Ismp::latest_state_machine_height(id) } }