Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chain Runtime implementation #364

Merged
merged 66 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
1f4b0d4
Started v0 impl: re-arranging handlers + initialization.
adizere Oct 29, 2020
8ef0d63
Clean up chain handle, prepare for generic client creation.
adizere Oct 29, 2020
4291e74
Trying different boundaries of abstraction b/t ForeignClient and Chai…
adizere Oct 30, 2020
dcef8a7
Version one: introduced assemble_ methods to construct chain-specific…
adizere Oct 30, 2020
d00cb98
Removed signer from foreign client config
adizere Nov 3, 2020
0eb1611
Merge branch 'master' into adi/346_V0_implementation
adizere Nov 3, 2020
23e750a
FMT quick fix
adizere Nov 3, 2020
3c82990
Client ID parsing
adizere Nov 4, 2020
4c24b67
Use ibc::ics24_host::identifier::ChainId instead of its tendermint c…
romac Nov 3, 2020
52d9fba
More error handling and split into modules
romac Nov 3, 2020
394a824
Move prod handle in its own module
romac Nov 5, 2020
9854506
Cleanup
romac Nov 5, 2020
9f1a42e
Overhaul subscriptions handling
romac Nov 5, 2020
b1baf7e
Add struct to represent a batch of events
romac Nov 5, 2020
a7112ba
Move SplitResults trait into its own module
romac Nov 5, 2020
2809cbd
WIP: More handle inputs
romac Nov 5, 2020
89e5320
Better errors
romac Nov 10, 2020
cc71d0c
Implement `query` in chain runtime
romac Nov 10, 2020
189bde0
Assemble client state and consensus state in runtime
romac Nov 10, 2020
9dd2a8a
Launch light clients
romac Nov 11, 2020
cab6f72
Light Block
romac Nov 11, 2020
166352d
Merge branch 'master' into adi/346_V0_implementation
adizere Nov 11, 2020
17ba302
Merge branch 'adi/346_V0_implementation' into romac/chain-runtime
romac Nov 11, 2020
ef82617
Merge branch 'master' into romac/chain-runtime
romac Nov 12, 2020
357d7c2
Remove unused file
romac Nov 12, 2020
75f6c20
Rename two handle inputs
romac Nov 12, 2020
ea7a588
Rename Chain::ics_query to Chain::query
romac Nov 12, 2020
3fbae91
Store the domain MerkleProof in QueryResponse instead of the raw Merk…
romac Nov 12, 2020
2c91aa8
Implement all chain methods in runtime + handle
romac Nov 12, 2020
ea403a4
Chain methods should return their Self types
romac Nov 12, 2020
3bb1df7
Use light client to build consensus state
romac Nov 12, 2020
8529d7f
Use light client to retrieve and build header
romac Nov 12, 2020
4163661
Comment out currently unused code
romac Nov 12, 2020
8e71d74
Merge branch 'master' into romac/chain-runtime
romac Nov 12, 2020
e11ac5c
Formatting
romac Nov 12, 2020
7af91b1
Make keybase field of CosmosSDKChain private
romac Nov 13, 2020
2afa90f
Fix tests
romac Nov 13, 2020
595a55e
Properly spawn runtime
romac Nov 13, 2020
e2b4e41
Revert 2afa90f
romac Nov 13, 2020
45ae7b8
Allow a ChainId to not include version number, default to 0
romac Nov 13, 2020
6b21e71
Upgrade Tokio to version 0.3
romac Nov 16, 2020
121941d
WIP: event monitor
romac Nov 16, 2020
1dcd491
Merge branch 'romac/upgrade-tokio' into romac/chain-runtime
romac Nov 17, 2020
ae1cabb
Syncify EventMonitor
romac Nov 17, 2020
c9590f0
Cleanup
romac Nov 17, 2020
e8c6c7b
Use shared Tokio runtime to `block_on` instead of spawning new one
romac Nov 17, 2020
e07a14b
Cleanup
romac Nov 17, 2020
5fd713a
Nest event_handler and event_monitor modules under event module
romac Nov 17, 2020
a75b92f
WIP: event bus
romac Nov 17, 2020
272ec49
Cleanup
romac Nov 17, 2020
3945107
Fix build issue
romac Nov 17, 2020
32dd4ad
Add tests for event bus
romac Nov 17, 2020
241e91d
Cleanup
romac Nov 17, 2020
5a48642
Update listen command
romac Nov 17, 2020
3ccb639
Point to tendermint-rs branch with Tokio 0.3
romac Nov 17, 2020
f1c951c
Remove unused downcast_* methods
romac Nov 18, 2020
3e74928
Re-enable some lints
romac Nov 18, 2020
b071a5e
Cleanup
romac Nov 18, 2020
e43dbfa
Merge branch 'master' into romac/chain-runtime
romac Nov 19, 2020
052d4f7
Merge branch 'master' into romac/chain-runtime
romac Nov 19, 2020
52eb208
Merge branch 'master' into romac/chain-runtime
romac Nov 20, 2020
de190ab
Use tendermint-rs master
romac Nov 20, 2020
835e002
Depend on tendermint-rs prost-dev branch
romac Nov 20, 2020
dcae53d
Merge branch 'master' into romac/chain-runtime
romac Nov 23, 2020
96d66a4
Formatting
romac Nov 23, 2020
1e6a02a
Deserialize client queries in Any types, temp fix for validator set
ancazamfir Nov 23, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,19 @@ members = [

exclude = [
"proto-compiler"
]
]

