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

Forward NewBlock events to all workers to clear pending packets if needed #733

Merged
merged 6 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion guide/src/tutorial_raw.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Currently, cosmos-SDK implementation uses:
- `connection-<n>` for connections
- For example `connection-0` is assigned to the first connection created on `ibc-1`:
```shell
tx raw conn-init ibc-1 ibc-0 07-tendermint-0 07-tendermint-0 | jq
hermes tx raw conn-init ibc-1 ibc-0 07-tendermint-0 07-tendermint-0 | jq
```
```json
{
Expand Down
4 changes: 3 additions & 1 deletion relayer-cli/src/conclude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
//! #[derive(Debug, Error)]
//! pub enum Kind {
//! #[error("failed with underlying causes: {0}, {1}")]
//! Query(String, String), // ...
//! Query(String, String),
//! // ...
//! }
//! ```
//!
//! - Exit from a query/tx with success:
Expand Down
6 changes: 6 additions & 0 deletions relayer/src/event/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ pub struct EventBatch {
pub events: Vec<IbcEvent>,
}

impl EventBatch {
pub fn unwrap_or_clone(self: Arc<Self>) -> Self {
Arc::try_unwrap(self).unwrap_or_else(|batch| batch.as_ref().clone())
}
}

type SubscriptionResult = Result<tendermint_rpc::event::Event, tendermint_rpc::Error>;
type SubscriptionStream = dyn Stream<Item = SubscriptionResult> + Send + Sync + Unpin;

Expand Down
25 changes: 15 additions & 10 deletions relayer/src/link.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::thread;
use std::time::Duration;
use std::{sync::Arc, thread};

use prost_types::Any;
use thiserror::Error;
Expand Down Expand Up @@ -411,19 +411,24 @@ impl RelayPath {
Err(LinkError::OldPacketClearingFailed)
}

/// Iterate through the IBC Events, build the message for each and collect all at same height.
/// Send a multi message transaction with these, prepending the client update
pub fn relay_from_events(&mut self, batch: Arc<EventBatch>) -> Result<(), LinkError> {
pub fn clear_packets(&mut self, height: Height) -> Result<(), LinkError> {
if self.clear_packets {
self.src_height = batch
.height
self.src_height = height
.decrement()
.map_err(|e| LinkError::Failed(e.to_string()))?;

self.relay_pending_packets()?;
self.clear_packets = false;
}

Ok(())
}

/// Iterate through the IBC Events, build the message for each and collect all at same height.
/// Send a multi message transaction with these, prepending the client update
pub fn relay_from_events(&mut self, batch: EventBatch) -> Result<(), LinkError> {
self.clear_packets(batch.height)?;

// collect relevant events in self.all_events
self.collect_events(&batch.events);
self.adjust_events_height()?;
Expand Down Expand Up @@ -893,12 +898,12 @@ impl Link {
return Ok(());
}

if let Ok(events) = events_a.try_recv() {
self.a_to_b.relay_from_events(events)?;
if let Ok(batch) = events_a.try_recv() {
self.a_to_b.relay_from_events(batch.unwrap_or_clone())?;
}

if let Ok(events) = events_b.try_recv() {
self.b_to_a.relay_from_events(events)?;
if let Ok(batch) = events_b.try_recv() {
self.b_to_a.relay_from_events(batch.unwrap_or_clone())?;
}

// TODO - select over the two subscriptions
Expand Down
Loading