Skip to content

Commit

Permalink
Migration to recent stargate (#449)
Browse files Browse the repository at this point in the history
* Initial migration changes

* More changes, add some of the ack CLIs

* cleanup

* fix packet ack

* clippy and fmt fixes

* Fixed connOpenTry tests; ignored update client tests

* Fixed ack msg tests

* Added next identifier generation in mock context

* Fixed ICS26 tests

* Fix for relayer tests

* Timeout packet, add Uninit for conn and chan, extract clientId

* Fix option order in packet Tx clis

* Tx result parsing (not generalized yet)

* add extern paths back

* WIP General event parsing out of tx response

* change packet envelope to packet

* Make the code compile, return clientID in relayer and CLI

* event parsing and matching for conn open init

* Change tm dependency, fix update client CLI

* log fix and move to cosmos v0.40.0-rc5 (no changes)

* Finished connection CLIs

* Event parsing and fixes for channel open CLIs

* add more event attributes, some refactor of the packet CLIs and packet relaying

* cleanup CLI output for channel, add more fields to events

* Fix relayer connection loop for dynamic IDs

* Fix relayer channel loop for dynamic IDs, started on config cleanup

* Cleanup relayer config

* update Changelog

* fix channel verification for packets

* Fix changelog typo

Co-authored-by: Adi Seredinschi <[email protected]>
  • Loading branch information
ancazamfir and adizere authored Dec 23, 2020
1 parent cfeee01 commit db2be6f
Show file tree
Hide file tree
Showing 117 changed files with 4,767 additions and 3,480 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
## Unreleased Changes

### FEATURES
- Update to tendermint-rs version `0.17` ([#451])
- Update to cosmos-sdk IBC proto version `v0.40.0-rc5` ([#451])

- [relayer]
- Implement relaying for recv_packet ([#379])
- Implement packet relaying ([#379])

- [relayer-cli]
- Packet CLIs for recv_packet ([#443])

- Packet CLIs for acknowledging packets ([#468])

### IMPROVEMENTS
- [relayer]
- Mock chain (implementing IBC handlers) and integration against CLI ([#158])
Expand All @@ -20,6 +24,9 @@
[#381]: https://github.com/informalsystems/ibc-rs/issues/381
[#443]: https://github.com/informalsystems/ibc-rs/issues/443
[#447]: https://github.com/informalsystems/ibc-rs/issues/447
[#451]: https://github.com/informalsystems/ibc-rs/issues/451
[#468]: https://github.com/informalsystems/ibc-rs/issues/468


## v0.0.5
*December 2, 2020*
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ tendermint = { git = "https://github.com/informalsystems/tendermint
tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs", branch = "romac/skip-verif" }
tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs", branch = "romac/skip-verif" }
tendermint-light-client = { git = "https://github.com/informalsystems/tendermint-rs", branch = "romac/skip-verif" }
tendermint-testgen = { git = "https://github.com/informalsystems/tendermint-rs", branch = "romac/skip-verif" }
tendermint-testgen = { git = "https://github.com/informalsystems/tendermint-rs", branch = "romac/skip-verif" }
6 changes: 2 additions & 4 deletions docs/architecture/adr-004-relayer-domain-decomposition.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,11 @@ fn main() -> Result<(), Box<dyn Error>> {

let src_foreign_client_on_dst = ForeignClient::new(
&src_chain_handle,
&dst_chain_handle,
ForeignClientConfig::default())?;
&dst_chain_handle)?;

let dst_foreign_client_on_src = ForeignClient::new(
&src_chain_handle,
&dst_chain_handle,
ForeignClientConfig::default())?;
&dst_chain_handle)?;

let connection = Connection::new(
&src_chain_handle,
Expand Down
4 changes: 2 additions & 2 deletions docs/spec/relayer/Packets.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func CreateDatagram(ev WriteAcknowledgementEvent,

// Stage 1
// Verify if acknowledment is committed to chain A and it is still pending
packetAck, packetAckCommitmentProof, error =
packetAck, PacketStateProof, error =
GetPacketAcknowledgement(chainA, ev.port, ev.channel, ev.sequence, proofHeight)
if error != nil { return (nil, error) }

Expand Down Expand Up @@ -191,6 +191,6 @@ func CreateDatagram(ev WriteAcknowledgementEvent,
data: ev.data
}

return (PacketAcknowledgement { packet, ev.acknowledgement, packetAckCommitmentProof, proofHeight }, nil)
return (PacketAcknowledgement { packet, ev.acknowledgement, PacketStateProof, proofHeight }, nil)
}
```
14 changes: 7 additions & 7 deletions modules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mocks = [ "tendermint-testgen" ]
[dependencies]
# Proto definitions for all IBC-related interfaces, e.g., connections or channels.
ibc-proto = { version = "0.5.0", path = "../proto" }

ics23 = "0.6.0"
anomaly = "0.2.0"
chrono = "0.4"
thiserror = "1.0.11"
Expand All @@ -38,23 +38,23 @@ regex = "1"
bech32 = "0.7.2"

[dependencies.tendermint]
version = "=0.17.0-rc3"
version = "=0.17.0"

[dependencies.tendermint-rpc]
version = "=0.17.0-rc3"
version = "=0.17.0"
features = ["http-client", "websocket-client"]

[dependencies.tendermint-light-client]
version = "=0.17.0-rc3"
version = "=0.17.0"

[dependencies.tendermint-proto]
version = "=0.17.0-rc3"
version = "=0.17.0"

[dependencies.tendermint-testgen]
version = "0.17.0-rc3"
version = "0.17.0"
optional = true

[dev-dependencies]
tokio = { version = "0.2", features = ["macros"] }
subtle-encoding = { version = "0.5" }
tendermint-testgen = { version = "0.17.0-rc3" } # Needed for generating (synthetic) light blocks.
tendermint-testgen = { version = "0.17.0" } # Needed for generating (synthetic) light blocks.
109 changes: 77 additions & 32 deletions modules/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use tendermint::block::Height;

use tendermint::abci::Event;
use tracing::warn;

/// Events types
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum IBCEventType {
CreateClient,
SendPacket,
RecvPacket,
WriteAck,
}

impl IBCEventType {
pub fn as_str(&self) -> &'static str {
match *self {
IBCEventType::CreateClient => "create_client",
IBCEventType::SendPacket => "send_packet",
_ => "unhandled",
IBCEventType::WriteAck => "write_acknowledgement",
}
}
}
Expand Down Expand Up @@ -54,13 +57,32 @@ pub enum IBCEvent {

SendPacketChannel(ChannelEvents::SendPacket),
ReceivePacketChannel(ChannelEvents::ReceivePacket),
WriteAcknowledgementChannel(ChannelEvents::WriteAcknowledgement),
AcknowledgePacketChannel(ChannelEvents::AcknowledgePacket),
CleanupPacketChannel(ChannelEvents::CleanupPacket),
TimeoutPacketChannel(ChannelEvents::TimeoutPacket),

TimeoutTransfer(TransferEvents::Timeout),
PacketTransfer(TransferEvents::Packet),
ChannelClosedTransfer(TransferEvents::ChannelClosed),

Empty(String), // Special event, signifying empty response
ChainError(String), // Special event, signifying an error on CheckTx or DeliverTx
}

// This is tendermint specific
pub fn from_tx_response_event(event: Event) -> Option<IBCEvent> {
// Return the first hit we find
// Look for client event...
if let Some(client_res) = ClientEvents::try_from_tx(event.clone()) {
return Some(client_res);
// Look for connection event...
} else if let Some(conn_res) = ConnectionEvents::try_from_tx(event.clone()) {
return Some(conn_res);
} else if let Some(chan_res) = ChannelEvents::try_from_tx(event) {
return Some(chan_res);
}

None
}

impl IBCEvent {
Expand All @@ -70,9 +92,13 @@ impl IBCEvent {
pub fn height(&self) -> Height {
match self {
IBCEvent::NewBlock(bl) => bl.height,
IBCEvent::UpdateClient(uc) => uc.height,
IBCEvent::SendPacketChannel(ev) => ev.envelope.height,
IBCEvent::UpdateClient(uc) => *uc.height(),
IBCEvent::SendPacketChannel(ev) => ev.height,
IBCEvent::ReceivePacketChannel(ev) => ev.height,
IBCEvent::WriteAcknowledgementChannel(ev) => ev.height,
IBCEvent::AcknowledgePacketChannel(ev) => ev.height,
IBCEvent::TimeoutPacketChannel(ev) => ev.height,

_ => {
unimplemented!()
}
Expand All @@ -81,7 +107,19 @@ impl IBCEvent {
pub fn set_height(&mut self, height: ICSHeight) {
match self {
IBCEvent::SendPacketChannel(ev) => {
ev.envelope.height = Height::try_from(height.version_height).unwrap()
ev.height = Height::try_from(height.revision_height).unwrap()
}
IBCEvent::ReceivePacketChannel(ev) => {
ev.height = Height::try_from(height.revision_height).unwrap()
}
IBCEvent::WriteAcknowledgementChannel(ev) => {
ev.height = Height::try_from(height.revision_height).unwrap()
}
IBCEvent::AcknowledgePacketChannel(ev) => {
ev.height = Height::try_from(height.revision_height).unwrap()
}
IBCEvent::TimeoutPacketChannel(ev) => {
ev.height = Height::try_from(height.revision_height).unwrap()
}
_ => {
unimplemented!()
Expand Down Expand Up @@ -200,15 +238,17 @@ pub fn get_all_events(result: RpcEvent) -> Result<Vec<(Height, IBCEvent)>, Strin
Ok(vals)
}

pub fn build_event(object: RawObject) -> Result<IBCEvent, BoxError> {
pub fn build_event(mut object: RawObject) -> Result<IBCEvent, BoxError> {
match object.action.as_str() {
// Client events
"create_client" => Ok(IBCEvent::from(ClientEvents::CreateClient::try_from(
object,
)?)),
"update_client" => Ok(IBCEvent::from(ClientEvents::UpdateClient::try_from(
object,
)?)),

// Connection events
"connection_open_init" => Ok(IBCEvent::from(ConnectionEvents::OpenInit::try_from(
object,
)?)),
Expand All @@ -218,6 +258,7 @@ pub fn build_event(object: RawObject) -> Result<IBCEvent, BoxError> {
object,
)?)),

// Channel events
"channel_open_init" => Ok(IBCEvent::from(ChannelEvents::OpenInit::try_from(object)?)),
"channel_open_try" => Ok(IBCEvent::from(ChannelEvents::OpenTry::try_from(object)?)),
"channel_open_ack" => Ok(IBCEvent::from(ChannelEvents::OpenAck::try_from(object)?)),
Expand All @@ -229,33 +270,30 @@ pub fn build_event(object: RawObject) -> Result<IBCEvent, BoxError> {
object,
)?)),

// send_packet
"transfer" => Ok(IBCEvent::from(ChannelEvents::SendPacket::try_from(object)?)),
// recv_packet
"ics04/opaque" => Ok(IBCEvent::from(ChannelEvents::ReceivePacket::try_from(
object,
)?)),
// acknowledge_packet
// needs these changes in cosmos-sdk
// --- a/x/ibc/04-channel/types/msgs.go
// +++ b/x/ibc/04-channel/types/msgs.go
// @@ -511,5 +511,5 @@ func (msg MsgAcknowledgement) GetSigners() []sdk.AccAddress {
//
// // Type implements sdk.Msg
// func (msg MsgAcknowledgement) Type() string {
// - return "ics04/opaque"
// + return "ics04/acknowledge"
// }
"ics04/acknowledge" => Ok(IBCEvent::from(ChannelEvents::AcknowledgePacket::try_from(
object,
)?)),
//timeout_packet
"ics04/timeout" => Ok(IBCEvent::from(ChannelEvents::TimeoutPacket::try_from(
// Packet events
// Note: There is no message.action "send_packet", the only one we can hook into is the
// module's action, "transfer" being the only one in IBC1.0. However the attributes
// are all prefixed with "send_packet" therefore the overwrite here
// TODO: This need to be sorted out
"transfer" => {
object.action = "send_packet".to_string();
Ok(IBCEvent::from(ChannelEvents::SendPacket::try_from(object)?))
}
// Same here
// TODO: sort this out
"recv_packet" => {
object.action = "write_acknowledgement".to_string();
Ok(IBCEvent::from(
ChannelEvents::WriteAcknowledgement::try_from(object)?,
))
}
"write_acknowledgement" => Ok(IBCEvent::from(
ChannelEvents::WriteAcknowledgement::try_from(object)?,
)),
"acknowledge_packet" => Ok(IBCEvent::from(ChannelEvents::AcknowledgePacket::try_from(
object,
)?)),

// TODO not clear what the message.action for this is
"cleanup_packet" => Ok(IBCEvent::from(ChannelEvents::CleanupPacket::try_from(
"timeout_packet" => Ok(IBCEvent::from(ChannelEvents::TimeoutPacket::try_from(
object,
)?)),

Expand Down Expand Up @@ -290,3 +328,10 @@ macro_rules! attribute {
$a.events.get($b).ok_or($b)?[$a.idx].parse()?
};
}

#[macro_export]
macro_rules! some_attribute {
($a:ident, $b:literal) => {
$a.events.get($b).ok_or($b)?[$a.idx].parse().ok()
};
}
13 changes: 13 additions & 0 deletions modules/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ impl Attribute {
pub fn new(key: String, value: String) -> Self {
Self { key, value }
}

pub fn value(&self) -> String {
self.value.clone()
}

pub fn key(&self) -> String {
self.key.clone()
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand All @@ -34,6 +42,11 @@ impl Event {
.collect(),
}
}

/// Returns a vector containing the values within all attributes of this event
pub fn attribute_values(&self) -> Vec<String> {
self.attributes.iter().map(|a| a.value.clone()).collect()
}
}

pub type HandlerResult<T, E> = Result<HandlerOutput<T>, E>;
Expand Down
14 changes: 7 additions & 7 deletions modules/src/ics02_client/client_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::ics07_tendermint::client_def::TendermintClient;
use crate::ics07_tendermint::client_state::ClientState as TendermintClientState;
use crate::ics07_tendermint::consensus_state::ConsensusState as TendermintConsensusState;
use crate::ics07_tendermint::header::Header as TendermintHeader;
use crate::ics23_commitment::commitment::{CommitmentPrefix, CommitmentProof, CommitmentRoot};
use crate::ics23_commitment::commitment::{CommitmentPrefix, CommitmentProofBytes, CommitmentRoot};
use crate::ics24_host::identifier::{ClientId, ConnectionId};
use crate::Height;

Expand Down Expand Up @@ -58,7 +58,7 @@ pub trait ClientDef: Clone {
client_state: &Self::ClientState,
height: Height,
prefix: &CommitmentPrefix,
proof: &CommitmentProof,
proof: &CommitmentProofBytes,
client_id: &ClientId,
consensus_height: Height,
expected_consensus_state: &AnyConsensusState,
Expand All @@ -70,7 +70,7 @@ pub trait ClientDef: Clone {
client_state: &Self::ClientState,
height: Height,
prefix: &CommitmentPrefix,
proof: &CommitmentProof,
proof: &CommitmentProofBytes,
connection_id: &ConnectionId,
expected_connection_end: &ConnectionEnd,
) -> Result<(), Box<dyn std::error::Error>>;
Expand All @@ -84,7 +84,7 @@ pub trait ClientDef: Clone {
root: &CommitmentRoot,
prefix: &CommitmentPrefix,
client_id: &ClientId,
proof: &CommitmentProof,
proof: &CommitmentProofBytes,
client_state: &AnyClientState,
) -> Result<(), Box<dyn std::error::Error>>;
}
Expand Down Expand Up @@ -403,7 +403,7 @@ impl ClientDef for AnyClient {
client_state: &Self::ClientState,
height: Height,
prefix: &CommitmentPrefix,
proof: &CommitmentProof,
proof: &CommitmentProofBytes,
client_id: &ClientId,
consensus_height: Height,
expected_consensus_state: &AnyConsensusState,
Expand Down Expand Up @@ -451,7 +451,7 @@ impl ClientDef for AnyClient {
client_state: &AnyClientState,
height: Height,
prefix: &CommitmentPrefix,
proof: &CommitmentProof,
proof: &CommitmentProofBytes,
connection_id: &ConnectionId,
expected_connection_end: &ConnectionEnd,
) -> Result<(), Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -494,7 +494,7 @@ impl ClientDef for AnyClient {
root: &CommitmentRoot,
prefix: &CommitmentPrefix,
client_id: &ClientId,
proof: &CommitmentProof,
proof: &CommitmentProofBytes,
client_state_on_counterparty: &AnyClientState,
) -> Result<(), Box<dyn std::error::Error>> {
match self {
Expand Down
Loading

0 comments on commit db2be6f

Please sign in to comment.