[patch.crates-io]
tendermint = { git = "https://github.com/informalsystems/tendermint-rs", branch = "romac/prost-dev" }
tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs", branch = "romac/prost-dev" }
tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs", branch = "romac/prost-dev" }
tendermint-light-client = { git = "https://github.com/informalsystems/tendermint-rs", branch = "romac/prost-dev" }

bytes = { git = "https://github.com/tokio-rs/bytes", tag = "v0.6.0" }

tonic = { git = "https://github.com/romac/tonic", branch = "romac/hyper-0.14-dev" }

prost = { git = "https://github.com/danburkert/prost", branch = "master" }
prost-types = { git = "https://github.com/danburkert/prost", branch = "master" }
prost-build = { git = "https://github.com/danburkert/prost", branch = "master" }
prost-derive = { git = "https://github.com/danburkert/prost", branch = "master" }
18 changes: 10 additions & 8 deletions modules/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,16 @@ fn extract_helper(events: &HashMap<String, Vec<String>>) -> Result<Vec<(String,
Ok(result)
}

pub fn get_all_events(result: RpcEvent) -> Result<Vec<IBCEvent>, String> {
let mut vals: Vec<IBCEvent> = vec![];
pub fn get_all_events(result: RpcEvent) -> Result<Vec<(Height, IBCEvent)>, String> {
let mut vals: Vec<(Height, IBCEvent)> = vec![];

match &result.data {
RpcEventData::NewBlock { block, .. } => {
let block = block.as_ref().ok_or("missing block")?;
vals.push(NewBlock::new(block.header.height).into());
vals.push((
block.header.height,
NewBlock::new(block.header.height).into(),
));
}

RpcEventData::Tx { .. } => {
Expand All @@ -142,21 +145,20 @@ pub fn get_all_events(result: RpcEvent) -> Result<Vec<IBCEvent>, String> {

let actions_and_indices = extract_helper(&events)?;
for action in actions_and_indices {
let event = build_event(RawObject::new(
match build_event(RawObject::new(
height,
action.0,
action.1 as usize,
events.clone(),
));

match event {
Ok(event) => vals.push(event),
)) {
Ok(event) => vals.push((height, event)),
Err(e) => warn!("error while building event {}", e.to_string()),
}
}
}
_ => {}
}

Ok(vals)
}

Expand Down
12 changes: 12 additions & 0 deletions modules/src/ics02_client/client_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ impl Header for AnyHeader {
Self::Mock(header) => header.height(),
}
}

fn wrap_any(self) -> AnyHeader {
self
}
}

impl Protobuf<Any> for AnyHeader {}
Expand Down Expand Up @@ -246,6 +250,10 @@ impl ClientState for AnyClientState {
AnyClientState::Mock(mock_state) => mock_state.is_frozen(),
}
}

