Skip to content

Commit

Permalink
Merge pull request #6 from bandprotocol/support-wasm-delay-1.1
Browse files Browse the repository at this point in the history
Support wasm, delay for v1.1.x
  • Loading branch information
RogerKSI authored Feb 1, 2023
2 parents 0daa3e1 + e5d7829 commit 0dff8aa
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 40 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,3 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# (optional)
CARGO_PROFILE_RELEASE_LTO: true
docker-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Get release version
run: echo "TAG=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./ci/release/
file: ./ci/release/hermes.Dockerfile
push: true
build-args: TAG=v${{env.TAG}}
tags: informalsystems/hermes:${{env.TAG}}
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,30 @@ See the table below for more details.
The repository also includes [TLA+ specifications](docs/spec).

## Band Implementation

- **Support Wasm Contract**
- **Add more chain config to ignore certain acknowledge packet**

add a config named 'ignore_port_channel' in chain config that recieve a list of destination port and channel id to ignore

e.g. ignore_port_channel = [{ channel_id = 'channel-64', port_id = 'oracle'}]
- **Add a global config that delay the packet sending used for backup hermes**

add a config named 'packet_delay' in global config that received the duration.

e.g. packet_delay = '10s'

## Status

| Crate name | Type | Version | Docs |
|:-------------:|:------:|:-------------:|:-----:|
| [ibc-relayer-cli](crates/relayer-cli) | bin: [hermes](crates/relayer-cli/) | [![IBC Relayer CLI Crate][relayer-cli-crate-image]][relayer-cli-crate-link] | [![IBC Relayer CLI Docs][relayer-cli-docs-image]][relayer-cli-docs-link] |
| [ibc-relayer](crates/relayer) | lib | [![IBC Relayer Crate][relayer-crate-image]][relayer-crate-link] | [![IBC Relayer Docs][relayer-docs-image]][relayer-docs-link] |
| [ibc-chain-registry](crates/ibc-chain-registry) | lib | [![Chain Registry Crate][ibc-chain-registry-crate-image]][ibc-chain-registry-crate-link] | [![Chain Registry Docs][ibc-chain-registry-docs-image]][ibc-chain-registry-docs-link] |
| [ibc-relayer-rest](crates/relayer-rest) | lib | [![IBC Relayer REST Crate][relayer-rest-crate-image]][relayer-rest-crate-link] | [![IBC Relayer REST Docs][relayer-rest-docs-image]][relayer-rest-docs-link] |
| [ibc-telemetry](crates/telemetry) | lib | [![IBC Telemetry Crate][ibc-telemetry-crate-image]][ibc-telemetry-crate-link] | [![IBC Telemetry Docs][ibc-telemetry-docs-image]][ibc-telemetry-docs-link] |
| [ibc-test-framework](./tools/test-framework) | lib | [![IBC Test Framework Crate][ibc-test-framework-crate-image]][ibc-test-framework-crate-link] | [![IBC Test Framework Docs][ibc-test-framework-docs-image]][ibc-test-framework-docs-link] |
| Crate name | Type | Version | Docs |
| :---------------------------------------------: | :--------------------------------: | :------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------: |
| [ibc-relayer-cli](crates/relayer-cli) | bin: [hermes](crates/relayer-cli/) | [![IBC Relayer CLI Crate][relayer-cli-crate-image]][relayer-cli-crate-link] | [![IBC Relayer CLI Docs][relayer-cli-docs-image]][relayer-cli-docs-link] |
| [ibc-relayer](crates/relayer) | lib | [![IBC Relayer Crate][relayer-crate-image]][relayer-crate-link] | [![IBC Relayer Docs][relayer-docs-image]][relayer-docs-link] |
| [ibc-chain-registry](crates/ibc-chain-registry) | lib | [![Chain Registry Crate][ibc-chain-registry-crate-image]][ibc-chain-registry-crate-link] | [![Chain Registry Docs][ibc-chain-registry-docs-image]][ibc-chain-registry-docs-link] |
| [ibc-relayer-rest](crates/relayer-rest) | lib | [![IBC Relayer REST Crate][relayer-rest-crate-image]][relayer-rest-crate-link] | [![IBC Relayer REST Docs][relayer-rest-docs-image]][relayer-rest-docs-link] |
| [ibc-telemetry](crates/telemetry) | lib | [![IBC Telemetry Crate][ibc-telemetry-crate-image]][ibc-telemetry-crate-link] | [![IBC Telemetry Docs][ibc-telemetry-docs-image]][ibc-telemetry-docs-link] |
| [ibc-test-framework](./tools/test-framework) | lib | [![IBC Test Framework Crate][ibc-test-framework-crate-image]][ibc-test-framework-crate-link] | [![IBC Test Framework Docs][ibc-test-framework-docs-image]][ibc-test-framework-docs-link] |


## Requirements
Expand Down
144 changes: 144 additions & 0 deletions config_example.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# The global section has parameters that apply globally to the relayer operation.
[global]

# Specify the verbosity for the relayer logging output. Default: 'info'
# Valid options are 'error', 'warn', 'info', 'debug', 'trace'.
log_level = 'trace'
packet_delay = '0s'

