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

Commit

Permalink
Canonical events (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizdave97 authored Aug 21, 2023
1 parent 317cb2f commit 3a85db0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
47 changes: 47 additions & 0 deletions ismp/src/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! Canonical ISMP Events

use crate::{
consensus::{ConsensusStateId, StateMachineHeight, StateMachineId},
router::{Get, Post, PostResponse},
};
use alloc::collections::BTreeSet;
use codec::{Decode, Encode};
use scale_info::TypeInfo;

/// Emitted when a state machine is successfully updated to a new height after the challenge period
/// has elapsed
#[derive(Clone, Debug, TypeInfo, Encode, Decode)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub struct StateMachineUpdated {
/// State machine id
pub state_machine_id: StateMachineId,
/// Latest height
pub latest_height: u64,
}

/// Emitted when a challenge period has begun for a consensus client
#[derive(Clone, Debug, TypeInfo, Encode, Decode)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub struct ChallengePeriodStarted {
/// Consensus client id
pub consensus_state_id: ConsensusStateId,
/// Tuple of previous height and latest height
pub state_machines: BTreeSet<(StateMachineHeight, StateMachineHeight)>,
}

/// This represents events that should be emitted by ismp-rs wrappers
#[derive(Clone, Debug, TypeInfo, Encode, Decode)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum Event {
/// Emitted when a state machine is successfully updated to a new height after the challenge
/// period has elapsed
StateMachineUpdated(StateMachineUpdated),
/// Emitted when a challenge period has begun for a consensus client
ChallengePeriodStarted(ChallengePeriodStarted),
/// An event that is emitted when a post request is dispatched
PostRequest(Post),
/// An event that is emitted when a post response is dispatched
PostResponse(PostResponse),
/// An event that is emitted when a get request is dispatched
GetRequest(Get),
}
1 change: 1 addition & 0 deletions ismp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern crate core;

pub mod consensus;
pub mod error;
pub mod events;
pub mod handlers;
pub mod host;
pub mod messaging;
Expand Down
3 changes: 3 additions & 0 deletions ismp/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub struct Get {
/// https://github.com/paritytech/substrate/blob/master/frame/support/src/storage/types/double_map.rs#L34-L44
/// https://github.com/paritytech/substrate/blob/master/frame/support/src/storage/types/nmap.rs#L39-L48
/// https://github.com/paritytech/substrate/blob/master/frame/support/src/storage/types/value.rs#L37
/// For fetching keys from EVM contracts each key should be 52 bytes
/// This should be a concatenation of contract address and slot hash
pub keys: Vec<Vec<u8>>,
/// Height at which to read the state machine.
pub height: u64,
Expand Down Expand Up @@ -316,6 +318,7 @@ pub enum DispatchRequest {
}

/// The Ismp dispatcher allows [`IsmpModules`] to send out outgoing [`Request`] or [`Response`]
/// [`Event`] should be emitted after successful dispatch
pub trait IsmpDispatcher {
/// Dispatches an outgoing request, the dispatcher should commit them to host state trie
fn dispatch_request(&self, request: DispatchRequest) -> Result<(), Error>;
Expand Down

0 comments on commit 3a85db0

Please sign in to comment.