fn wrap_any(self) -> AnyClientState {
self
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -318,6 +326,10 @@ impl ConsensusState for AnyConsensusState {
fn validate_basic(&self) -> Result<(), Box<dyn std::error::Error>> {
todo!()
}

fn wrap_any(self) -> AnyConsensusState {
self
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down
7 changes: 6 additions & 1 deletion modules/src/ics02_client/header.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use crate::ics02_client::client_type::ClientType;
use crate::Height;

use super::client_def::AnyHeader;

/// Abstract of consensus state update information
#[dyn_clonable::clonable]
pub trait Header: Clone + std::fmt::Debug {
pub trait Header: Clone + std::fmt::Debug + Send + Sync {
/// The type of client (eg. Tendermint)
fn client_type(&self) -> ClientType;

/// The height of the consensus state
fn height(&self) -> Height;

/// Wrap into an `AnyHeader`
fn wrap_any(self) -> AnyHeader;
}
15 changes: 12 additions & 3 deletions modules/src/ics02_client/state.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use super::client_type::ClientType;
use super::{
client_def::{AnyClientState, AnyConsensusState},
client_type::ClientType,
};
use crate::ics23_commitment::commitment::CommitmentRoot;
use crate::Height;

#[dyn_clonable::clonable]
pub trait ConsensusState: Clone + std::fmt::Debug {
pub trait ConsensusState: Clone + std::fmt::Debug + Send + Sync {
/// Type of client associated with this consensus state (eg. Tendermint)
fn client_type(&self) -> ClientType;

Expand All @@ -12,10 +15,13 @@ pub trait ConsensusState: Clone + std::fmt::Debug {

/// Performs basic validation of the consensus state
fn validate_basic(&self) -> Result<(), Box<dyn std::error::Error>>;

/// Wrap into an `AnyConsensusState`
fn wrap_any(self) -> AnyConsensusState;
}

#[dyn_clonable::clonable]
pub trait ClientState: Clone + std::fmt::Debug {
pub trait ClientState: Clone + std::fmt::Debug + Send + Sync {
/// Client ID of this state
fn chain_id(&self) -> String;

Expand All @@ -27,4 +33,7 @@ pub trait ClientState: Clone + std::fmt::Debug {

/// Freeze status of the client
fn is_frozen(&self) -> bool;

/// Wrap into an `AnyClientState`
fn wrap_any(self) -> AnyClientState;
}
2 changes: 1 addition & 1 deletion modules/src/ics03_connection/handler/conn_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ mod tests {
// Parametrize the (correct) host chain to have a height at least as recent as the
// the height of the proofs in the Ack msg.
let correct_context = MockContext::new(
ChainId::new("mockgaia", 1).unwrap(),
ChainId::new("mockgaia".to_string(), 1),
HostType::Mock,
5,
Height::new(1, msg_ack.proofs().height().increment().version_height),
Expand Down
2 changes: 1 addition & 1 deletion modules/src/ics03_connection/handler/conn_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ mod tests {

let host_chain_height = Height::new(1, 35);
let context = MockContext::new(
ChainId::new("mockgaia", 1).unwrap(),
ChainId::new("mockgaia".to_string(), 1),
HostType::Mock,
5,
host_chain_height,
Expand Down
10 changes: 7 additions & 3 deletions modules/src/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use tendermint::consensus::Params;
use tendermint_light_client::types::TrustThreshold;
use tendermint_proto::Protobuf;

use crate::Height;

use crate::ics02_client::client_def::AnyClientState;
use crate::ics02_client::client_type::ClientType;
use crate::ics07_tendermint::error::{Error, Kind};
use crate::ics07_tendermint::header::Header;
use crate::ics23_commitment::merkle::cosmos_specs;
use crate::Height;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ClientState {
Expand Down Expand Up @@ -123,6 +123,10 @@ impl crate::ics02_client::state::ClientState for ClientState {
// If 'frozen_height' is set to a non-zero value, then the client state is frozen.
!self.frozen_height.is_zero()
}

fn wrap_any(self) -> AnyClientState {
AnyClientState::Tendermint(self)
}
}

impl TryFrom<RawClientState> for ClientState {
Expand Down Expand Up @@ -360,7 +364,7 @@ pub mod test_util {
Duration::from_secs(128000),
Duration::from_millis(3000),
Height::new(
ChainId::chain_version(tm_header.chain_id.to_string()),
ChainId::chain_version(tm_header.chain_id.as_str()),
u64::from(tm_header.height),
),
Height::zero(),
Expand Down
6 changes: 5 additions & 1 deletion modules/src/ics07_tendermint/consensus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tendermint::time::Time;
use tendermint::Hash;
use tendermint_proto::Protobuf;

use crate::ics02_client::client_type::ClientType;
use crate::ics02_client::{client_def::AnyConsensusState, client_type::ClientType};
use crate::ics07_tendermint::error::{Error, Kind};
use crate::ics07_tendermint::header::Header;
use crate::ics23_commitment::commitment::CommitmentRoot;
Expand Down Expand Up @@ -42,6 +42,10 @@ impl crate::ics02_client::state::ConsensusState for ConsensusState {
fn validate_basic(&self) -> Result<(), Box<dyn std::error::Error>> {
unimplemented!()
}

fn wrap_any(self) -> AnyConsensusState {
AnyConsensusState::Tendermint(self)
}
}

impl Protobuf<RawConsensusState> for ConsensusState {}
Expand Down
8 changes: 6 additions & 2 deletions modules/src/ics07_tendermint/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tendermint_proto::Protobuf;

use ibc_proto::ibc::lightclients::tendermint::v1::Header as RawHeader;

use crate::ics02_client::client_type::ClientType;
use crate::ics02_client::{client_def::AnyHeader, client_type::ClientType};
use crate::ics07_tendermint::error::{Error, Kind};
use crate::ics24_host::identifier::ChainId;
use crate::Height;
Expand All @@ -27,10 +27,14 @@ impl crate::ics02_client::header::Header for Header {

fn height(&self) -> Height {
Height::new(
ChainId::chain_version(self.signed_header.header.chain_id.to_string()),
ChainId::chain_version(self.signed_header.header.chain_id.as_str()),
u64::from(self.signed_header.header.height),
)
}

fn wrap_any(self) -> AnyHeader {
AnyHeader::Tendermint(self)
}
}

impl Protobuf<RawHeader> for Header {}
Expand Down
4 changes: 2 additions & 2 deletions modules/src/ics18_relayer/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mod tests {

// Create two mock contexts, one for each chain.
let mut ctx_a = MockContext::new(
ChainId::new("mockgaiaA", 1).unwrap(),
ChainId::new("mockgaiaA".to_string(), 1),
HostType::Mock,
5,
chain_a_start_height,
Expand All @@ -93,7 +93,7 @@ mod tests {
Some(client_on_a_for_b_height),
);
let mut ctx_b = MockContext::new(
ChainId::new("mockgaiaB", 1).unwrap(),
ChainId::new("mockgaiaB".to_string(), 1),
HostType::SyntheticTendermint,
5,
chain_b_start_height,
Expand Down
12 changes: 11 additions & 1 deletion modules/src/ics23_commitment/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof;

use crate::ics23_commitment::error::{Error, Kind};

use super::merkle::MerkleProof;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CommitmentRoot(pub Vec<u8>); // Todo: write constructor
impl CommitmentRoot {
Expand Down Expand Up @@ -45,6 +47,13 @@ impl From<CommitmentProof> for Vec<u8> {
}
}

impl From<MerkleProof> for CommitmentProof {
fn from(proof: MerkleProof) -> Self {
let raw_proof: RawMerkleProof = proof.into();
raw_proof.into()
}
}

impl From<RawMerkleProof> for CommitmentProof {
fn from(proof: RawMerkleProof) -> Self {
let mut buf = Vec::new();
Expand All @@ -64,8 +73,9 @@ impl TryFrom<CommitmentProof> for RawMerkleProof {
}
}

// TODO: decent getter or Protobuf trait implementation
#[derive(Clone, PartialEq, Eq)]
pub struct CommitmentPrefix(pub Vec<u8>); // Todo: decent getter or DomainType trait implementation
pub struct CommitmentPrefix(pub Vec<u8>);

impl CommitmentPrefix {
pub fn is_empty(&self) -> bool {
Expand Down
Loading