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

Fast start for chains configured with an allow list #1705

Merged
merged 29 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
883ee7d
Introduce a `ChainScanner` to scan the chains for clients, connection…
romac Dec 3, 2021
70f5e1f
Use `ChainScanner` for spawning workers
romac Dec 13, 2021
2a51530
Merge branch 'master' into romac/spawn-scanner
romac Jan 6, 2022
4ffffb7
Formatting
romac Jan 6, 2022
8f1a62c
Add `--full-scan` option to `start` command to force a full scan even…
romac Jan 6, 2022
25e57de
Remove debug statements and print scanned chains on startup
romac Jan 7, 2022
600a0c6
Changelog entry
romac Jan 10, 2022
1151a2d
Merge branch 'master' into romac/spawn-scanner
romac Jan 10, 2022
1986051
Merge branch 'master' into romac/spawn-scanner
romac Jan 13, 2022
25d5119
Fix duplicate info message
romac Jan 19, 2022
59d744f
Quote identifiers in log messages
romac Jan 19, 2022
9404a81
Merge branch 'master' into romac/spawn-scanner
romac Jan 19, 2022
23924e9
Better error when port/channel does not exists
romac Jan 19, 2022
28866ad
Merge branch 'master' into romac/spawn-scanner
romac Jan 20, 2022
56ff223
Add metrics for queries
romac Jan 20, 2022
3d450d9
Small log improvements
romac Jan 20, 2022
5ea4f27
Rename queries metric
romac Jan 20, 2022
a414523
Use `chain` key for recording chain identifier in tracing logs
romac Jan 20, 2022
496d735
Use more structured logging in chain scanner
romac Jan 20, 2022
d763b4d
Fix changelog entry
romac Jan 20, 2022
d7f829e
Merge branch 'master' into romac/spawn-scanner
romac Jan 20, 2022
8a36fff
Improve logs when no workers were spawned
romac Jan 20, 2022
8f49559
Improve logs when spawning connection and channel workers
romac Jan 20, 2022
763aaa0
Remove spaces in objects names
romac Jan 20, 2022
111150c
Add changelog entry
romac Jan 20, 2022
48616b8
Revert part of logs changes
romac Jan 24, 2022
13160a7
Merge branch 'master' into romac/spawn-scanner
romac Jan 25, 2022
c43ce1a
Use INFO level for spawning logs
romac Jan 25, 2022
b0eafcf
Remove redundant changelog entry
romac Jan 25, 2022
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
Next Next commit
Introduce a ChainScanner to scan the chains for clients, connection…
…s and channels
  • Loading branch information
romac committed Dec 10, 2021
commit 883ee7d0ad8558d4ac68f10ef8c873eb5fb4a524
13 changes: 10 additions & 3 deletions modules/src/core/ics03_connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::prelude::*;

use core::str::FromStr;
use core::time::Duration;
use core::u64;
use core::{fmt, u64};

use serde::{Deserialize, Serialize};
use tendermint_proto::Protobuf;
Expand Down Expand Up @@ -323,15 +323,16 @@ pub enum State {

impl State {
/// Yields the State as a string.
pub fn as_string(&self) -> &'static str {
pub fn as_str(&self) -> &'static str {
match self {
Self::Uninitialized => "UNINITIALIZED",
Self::Init => "INIT",
Self::TryOpen => "TRYOPEN",
Self::Open => "OPEN",
}
}
// Parses the State out from a i32.

/// Parses the State out from a i32.
pub fn from_i32(s: i32) -> Result<Self, Error> {
match s {
0 => Ok(Self::Uninitialized),
Expand Down Expand Up @@ -361,6 +362,12 @@ impl State {
}
}

impl fmt::Display for State {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_str())
}
}

impl TryFrom<i32> for State {
type Error = Error;
fn try_from(value: i32) -> Result<Self, Self::Error> {
Expand Down
2 changes: 1 addition & 1 deletion relayer/src/chain/counterparty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn connection_on_destination(
}

pub fn connection_state_on_destination(
connection: IdentifiedConnectionEnd,
connection: &IdentifiedConnectionEnd,
counterparty_chain: &impl ChainHandle,
) -> Result<ConnectionState, Error> {
if let Some(remote_connection_id) = connection.connection_end.counterparty().connection_id() {
Expand Down
2 changes: 1 addition & 1 deletion relayer/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ impl<ChainA: ChainHandle, ChainB: ChainHandle> Connection<ChainA, ChainB> {
connection_id: connection_id.clone(),
};

connection_state_on_destination(connection, &self.dst_chain())
connection_state_on_destination(&connection, &self.dst_chain())
.map_err(ConnectionError::supervisor)
}

Expand Down
28 changes: 23 additions & 5 deletions relayer/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ pub mod dump_state;
use dump_state::SupervisorState;

pub mod spawn;
use spawn::SpawnContext;
use spawn::{SpawnContext, SpawnMode};

pub mod scan;

pub mod cmd;
use cmd::{CmdEffect, ConfigUpdate, SupervisorCmd};

use self::spawn::SpawnMode;
use self::scan::ChainsScan;

type ArcBatch = Arc<event::monitor::Result<EventBatch>>;
type Subscription = Receiver<ArcBatch>;
Expand Down Expand Up @@ -332,8 +334,22 @@ impl<Chain: ChainHandle + 'static> Supervisor<Chain> {

/// Spawn all the workers necessary for the relayer to connect
/// and relay between all the chains in the configurations.
fn spawn_workers(&mut self, mode: SpawnMode) {
self.spawn_context(mode).spawn_workers();
fn spawn_workers(&mut self, scan: ChainsScan, mode: SpawnMode) {
self.spawn_context(mode).spawn_workers(scan);
}

fn scan(&mut self) -> ChainsScan {
use self::scan::ChainScanner;

let mut scanner = ChainScanner::new(
self.config.read().unwrap().clone(),
self.registry.clone(),
&mut self.client_state_filter,
);

let scan = scanner.scan_chains();
println!("{}", scan);
scan
}

/// Perform a health check on all connected chains
Expand Down Expand Up @@ -413,7 +429,9 @@ impl<Chain: ChainHandle + 'static> Supervisor<Chain> {
}

pub fn run_without_health_check(&mut self) -> Result<(), Error> {
self.spawn_workers(SpawnMode::Startup);
let scan = self.scan();

self.spawn_workers(scan, SpawnMode::Startup);

let mut subscriptions = self.init_subscriptions()?;

Expand Down
5 changes: 5 additions & 0 deletions relayer/src/supervisor/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use ibc::core::ics24_host::identifier::{ChainId, ChannelId, ConnectionId, PortId

use crate::error::Error as RelayerError;
use crate::registry::SpawnError;
use crate::supervisor::scan::Error as ScanError;
use crate::worker::WorkerError;

define_error! {
Expand Down Expand Up @@ -66,6 +67,10 @@ define_error! {
[ SpawnError ]
|_| { "supervisor was not able to connect to any chains" },

Scan
[ ScanError ]
|_| { "supervisor encountered an error when scanning chains" },

Worker
[ WorkerError ]
|_| { "worker error" },
Expand Down
Loading