forked from informalsystems/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chain Runtime implementation (informalsystems#364)
* Started v0 impl: re-arranging handlers + initialization. * Clean up chain handle, prepare for generic client creation. * Trying different boundaries of abstraction b/t ForeignClient and ChainHandle. * Version one: introduced assemble_ methods to construct chain-specific data types * Removed signer from foreign client config * FMT quick fix * Client ID parsing * Use ibc::ics24_host::identifier::ChainId instead of its tendermint counterpart * More error handling and split into modules * Move prod handle in its own module * Cleanup * Overhaul subscriptions handling * Add struct to represent a batch of events * Move SplitResults trait into its own module * WIP: More handle inputs * Better errors * Implement `query` in chain runtime * Assemble client state and consensus state in runtime * Launch light clients * Light Block * Remove unused file * Rename two handle inputs * Rename Chain::ics_query to Chain::query * Store the domain MerkleProof in QueryResponse instead of the raw MerkleProof * Implement all chain methods in runtime + handle * Chain methods should return their Self types * Use light client to build consensus state * Use light client to retrieve and build header * Comment out currently unused code * Formatting * Make keybase field of CosmosSDKChain private * Fix tests * Properly spawn runtime * Revert 2afa90f * Allow a ChainId to not include version number, default to 0 * Upgrade Tokio to version 0.3 * WIP: event monitor * Syncify EventMonitor * Cleanup * Use shared Tokio runtime to `block_on` instead of spawning new one * Cleanup * Nest event_handler and event_monitor modules under event module * WIP: event bus * Cleanup * Fix build issue * Add tests for event bus * Cleanup * Update listen command * Point to tendermint-rs branch with Tokio 0.3 * Remove unused downcast_* methods * Re-enable some lints * Cleanup * Use tendermint-rs master * Depend on tendermint-rs prost-dev branch * Formatting * Deserialize client queries in Any types, temp fix for validator set Co-authored-by: Adi Seredinschi <[email protected]> Co-authored-by: Anca Zamfir <[email protected]>
- Loading branch information
1 parent
d846a6c
commit d2cbc2b
Showing
55 changed files
with
2,571 additions
and
1,615 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,67 @@ | ||
use std::ops::Deref; | ||
use std::{ops::Deref, sync::Arc, thread}; | ||
|
||
use abscissa_core::{ | ||
application::fatal_error, error::BoxError, tracing::debug, Command, Options, Runnable, | ||
}; | ||
use abscissa_core::{application::fatal_error, error::BoxError, Command, Options, Runnable}; | ||
use crossbeam_channel as channel; | ||
use tokio::runtime::Runtime as TokioRuntime; | ||
|
||
use crate::{prelude::*, tasks::event_listener}; | ||
use ibc::ics24_host::identifier::ChainId; | ||
use relayer::{config::ChainConfig, event::monitor::*}; | ||
|
||
use crate::prelude::*; | ||
|
||
#[derive(Command, Debug, Options)] | ||
pub struct ListenCmd {} | ||
pub struct ListenCmd { | ||
#[options(free)] | ||
chain_id: Option<ChainId>, | ||
} | ||
|
||
impl ListenCmd { | ||
async fn cmd(&self) -> Result<(), BoxError> { | ||
fn cmd(&self) -> Result<(), BoxError> { | ||
let rt = Arc::new(TokioRuntime::new().unwrap()); | ||
let config = app_config().clone(); | ||
|
||
debug!("launching 'listen' command"); | ||
event_listener::start(&config, false).await | ||
let chain_id = self.chain_id.clone().unwrap(); | ||
let chain_config = config | ||
.chains | ||
.into_iter() | ||
.find(|c| c.id == chain_id) | ||
.unwrap(); | ||
|
||
listen(rt, chain_config) | ||
} | ||
} | ||
|
||
impl Runnable for ListenCmd { | ||
fn run(&self) { | ||
let rt = tokio::runtime::Runtime::new().unwrap(); | ||
self.cmd() | ||
.unwrap_or_else(|e| fatal_error(app_reader().deref(), &*e)); | ||
} | ||
} | ||
|
||
/// Listen to events | ||
pub fn listen(rt: Arc<TokioRuntime>, config: ChainConfig) -> Result<(), BoxError> { | ||
info!(chain.id = %config.id, "spawning event monitor for"); | ||
|
||
rt.block_on(async move { | ||
self.cmd() | ||
.await | ||
.unwrap_or_else(|e| fatal_error(app_reader().deref(), &*e)); | ||
}); | ||
let (event_monitor, rx) = subscribe(config, rt)?; | ||
let _ = thread::spawn(|| event_monitor.run()); | ||
|
||
while let Ok(event_batch) = rx.recv() { | ||
dbg!(event_batch); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn subscribe( | ||
chain_config: ChainConfig, | ||
rt: Arc<tokio::runtime::Runtime>, | ||
) -> Result<(EventMonitor, channel::Receiver<EventBatch>), BoxError> { | ||
let (mut event_monitor, rx) = EventMonitor::new(chain_config.id, chain_config.rpc_addr, rt) | ||
.map_err(|e| format!("couldn't initialize event monitor: {}", e))?; | ||
|
||
event_monitor | ||
.subscribe() | ||
.map_err(|e| format!("couldn't initialize subscriptions: {}", e))?; | ||
|
||
Ok((event_monitor, rx)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.