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

Allow more granular configuration of Hermes modes of operation #1539

Merged
merged 38 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9f559b2
Add config mode
hu55a1n1 Nov 3, 2021
403d280
Remove config strategy
hu55a1n1 Nov 3, 2021
1287576
Remove config global clear_packets_interval option
hu55a1n1 Nov 3, 2021
59e02c2
Skip misbehaviour based on client mode in config
hu55a1n1 Nov 3, 2021
26e72cf
Clear packets on start based on config mode
hu55a1n1 Nov 3, 2021
0fb2d6c
Refresh clients only if enabled in config
hu55a1n1 Nov 3, 2021
3957b2e
Collect event based on config mode
hu55a1n1 Nov 5, 2021
867c42d
Fix collect_event()
hu55a1n1 Nov 5, 2021
cac31a6
Spawn workers based on config mode
hu55a1n1 Nov 5, 2021
5cbe960
Update E2E hermes config
hu55a1n1 Nov 5, 2021
7fbe9a8
Fix tests
hu55a1n1 Nov 5, 2021
86b5e5d
Fix E2E tests
hu55a1n1 Nov 5, 2021
2f2e496
Fix comments that referenced 'strategy' in py files
hu55a1n1 Nov 8, 2021
d3bb531
Spawn workers conditionally depending on mode config
hu55a1n1 Nov 8, 2021
1b2463c
Remove references to strategy in guide and docs
hu55a1n1 Nov 8, 2021
ce1bee5
Remove more refs to strategy
hu55a1n1 Nov 8, 2021
47a3c1f
Add .changelog entry
hu55a1n1 Nov 8, 2021
28cae96
Remove global config options - filter & tx_confirmations
hu55a1n1 Nov 8, 2021
3551055
Fix Packet::default() recursion bug
hu55a1n1 Nov 8, 2021
3b61294
cargo fmt
hu55a1n1 Nov 8, 2021
a12be44
Address feedback
hu55a1n1 Nov 9, 2021
c51992c
Add serde(deny_unknown_fields) for mode config
hu55a1n1 Nov 9, 2021
a743ea0
Add check for valid mode config
hu55a1n1 Nov 9, 2021
bfc839c
Update ADRs that referenced strategy config
hu55a1n1 Nov 9, 2021
a3137e2
Modify gm scripts for config changes
hu55a1n1 Nov 9, 2021
8912511
Trck packet worker's first run using a boolean
hu55a1n1 Nov 10, 2021
f87720d
Enable connections and channels mode for gm default config
hu55a1n1 Nov 10, 2021
4dc73ca
Apply suggestion
hu55a1n1 Nov 10, 2021
df9cc0f
Fix build
hu55a1n1 Nov 10, 2021
d09f6a5
Add comment for `Supervisor::collect_events`
romac Nov 11, 2021
1b294a1
Avoid holding the lock on the config for too long in `Supervisor::col…
romac Nov 11, 2021
81f96f9
Small refactor in the packet worker
romac Nov 11, 2021
2e3bca3
Emit a warning if all operations modes are disabled
romac Nov 11, 2021
04b501e
Fix typo
romac Nov 11, 2021
4ec957b
Fix case where only packet mode in enabled
hu55a1n1 Nov 11, 2021
e14c8af
Merge branch '1518-config-modes' of github.com:informalsystems/ibc-rs…
hu55a1n1 Nov 11, 2021
2555801
Merge branch 'master' into 1518-config-modes
romac Nov 12, 2021
db3b6a5
Improve log message in cient worker
romac Nov 12, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Allow for more granular control of relaying modes. The `mode` configuration section replaces the `strategy` option.
([#1518](https://github.com/informalsystems/ibc-rs/issues/1518))
21 changes: 19 additions & 2 deletions ci/simple_config.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
[global]
strategy = 'all'
log_level = 'trace'

[mode]

[mode.clients]
enabled = true
refresh = true
misbehaviour = true

[mode.connections]
enabled = false

[mode.channels]
enabled = false

[mode.packets]
enabled = true
clear_interval = 100
clear_on_start = true
filter = false
clear_packets_interval = 100
tx_confirmation = true

[telemetry]
enabled = false
Expand Down
58 changes: 40 additions & 18 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
# The global section has parameters that apply globally to the relayer operation.
[global]

# Specify the strategy to be used by the relayer. Default: 'packets'
# Two options are currently supported:
# - 'all': Relay packets and perform channel and connection handshakes.
# - 'packets': Relay packets only.
strategy = 'packets'
# Specify the verbosity for the relayer logging output. Default: 'info'
# Valid options are 'error', 'warn', 'info', 'debug', 'trace'.
log_level = 'info'


# Enable or disable the filtering mechanism. Default: 'false'
# Specify the mode to be used by the relayer. [Required]
[mode]
romac marked this conversation as resolved.
Show resolved Hide resolved

# Specify the client mode.
[mode.clients]
# Whether or not to enable the client workers. [Required]
enabled = false
# Whether or not to enable periodic refresh of clients. [Default: false]
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. [Required]
enabled = false

# Specify the channels mode.
[mode.channels]
# Whether or not to enable the channel workers. [Required]
enabled = false

# Specify the packets mode.
[mode.packets]
# Whether or not to enable the packet workers. [Required]
enabled = false
# 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
# Enable or disable the filtering mechanism.
# Valid options are 'true', 'false'.
# Currently Hermes supports two filters:
# 1. Packet filtering on a per-chain basis; see the chain-specific
Expand All @@ -16,24 +48,14 @@ strategy = 'packets'
# is parametrized with (numerator = 1, denominator = 3), so that clients with
# thresholds different than this will be ignored.
# If set to 'true', both of the above filters will be enabled.
# [Default: false]
filter = false

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

# 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_packets_interval = 100

# 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.
# [Default: true]
tx_confirmation = true


Expand Down
28 changes: 20 additions & 8 deletions docs/architecture/adr-002-ibc-relayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,28 @@ Below is an example of a configuration file.

```toml
[global]
strategy = "packets"
log_level = "error"