# Specify the mode to be used by the relayer. [Required]
[mode]

# Specify the client mode.
[mode.clients]

# Whether or not to enable the client workers. [Required]
enabled = true

# Whether or not to enable periodic refresh of clients. [Default: true]
# Note: Even if this is disabled, clients will be refreshed automatically if
# there is activity on a connection or channel they are involved with.
refresh = true

# Whether or not to enable misbehaviour detection for clients. [Default: false]
misbehaviour = true

# Specify the connections mode.
[mode.connections]

# Whether or not to enable the connection workers for handshake completion. [Required]
enabled = true

# Specify the channels mode.
[mode.channels]

# Whether or not to enable the channel workers for handshake completion. [Required]
enabled = true

# Specify the packets mode.
[mode.packets]

# Whether or not to enable the packet workers. [Required]
enabled = true

# Parametrize the periodic packet clearing feature.
# Interval (in number of blocks) at which pending packets
# should be eagerly cleared. A value of '0' will disable
# periodic packet clearing. [Default: 100]
clear_interval = 100

# Whether or not to clear packets on start. [Default: false]
clear_on_start = true

# Toggle the transaction confirmation mechanism.
# The tx confirmation mechanism periodically queries the `/tx_search` RPC
# endpoint to check that previously-submitted transactions
# (to any chain in this config file) have delivered successfully.
# Experimental feature. Affects telemetry if set to false.
# [Default: true]
tx_confirmation = true

# The REST section defines parameters for Hermes' built-in RESTful API.
# https://hermes.informal.systems/rest.html
[rest]

# Whether or not to enable the REST service. Default: false
enabled = true

# Specify the IPv4/6 host over which the built-in HTTP server will serve the RESTful
# API requests. Default: 127.0.0.1
host = '127.0.0.1'

# Specify the port over which the built-in HTTP server will serve the restful API
# requests. Default: 3000
port = 3000


# The telemetry section defines parameters for Hermes' built-in telemetry capabilities.
# https://hermes.informal.systems/telemetry.html
[telemetry]

# Whether or not to enable the telemetry service. Default: false
enabled = true

# Specify the IPv4/6 host over which the built-in HTTP server will serve the metrics
# gathered by the telemetry service. Default: 127.0.0.1
host = '127.0.0.1'

# Specify the port over which the built-in HTTP server will serve the metrics gathered
# by the telemetry service. Default: 3001
port = 3001

[[chains]]
id = 'wasmchain'
rpc_addr = 'http://127.0.0.1:26657'
grpc_addr = 'http://127.0.0.1:9090'
websocket_addr = 'ws://127.0.0.1:26657/websocket'
rpc_timeout = '10s'
account_prefix = 'wasm'
key_name = 'requester'
store_prefix = 'ibc'
default_gas = 5000000
max_gas = 15000000
gas_price = { price = 0, denom = 'stake' }
gas_multiplier = 1.1
max_msg_num = 20
max_tx_size = 209715
clock_drift = '20s'
max_block_time = '10s'
trusting_period = '10days'
trust_threshold = { numerator = '1', denominator = '3' }
address_type = { derivation = 'cosmos' }
ignore_port_channel = []
# [chains.packet_filter]
# policy = 'allow'
# list = [
# ['wasm.*', '*'],
# ]

[[chains]]
id = 'band-laozi-testnet6'
rpc_addr = 'https://rpc.laozi-testnet6.bandchain.org:443'
grpc_addr = 'https://laozi-testnet6.bandchain.org:443'
websocket_addr = 'wss://rpc.laozi-testnet6.bandchain.org:443/websocket'
rpc_timeout = '10s'
account_prefix = 'band'
key_name = 'testkey'
store_prefix = 'ibc'
default_gas = 100000
max_gas = 5000000
gas_price = { price = 0.0025, denom = 'uband' }
gas_multiplier = 1.1
max_msg_num = 30
max_tx_size = 2097152
clock_drift = '5s'
max_block_time = '10s'
trusting_period = '14days'
trust_threshold = { numerator = '1', denominator = '3' }
address_type = { derivation = 'cosmos' }
ignore_port_channel = []
# [chains.packet_filter]
# policy = 'allow'
# list = [
# ['oracle', '*'],
# ]
1 change: 1 addition & 0 deletions crates/relayer-cli/src/chain_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ where
address_type: AddressType::default(),
sequential_batch_tx: false,
extension_options: Vec::new(),
ignore_port_channel: Vec::new(),
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/relayer-cli/src/commands/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ fn subscribe(
chain_config.id.clone(),
chain_config.websocket_addr.clone(),
rt,
chain_config.ignore_port_channel.clone(),
)
.map_err(|e| eyre!("could not initialize event monitor: {}", e))?;

Expand Down
1 change: 1 addition & 0 deletions crates/relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ impl ChainEndpoint for CosmosSdkChain {
self.config.id.clone(),
self.config.websocket_addr.clone(),
rt,
self.config.ignore_port_channel.clone(),
)
.map_err(Error::event_monitor)?;

