-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement builder DSL for light client initialization, and other thin…
…gs (#583) * Add Send + Sync bound on light client Handle * Remove default implementation on Handle trait * Whitespace * Fix light-node code after Handle update * Remove unused mut qualifier after Supervisor update * Derive Clone on SupervisorHandle * Add DSL for building supervisor and light clients * Refactor Io component * Refactor Supervisor builder * Re-add a TODO that got lost in the refactor * Document builders * Simplify return types of supervisor builder methods * Update light client example to use builders * Perform more validation when doing subjective initialization * Add option to use trusted state alrady in store to light client builder * Use builders in light node start command * Improve API of PeerListBuilder * Finish adapting start command to use supervisor builder * Fix WASM build * Expose a couple functions on the supervisor * Block on async tasks in a new thread to avoid nesting Tokio runtimes * Cleanup * Nest std_ext module under utils * Feature-guard `block_on` for WASM * Fix typo in comment Co-authored-by: Thane Thomson <[email protected]> * Ensure that at least one witness is provided in the SupervisorBuilder * Rename SupervisorBuilder::unwrap to inner to express is infallability * Remove LightClientBuilder::trust_primary_latest since we do not need it and it is quite dangerous * Make `LightClientBuilder::trust_light_block` method private * Perform more thorough validation of the trusted light block in the light client builder * Update light client integration test to use builders Co-authored-by: Thane Thomson <[email protected]>
- Loading branch information
1 parent
416f514
commit 34d7d02
Showing
22 changed files
with
794 additions
and
410 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//! DSL for building light clients and supervisor | ||
|
||
mod light_client; | ||
pub use light_client::LightClientBuilder; | ||
|
||
mod supervisor; | ||
pub use supervisor::SupervisorBuilder; | ||
|
||
pub mod error; |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//! Errors raised by the builder DSL | ||
|
||
use anomaly::BoxError; | ||
use anomaly::Context; | ||
use tendermint::block::Height; | ||
use tendermint::Hash; | ||
use thiserror::Error; | ||
|
||
use crate::components::io::IoError; | ||
|
||
/// An error raised by the builder | ||
pub type Error = anomaly::Error<Kind>; | ||
|
||
/// The various error kinds raised by the builder | ||
#[derive(Debug, Clone, Error, PartialEq)] | ||
pub enum Kind { | ||
/// I/O error | ||
#[error("I/O error: {0}")] | ||
Io(#[from] IoError), | ||
|
||
/// Height mismatch | ||
#[error("height mismatch: given = {given}, found = {found}")] | ||
HeightMismatch { | ||
/// Height of trusted header | ||
given: Height, | ||
/// Height of fetched header | ||
found: Height, | ||
}, | ||
|
||
/// Hash mismatch | ||
#[error("hash mismatch: given = {given}, found = {found}")] | ||
HashMismatch { | ||
/// Hash of trusted header | ||
given: Hash, | ||
/// hash of fetched header | ||
found: Hash, | ||
}, | ||
|
||
/// Invalid light block | ||
#[error("invalid light block")] | ||
InvalidLightBlock, | ||
|
||
/// No trusted state as found in the store | ||
#[error("no trusted state in store")] | ||
NoTrustedStateInStore, | ||
|
||
/// An empty witness list was given | ||
#[error("empty witness list")] | ||
EmptyWitnessList, | ||
} | ||
|
||
impl Kind { | ||
/// Add additional context (i.e. include a source error and capture a backtrace). | ||
/// You can convert the resulting `Context` into an `Error` by calling `.into()`. | ||
pub fn context(self, source: impl Into<BoxError>) -> Context<Self> { | ||
Context::new(self, Some(source.into())) | ||
} | ||
} |
Oops, something went wrong.