Skip to content

Commit

Permalink
consensus updates (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege authored Apr 24, 2023
1 parent 29e827c commit 14ff707
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
name = "ismp"
version = "0.1.0"
edition = "2021"
authors = ["Polytope Labs"]
description = "Rust implementation of the ISMP protocol"
authors = ["Polytope Labs <[email protected]>"]

[package.metadata.docs.rs]
all-features = true
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! ISMP error definitions

use crate::{
consensus_client::{ConsensusClientId, StateMachineHeight},
consensus::{ConsensusClientId, StateMachineHeight},
host::StateMachine,
};
use alloc::string::String;
Expand Down
8 changes: 3 additions & 5 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! ISMP handler definitions

use crate::{
consensus_client::{ConsensusClient, ConsensusClientId, StateMachineHeight},
consensus::{ConsensusClient, ConsensusClientId, StateMachineHeight},
error::Error,
host::ISMPHost,
messaging::{Message, Proof},
Expand All @@ -29,6 +29,8 @@ mod request;
mod response;
mod timeout;

pub use consensus::create_consensus_client;

pub struct ConsensusUpdateResult {
/// Consensus client Id
pub consensus_client_id: ConsensusClientId,
Expand All @@ -46,7 +48,6 @@ pub enum MessageResult {
ConsensusMessage(ConsensusUpdateResult),
Request(Vec<DispatchResult>),
Response(Vec<DispatchResult>),
ConsensusClientCreated(ConsensusClientCreatedResult),
Timeout(Vec<DispatchResult>),
}

Expand All @@ -59,9 +60,6 @@ where
Message::Consensus(consensus_message) => consensus::handle(host, consensus_message),
Message::Request(req) => request::handle(host, req),
Message::Response(resp) => response::handle(host, resp),
Message::CreateConsensusClient(create_consensus_client_message) => {
consensus::create_consensus_client(host, create_consensus_client_message)
}
Message::Timeout(timeout) => timeout::handle(host, timeout),
}
}
Expand Down
13 changes: 2 additions & 11 deletions src/handlers/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,10 @@ where
pub fn create_consensus_client<H>(
host: &H,
message: CreateConsensusClient,
) -> Result<MessageResult, Error>
) -> Result<ConsensusClientCreatedResult, Error>
where
H: ISMPHost,
{
// Do not attempt to create a new consensus client if consensus state already exists for the
// client
if host.consensus_state(message.consensus_client_id).is_ok() {
return Err(Error::CannotCreateAlreadyExistingConsensusClient {
id: message.consensus_client_id,
})
}

// Store the initial state for the consensus client
host.store_consensus_state(message.consensus_client_id, message.consensus_state)?;

Expand All @@ -116,6 +108,5 @@ where

host.store_consensus_update_time(message.consensus_client_id, host.timestamp())?;

let result = ConsensusClientCreatedResult { consensus_client_id: message.consensus_client_id };
Ok(MessageResult::ConsensusClientCreated(result))
Ok(ConsensusClientCreatedResult { consensus_client_id: message.consensus_client_id })
}
2 changes: 1 addition & 1 deletion src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! The ISMPHost definition

use crate::{
consensus_client::{
consensus::{
ConsensusClient, ConsensusClientId, StateCommitment, StateMachineHeight, StateMachineId,
},
error::Error,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
extern crate alloc;
extern crate core;

pub mod consensus_client;
pub mod consensus;
pub mod error;
pub mod handlers;
pub mod host;
Expand Down
10 changes: 4 additions & 6 deletions src/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! ISMP message types

use crate::{
consensus_client::{ConsensusClientId, IntermediateState, StateMachineHeight},
consensus::{ConsensusClientId, IntermediateState, StateMachineHeight},
router::{Request, Response},
};
use alloc::vec::Vec;
Expand Down Expand Up @@ -76,13 +76,11 @@ pub struct Proof {
#[derive(Debug, Clone, Encode, Decode, scale_info::TypeInfo, PartialEq, Eq)]
pub enum Message {
#[codec(index = 0)]
CreateConsensusClient(CreateConsensusClient),
#[codec(index = 1)]
Consensus(ConsensusMessage),
#[codec(index = 2)]
#[codec(index = 1)]
Request(RequestMessage),
#[codec(index = 3)]
#[codec(index = 2)]
Response(ResponseMessage),
#[codec(index = 4)]
#[codec(index = 3)]
Timeout(TimeoutMessage),
}
2 changes: 1 addition & 1 deletion src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

//! ISMPRouter definition

use crate::{consensus_client::StateMachineHeight, host::StateMachine, prelude::Vec};
use crate::{consensus::StateMachineHeight, host::StateMachine, prelude::Vec};
use alloc::string::String;
use codec::{Decode, Encode};
use core::time::Duration;
Expand Down

0 comments on commit 14ff707

Please sign in to comment.