Expand Down
9 changes: 8 additions & 1 deletion crates/relayer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use serde_derive::{Deserialize, Serialize};
use tendermint_light_client_verifier::types::TrustThreshold;

use ibc_relayer_types::core::ics23_commitment::specs::ProofSpecs;
use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ChannelId, PortId};
use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ChannelId, PortChannelId, PortId};
use ibc_relayer_types::timestamp::ZERO_DURATION;

use crate::chain::ChainType;
Expand Down Expand Up @@ -106,6 +106,10 @@ pub mod default {
100
}

pub fn packet_delay() -> Duration {
Duration::ZERO
}

pub fn rpc_timeout() -> Duration {
Duration::from_secs(10)
}
Expand Down Expand Up @@ -295,6 +299,8 @@ impl Display for LogLevel {
#[serde(default, deny_unknown_fields)]
pub struct GlobalConfig {
pub log_level: LogLevel,
#[serde(default = "default::packet_delay", with = "humantime_serde")]
pub packet_delay: Duration,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -385,6 +391,7 @@ pub struct ChainConfig {
pub store_prefix: String,
pub default_gas: Option<u64>,
pub max_gas: Option<u64>,
pub ignore_port_channel: Vec<PortChannelId>,

// This field is deprecated, use `gas_multiplier` instead
pub gas_adjustment: Option<f64>,
Expand Down
25 changes: 21 additions & 4 deletions crates/relayer/src/event/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use tendermint_rpc::{
};

use ibc_relayer_types::{
core::ics02_client::height::Height, core::ics24_host::identifier::ChainId, events::IbcEvent,
core::ics02_client::height::Height,
core::ics24_host::identifier::{ChainId, PortChannelId},
events::IbcEvent,
};

use crate::{
Expand Down Expand Up @@ -101,6 +103,7 @@ pub struct EventMonitor {
subscriptions: Box<SubscriptionStream>,
/// Tokio runtime
rt: Arc<TokioRuntime>,
ignore_port_channel: Vec<PortChannelId>,
}

// TODO: These are SDK specific, should be eventually moved.
Expand All @@ -114,6 +117,7 @@ pub mod queries {
ibc_client(),
ibc_connection(),
ibc_channel(),
ibc_wasm(),
// This will be needed when we send misbehavior evidence to full node
// Query::eq("message.module", "evidence"),
]
Expand All @@ -134,6 +138,10 @@ pub mod queries {
pub fn ibc_channel() -> Query {
Query::eq("message.module", "ibc_channel")
}

pub fn ibc_wasm() -> Query {
Query::eq("message.module", "wasm")
}
}

impl EventMonitor {
Expand All @@ -148,6 +156,7 @@ impl EventMonitor {
chain_id: ChainId,
node_addr: Url,
rt: Arc<TokioRuntime>,
ignore_port_channel: Vec<PortChannelId>,
) -> Result<(Self, EventReceiver, TxMonitorCmd)> {
let (tx_batch, rx_batch) = channel::unbounded();
let (tx_cmd, rx_cmd) = channel::unbounded();
Expand Down Expand Up @@ -175,6 +184,7 @@ impl EventMonitor {
rx_cmd,
node_addr,
subscriptions: Box::new(futures::stream::empty()),
ignore_port_channel,
};

Ok((monitor, rx_batch, tx_cmd))
Expand Down Expand Up @@ -339,7 +349,11 @@ impl EventMonitor {
core::mem::replace(&mut self.subscriptions, Box::new(futures::stream::empty()));

// Convert the stream of RPC events into a stream of event batches.
let batches = stream_batches(subscriptions, self.chain_id.clone());
let batches = stream_batches(
subscriptions,
self.chain_id.clone(),
self.ignore_port_channel.clone(),
);

// Needed to be able to poll the stream
pin_mut!(batches);
Expand Down Expand Up @@ -437,21 +451,24 @@ impl EventMonitor {
fn collect_events(
chain_id: &ChainId,
event: RpcEvent,
ignore_port_channel: &Vec<PortChannelId>,
) -> impl Stream<Item = Result<IbcEventWithHeight>> {
let events = crate::event::rpc::get_all_events(chain_id, event).unwrap_or_default();
let events =
crate::event::rpc::get_all_events(chain_id, event, ignore_port_channel).unwrap_or_default();
stream::iter(events).map(Ok)
}

/// Convert a stream of RPC event into a stream of event batches
fn stream_batches(
subscriptions: Box<SubscriptionStream>,
chain_id: ChainId,
ignore_port_channel: Vec<PortChannelId>,
) -> impl Stream<Item = Result<EventBatch>> {
let id = chain_id.clone();

// Collect IBC events from each RPC event
let events = subscriptions
.map_ok(move |rpc_event| collect_events(&id, rpc_event))
.map_ok(move |rpc_event| collect_events(&id, rpc_event, &ignore_port_channel))
.map_err(Error::canceled_or_generic)
.try_flatten();

Expand Down
Loading

0 comments on commit 0dff8aa

Please sign in to comment.