Skip to content

Commit

Permalink
Merge branch 'master' into andy/tx-sign
Browse files Browse the repository at this point in the history
  • Loading branch information
andynog committed Oct 10, 2020
2 parents 7ae66f2 + e3a8384 commit 4a867a3
Show file tree
Hide file tree
Showing 58 changed files with 900 additions and 458 deletions.
66 changes: 66 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,71 @@
# Changelog

## v0.0.4
*September 30, 2020*

This release focuses on the refinement of the IBC message processor framework, protobuf migration,
adding (de)serialization capability to ICS02 and ICS03 messages and structures.

Additional highlights:
- Added initial implementations for the ICS26 (routing module) and ICS18 (basic relayer algorithms module) for use in testing.
- Also added support for packet handling in the relayer algorithm specifications.

### BREAKING CHANGES:

### FEATURES:
- [modules/ics03] ICS03 Ack and Confirm message processors ([#223])
- [relayer-cli] Relayer CLIs for client messages ([#207])
- [relayer-cli] Relayer CLIs for connection-open-init ([#206])
- [modules] Routing module minimal implementation for MVP ([#159], [#232])
- [spec/relayer] Relayer specification for packet handling ([#229], [#234], [#237])
- [spec/relayer] Basic packet handling in TLA+([#124])
- [modules] Basic relayer functionality: a test with ClientUpdate ping-pong between two mocked chains ([#276])

### IMPROVEMENTS:
- [modules] Implemented the `DomainType` trait for IBC proto structures ([#249]).
- [modules] & [ibc-proto] Several improvements to message processors, among which ([#218]):
- ICS03 connection handshake protocol initial implementation and tests ([#160])
- Add capability to decode from protobuf Any* type into Tendermint and Mock client states
- Cleanup Any* client wrappers related code
- Migrate handlers to newer protobuf definitions ([#226])
- Extend client context mock ([#221])
- [modules/ics03] Split `msgs.rs` in multiple files, implement `From` for all messages ([#253])
- [ibc-proto] Move ibc-proto source code into ibc-rs ([#142])
- [spec/relayer] Add support for APALACHE to the Relayer TLA+ spec ([#165])
- [relayer] Update to tendermint v.0.16 and integrate with the new light client implementation ([#90], [#243])

### BUG FIXES:
- [relayer-cli] Fix for client query subcommands ([#231])
- [disclosure-log] & [spec/connection-handshake] Disclosed bugs in ICS3 version negotiation and proposed a fix ([#209], [#213])

[#90]: https://github.com/informalsystems/ibc-rs/issues/90
[#124]: https://github.com/informalsystems/ibc-rs/issues/124
[#142]: https://github.com/informalsystems/ibc-rs/issues/142
[#159]: https://github.com/informalsystems/ibc-rs/issues/159
[#160]: https://github.com/informalsystems/ibc-rs/issues/160
[#165]: https://github.com/informalsystems/ibc-rs/issues/165
[#206]: https://github.com/informalsystems/ibc-rs/issues/206
[#207]: https://github.com/informalsystems/ibc-rs/issues/207
[#209]: https://github.com/informalsystems/ibc-rs/issues/209
[#213]: https://github.com/informalsystems/ibc-rs/issues/213
[#218]: https://github.com/informalsystems/ibc-rs/issues/218
[#221]: https://github.com/informalsystems/ibc-rs/issues/221
[#223]: https://github.com/informalsystems/ibc-rs/issues/223
[#226]: https://github.com/informalsystems/ibc-rs/issues/226
[#229]: https://github.com/informalsystems/ibc-rs/issues/229
[#231]: https://github.com/informalsystems/ibc-rs/issues/231
[#232]: https://github.com/informalsystems/ibc-rs/issues/232
[#234]: https://github.com/informalsystems/ibc-rs/issues/234
[#237]: https://github.com/informalsystems/ibc-rs/issues/237
[#243]: https://github.com/informalsystems/ibc-rs/issues/243
[#249]: https://github.com/informalsystems/ibc-rs/issues/249
[#253]: https://github.com/informalsystems/ibc-rs/issues/253
[#276]: https://github.com/informalsystems/ibc-rs/issues/276
[ibc-proto]: https://github.com/informalsystems/ibc-rs/tree/master/proto
[disclosure-log]: https://github.com/informalsystems/ibc-rs/blob/master/docs/disclosure-log.md
[spec/connection-handshake]: https://github.com/informalsystems/ibc-rs/tree/master/docs/spec/connection-handshake
[relayer]: https://github.com/informalsystems/ibc-rs/tree/master/relayer

## v0.0.3
*September 1, 2020*

Expand Down
2 changes: 1 addition & 1 deletion modules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ description = """
tendermint-proto = "0.1.0"

# Proto definitions for all IBC-related interfaces, e.g., connections or channels.
ibc-proto = { version = "0.3.0", path = "../proto" }
ibc-proto = { version = "0.4.0", path = "../proto" }

anomaly = "0.2.0"
chrono = "0.4"
Expand Down
27 changes: 16 additions & 11 deletions modules/src/context_mock.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use crate::context::{ChainKeeper, ChainReader, HistoricalInfo, SelfChainType, SelfHeader};
use crate::ics02_client::client_def::{AnyConsensusState, AnyHeader};
use crate::mock_client::header::MockHeader;
use serde_derive::{Deserialize, Serialize};

use std::cmp::min;
use std::convert::TryInto;
use std::error::Error;

use serde_derive::{Deserialize, Serialize};
use tendermint::block::Height;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Default)]
Expand All @@ -21,12 +24,14 @@ impl MockChainContext {
pub fn new(max_size: usize, h: Height) -> Self {
// number of headers to store, if h is 0 nothing is stored
let n = min(max_size as u64, h.value());

Self {
max_size,
latest: h,
history: (0..n)
.rev()
.map(|i| MockHeader(Height(h.value() - i)))
// SAFETY: Call to `unwrap` is safe because we are decreasing the height
.map(|i| MockHeader((h.value() - i).try_into().unwrap()))
.collect(),
}
}
Expand All @@ -39,9 +44,9 @@ impl MockChainContext {
pub fn populate(&mut self, hs: Vec<u64>) {
for h in hs {
self.store_historical_info(
Height(h),
h.try_into().unwrap(),
HistoricalInfo {
header: SelfHeader::Mock(MockHeader(Height(h))),
header: SelfHeader::Mock(MockHeader(h.try_into().unwrap())),
},
);
}
Expand All @@ -53,9 +58,9 @@ impl MockChainContext {
new_h = u64::from(self.latest.increment());
}
self.store_historical_info(
Height(new_h),
new_h.try_into().unwrap(),
HistoricalInfo {
header: SelfHeader::Mock(MockHeader(Height(new_h))),
header: SelfHeader::Mock(MockHeader(new_h.try_into().unwrap())),
},
);
}
Expand Down Expand Up @@ -145,7 +150,7 @@ impl ChainKeeper for MockChainContext {
#[cfg(test)]
mod tests {
use crate::context_mock::MockChainContext;
use tendermint::block::Height;
use std::convert::TryInto;

#[test]
fn test_store_historical_info() {
Expand All @@ -164,22 +169,22 @@ mod tests {
let tests: Vec<Test> = vec![
Test {
name: "Add no prune".to_string(),
ctx: MockChainContext::new(3, Height(0)),
ctx: MockChainContext::new(3, 0_u64.try_into().unwrap()),
args: [1].to_vec(),
},
Test {
name: "Add with prune".to_string(),
ctx: MockChainContext::new(3, Height(2)),
ctx: MockChainContext::new(3, 2_u64.try_into().unwrap()),
args: [3, 4].to_vec(),
},
Test {
name: "Add with initial prune".to_string(),
ctx: MockChainContext::new(3, Height(10)),
ctx: MockChainContext::new(3, 10_u64.try_into().unwrap()),
args: [11].to_vec(),
},
Test {
name: "Attempt to add non sequential headers".to_string(),
ctx: MockChainContext::new(3, Height(2)),
ctx: MockChainContext::new(3, 2_u64.try_into().unwrap()),
args: [3, 5, 7].to_vec(),
},
];
Expand Down
4 changes: 2 additions & 2 deletions modules/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ 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 ev = build_event(RawObject::new(
height.into(),
height.try_into().unwrap(), // TODO: Handle overflow
action.0,
action.1.try_into().unwrap(),
action.1 as usize,
events.clone(),
))
.map_err(|e| e.to_string())?;
Expand Down
26 changes: 15 additions & 11 deletions modules/src/ics02_client/client_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ pub enum AnyClientState {
Mock(MockClientState),
}

impl AnyClientState {
pub fn height(&self) -> Height {
match self {
AnyClientState::Tendermint(tcs) => tcs.latest_height(),

#[cfg(test)]
AnyClientState::Mock(mcs) => mcs.latest_height(),
}
}
}

impl DomainType<Any> for AnyClientState {}

impl TryFrom<Any> for AnyClientState {
Expand Down Expand Up @@ -248,15 +259,6 @@ impl ConsensusState for AnyConsensusState {
todo!()
}

fn height(&self) -> Height {
match self {
AnyConsensusState::Tendermint(cs) => cs.height(),

#[cfg(test)]
AnyConsensusState::Mock(cs) => cs.height(),
}
}

fn root(&self) -> &CommitmentRoot {
todo!()
}
Expand Down Expand Up @@ -476,7 +478,7 @@ mod tests {
use crate::ics07_tendermint::client_state::ClientState;
use crate::ics07_tendermint::header::test_util::get_dummy_header;
use prost_types::Any;
use std::convert::TryFrom;
use std::convert::{TryFrom, TryInto};
use std::time::Duration;

#[test]
Expand All @@ -488,7 +490,9 @@ mod tests {
unbonding_period: Duration::from_secs(128000),
max_clock_drift: Duration::from_millis(3000),
latest_height: tm_header.signed_header.header.height,
frozen_height: 0_u64.into(),
frozen_height: 0_u64.try_into().unwrap(),
allow_update_after_expiry: false,
allow_update_after_misbehaviour: false,
});

let raw: Any = tm_client_state.clone().into();
Expand Down
17 changes: 13 additions & 4 deletions modules/src/ics02_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ pub trait ClientKeeper {
match handler_res {
CreateResult(res) => {
self.store_client_type(res.client_id.clone(), res.client_type)?;
self.store_client_state(res.client_id.clone(), res.client_state)?;
self.store_consensus_state(res.client_id, res.consensus_state)?;
self.store_client_state(res.client_id.clone(), res.client_state.clone())?;
self.store_consensus_state(
res.client_id,
res.client_state.height(),
res.consensus_state,
)?;
}
UpdateResult(res) => {
self.store_client_state(res.client_id.clone(), res.client_state)?;
self.store_consensus_state(res.client_id, res.consensus_state)?;
self.store_client_state(res.client_id.clone(), res.client_state.clone())?;
self.store_consensus_state(
res.client_id,
res.client_state.height(),
res.consensus_state,
)?;
}
}
Ok(())
Expand All @@ -43,6 +51,7 @@ pub trait ClientKeeper {
fn store_consensus_state(
&mut self,
client_id: ClientId,
height: Height,
consensus_state: AnyConsensusState,
) -> Result<(), Error>;
}
10 changes: 7 additions & 3 deletions modules/src/ics02_client/context_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use crate::ics02_client::client_def::{AnyClientState, AnyConsensusState};
use crate::ics02_client::client_type::ClientType;
use crate::ics02_client::context::{ClientKeeper, ClientReader};
use crate::ics02_client::error::{Error, Kind};
use crate::ics02_client::state::ConsensusState;
use crate::ics24_host::identifier::ClientId;
use crate::mock_client::header::MockHeader;
use crate::mock_client::state::{MockClientRecord, MockClientState, MockConsensusState};
use std::collections::HashMap;
use std::convert::TryInto;
use tendermint::block::Height;

/// A mock implementation of client context. This mocks (i.e., replaces) the functionality of
Expand All @@ -25,7 +25,10 @@ pub struct MockClientContext {
impl MockClientContext {
pub fn new(chain_height: u64, max_history_size: usize) -> Self {
MockClientContext {
chain_context: MockChainContext::new(max_history_size, Height(chain_height)),
chain_context: MockChainContext::new(
max_history_size,
chain_height.try_into().unwrap(),
),
clients: Default::default(),
}
}
Expand Down Expand Up @@ -156,6 +159,7 @@ impl ClientKeeper for MockClientContext {
fn store_consensus_state(
&mut self,
client_id: ClientId,
height: Height,
consensus_state: AnyConsensusState,
) -> Result<(), Error> {
match consensus_state {
Expand All @@ -167,7 +171,7 @@ impl ClientKeeper for MockClientContext {
});
client_record
.consensus_states
.insert(consensus_state.height(), consensus_state);
.insert(height, consensus_state);
Ok(())
}
_ => Err(Kind::BadClientState.into()),
Expand Down
Loading

0 comments on commit 4a867a3

Please sign in to comment.