[mode]

[mode.clients]
enabled = true
refresh = true
misbehaviour = true

[mode.connections]
enabled = false

[mode.channels]
enabled = false

[mode.packets]
enabled = true
clear_interval = 100
clear_on_start = true
filter = false
tx_confirmation = true

[[chains]]
id = "chain_A"
rpc_addr = "http://localhost:26657"
Expand Down Expand Up @@ -172,14 +191,7 @@ pub struct Config {
pub connections: Option<Vec<Connection>>,
}

pub enum Strategy {
Packets,
HandshakeAndPackets,
}

pub struct GlobalConfig {
pub strategy: Strategy,

/// All valid log levels, as defined in tracing:
/// https://docs.rs/tracing-core/0.1.17/tracing_core/struct.Level.html
pub log_level: String,
Expand Down
1 change: 0 additions & 1 deletion docs/architecture/adr-006-hermes-v0.2-usecases.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ of the config file will look as follows:

```toml
[global]
strategy = 'packets'
log_level = 'error'
log_json = 'false'
```
Expand Down
14 changes: 9 additions & 5 deletions e2e/e2e/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,14 @@ def verify_state(c: Config,
ibc1: ChainId, ibc0: ChainId,
ibc1_chan_id: ChannelId, port_id: PortId):

strategy = toml.load(c.config_file)['global']['strategy']
# verify channel state on both chains, should be 'Open' for 'all' strategy, 'Init' otherwise

if strategy == 'all':
mode = toml.load(c.config_file)['mode']
clients_enabled = mode['clients']['enabled']
conn_enabled = mode['connections']['enabled']
chan_enabled = mode['channels']['enabled']
packets_enabled = mode['packets']['enabled']

# verify connection state on both chains, should be 'Open' or 'Init' depending on config 'mode'
if clients_enabled and conn_enabled and chan_enabled and packets_enabled:
sleep(10.0)
for i in range(20):
sleep(2.0)
Expand All @@ -569,7 +573,7 @@ def verify_state(c: Config,
assert (ibc0_chan_end.state == 'Open'), (ibc0_chan_end, "state is not Open")
assert (ibc1_chan_end.state == 'Open'), (ibc1_chan_end, "state is not Open")

elif strategy == 'packets':
else:
sleep(5.0)
ibc1_chan_end = query_channel_end(c, ibc1, port_id, ibc1_chan_id)
assert (ibc1_chan_end.state == 'Init'), (ibc1_chan_end, "state is not Init")
Expand Down
15 changes: 9 additions & 6 deletions e2e/e2e/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,14 @@ def verify_state(c: Config,
ibc1: ChainId, ibc0: ChainId,
ibc1_conn_id: ConnectionId):

strategy = toml.load(c.config_file)['global']['strategy']
l.debug(f'Using strategy: {strategy}')

# verify connection state on both chains, should be 'Open' for 'all' strategy, 'Init' otherwise
if strategy == 'all':
mode = toml.load(c.config_file)['mode']
clients_enabled = mode['clients']['enabled']
conn_enabled = mode['connections']['enabled']
chan_enabled = mode['channels']['enabled']
packets_enabled = mode['packets']['enabled']

# verify connection state on both chains, should be 'Open' or 'Init' depending on config 'mode'
if clients_enabled and conn_enabled and chan_enabled and packets_enabled:
sleep(10.0)
for i in range(20):
sleep(5.0)
Expand All @@ -280,7 +283,7 @@ def verify_state(c: Config,
assert (ibc0_conn_end.state == 'Open'), (ibc0_conn_end, "state is not Open")
assert (ibc1_conn_end.state == 'Open'), (ibc1_conn_end, "state is not Open")

elif strategy == 'packets':
else:
sleep(5.0)
ibc1_conn_end = query_connection_end(c, ibc1, ibc1_conn_id)
assert (ibc1_conn_end.state == 'Init'), (ibc1_conn_end, "state is not Init")
Expand Down
25 changes: 20 additions & 5 deletions guide/src/commands/relaying/handshakes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,26 @@ for connections and channels.

## The `start` Command

To relay packets and handshake messages use `all` as strategy in the `global` section of the configuration file:
To relay packets and handshake messages configure the `mode` section of the configuration file like so:
```toml
[global]
strategy = 'all'
log_level = 'info'

[mode]

[mode.clients]
enabled = true
# ...

[mode.connections]
enabled = true

[mode.channels]
enabled = true

[mode.packets]
enabled = true
# ...
```

Then start hermes using the start command:
Expand All @@ -28,15 +43,15 @@ the configured chains.

Assuming the events are coming from a `source` chain, the relayer determines the `destination` chain and builds the handshake messages based on these events. These are then sent to the `destination` chain.

In addition to the events described in [Packet Relaying](packets.md#packet-relaying), in the `all` strategy mode the following IBC events are handled:
In addition to the events described in [Packet Relaying](packets.md#packet-relaying), the following IBC events may be handled:

- Channels:
- Channels (if `mode.channels.enabled=true`):
- `chan_open_init`: the relayer builds a `MsgChannelOpenTry` message
- `chan_open_try`: the relayer builds a `MsgChannelOpenAck` message
- `chan_open_ack`: the relayer builds a `MsgChannelOpenConfirm` message
- `chan_open_confirm`: no message is sent out, channel opening is finished

- Connections:
- Connections (if `mode.connections.enabled=true`):
- `conn_open_init`: the relayer builds a `MsgConnOpenTry` message
- `conn_open_try`: the relayer builds a `MsgConnOpenAck` message
- `conn_open_ack`: the relayer builds a `MsgConnOpenConfirm` message
Expand Down
19 changes: 17 additions & 2 deletions guide/src/commands/relaying/packets.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@ This section describes the configuration and commands that can be used to start

## The `start` Command

To relay packets only use `packets` as strategy in the `global` section of the configuration file:
To relay packets only configure the `mode` section of the configuration file like so:
```toml
[global]
strategy = 'packets'
log_level = 'info'

[mode]

[mode.clients]
enabled = true
# ...

[mode.connections]
enabled = false

[mode.channels]
enabled = false

[mode.packets]
enabled = true
# ...
```

Then start hermes using the start command:
Expand Down
21 changes: 19 additions & 2 deletions guide/src/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,27 @@ Here is a full example of a configuration file with two chains configured:

```toml
[global]
strategy = 'all'
log_level = 'info'

[mode]

[mode.clients]
enabled = true
refresh = true
misbehaviour = true

[mode.connections]
enabled = false

[mode.channels]
enabled = false

[mode.packets]
enabled = true
clear_interval = 100
clear_on_start = true
filter = false
clear_packets_interval = 100
tx_confirmation = true

[rest]
enabled = true
Expand Down
1 change: 0 additions & 1 deletion guide/src/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ Relevant snippet:

```toml
[global]
strategy = 'packets'
log_level = 'error'
```

Expand Down
21 changes: 20 additions & 1 deletion guide/src/tutorials/local-chains/relay-paths/multiple-paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,27 @@ Follow the steps below to connect three chains together and relay packets betwee

```toml
[global]
strategy = 'packets'
log_level = 'info'

[mode]

[mode.clients]
enabled = true
refresh = true
misbehaviour = true

[mode.connections]
enabled = false

[mode.channels]
enabled = false

[mode.packets]
enabled = true
clear_interval = 100
clear_on_start = true
filter = false
tx_confirmation = true

[[chains]]
id = 'ibc-0'
Expand Down
15 changes: 12 additions & 3 deletions relayer-cli/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,21 @@ impl Application for CliApp {
/// time in app lifecycle when configuration would be loaded if
/// possible.
fn after_config(&mut self, config: Self::Cfg) -> Result<(), FrameworkError> {
use crate::config::Diagnostic;

// Configure components
self.state.components.after_config(&config)?;

validate_config(&config).map_err(|validation_err| {
FrameworkErrorKind::ConfigError.context(format!("{}", validation_err))
})?;
if let Err(diagnostic) = validate_config(&config) {
match diagnostic {
Diagnostic::Warning(e) => {
tracing::warn!("relayer may be misconfigured: {}", e);
}
Diagnostic::Error(e) => {
return Err(FrameworkErrorKind::ConfigError.context(e).into());
}
}
};

self.config = Some(config);

Expand Down
Loading