Skip to content

Commit

Permalink
Mre meta data and cargo +nightly fmt --
Browse files Browse the repository at this point in the history
  • Loading branch information
liamsi committed Jul 17, 2020
1 parent 28df7d2 commit ad845de
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 33 deletions.
1 change: 1 addition & 0 deletions light-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.15.0"
authors = ["Romain Ruetschi <romain@informal.systems>"]
edition = "2018"
license = "Apache-2.0"
keywords = ["blockchain", "bft", "consensus", "cosmos", "tendermint"]

[dependencies]
tendermint = { version = "0.15.0", path = "../tendermint" }
Expand Down
9 changes: 5 additions & 4 deletions light-client/src/components/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ pub fn basic_bisecting_schedule(
/// ## Note
///
/// - Case i. captures the case where the light block at height `current_height` has been verified,
/// and we can choose a height closer to the `target_height`. As we get the `light_store` as parameter,
/// the choice of the next height can depend on the `light_store`, e.g., we can pick a height
/// for which we have already downloaded a light block.
/// - In Case ii. the header at `current_height` could not be verified, and we need to pick a lesser height.
/// and we can choose a height closer to the `target_height`. As we get the `light_store` as
/// parameter, the choice of the next height can depend on the `light_store`, e.g., we can pick a
/// height for which we have already downloaded a light block.
/// - In Case ii. the header at `current_height` could not be verified, and we need to pick a lesser
/// height.
/// - In Case iii. is a special case when we have verified the `target_height`.
///
/// ## Implements
Expand Down
6 changes: 2 additions & 4 deletions light-client/src/fork_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ pub trait ForkDetector: Send {
/// the given trusted state, and then:
///
/// - If the verification succeeds, we have a real fork
/// - If verification fails because of lack of trust,
/// we have a potential fork.
/// - If verification fails for any other reason, the
/// witness is deemed faulty.
/// - If verification fails because of lack of trust, we have a potential fork.
/// - If verification fails for any other reason, the witness is deemed faulty.
pub struct ProdForkDetector {
hasher: Box<dyn Hasher>,
}
Expand Down
34 changes: 19 additions & 15 deletions light-client/src/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ impl LightClient {
///
/// This is the main function and uses the following components:
///
/// - The I/O component is called to fetch the next light block.
/// It is the only component that communicates with other nodes.
/// - The Verifier component checks whether a header is valid and checks if a new
/// light block should be trusted based on a previously verified light block.
/// - The Scheduler component decides which height to try to verify next, in case
/// the current block pass verification but cannot be trusted yet.
/// - The I/O component is called to fetch the next light block. It is the only component that
/// communicates with other nodes.
/// - The Verifier component checks whether a header is valid and checks if a new light block
/// should be trusted based on a previously verified light block.
/// - The Scheduler component decides which height to try to verify next, in case the current
/// block pass verification but cannot be trusted yet.
///
/// ## Implements
/// - [LCV-DIST-SAFE.1]
Expand All @@ -120,8 +120,8 @@ impl LightClient {
/// - The light store contains a light block within the trusting period [LCV-PRE-TP.1]
///
/// ## Postcondition
/// - The light store contains a light block that corresponds
/// to a block of the blockchain of height `target_height` [LCV-POST-LS.1]
/// - The light store contains a light block that corresponds to a block of the blockchain of
/// height `target_height` [LCV-POST-LS.1]
///
/// ## Error conditions
/// - If the precondition is violated [LVC-PRE-TP.1]
Expand All @@ -146,7 +146,8 @@ impl LightClient {
target_height: Height,
state: &mut State,
) -> Result<LightBlock, Error> {
// Let's first look in the store to see whether we have already successfully verified this block
// Let's first look in the store to see whether we have already successfully verified this
// block
if let Some(light_block) = state.light_store.get_trusted_or_verified(target_height) {
return Ok(light_block);
}
Expand Down Expand Up @@ -180,7 +181,8 @@ impl LightClient {
// Log the current height as a dependency of the block at the target height
state.trace_block(target_height, current_height);

// If the trusted state is now at a height equal to the target height, we are done. [LCV-DIST-LIFE.1]
// If the trusted state is now at a height equal to the target height, we are done.
// [LCV-DIST-LIFE.1]
if target_height == trusted_state.height() {
return Ok(trusted_state);
}
Expand All @@ -202,16 +204,18 @@ impl LightClient {
state.light_store.update(&current_block, new_status);
}
Verdict::Invalid(e) => {
// Verification failed, add the block to the light store with `Failed` status, and abort.
// Verification failed, add the block to the light store with `Failed` status,
// and abort.
state.light_store.update(&current_block, Status::Failed);

bail!(ErrorKind::InvalidLightBlock(e))
}
Verdict::NotEnoughTrust(_) => {
// The current block cannot be trusted because of missing overlap in the validator sets.
// Add the block to the light store with `Unverified` status.
// This will engage bisection in an attempt to raise the height of the highest
// trusted state until there is enough overlap.
// The current block cannot be trusted because of missing overlap in the
// validator sets. Add the block to the light store with
// `Unverified` status. This will engage bisection in an
// attempt to raise the height of the highest trusted state
// until there is enough overlap.
state.light_store.update(&current_block, Status::Unverified);
}
}
Expand Down
3 changes: 2 additions & 1 deletion light-client/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ impl Supervisor {
self.verify(Some(height))
}

/// Verify either to the latest block (if `height == None`) or to a given block (if `height == Some(height)`).
/// Verify either to the latest block (if `height == None`) or to a given block (if `height ==
/// Some(height)`).
fn verify(&mut self, height: Option<Height>) -> Result<LightBlock, Error> {
let primary = self.peers.primary_mut();

Expand Down
7 changes: 7 additions & 0 deletions light-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ edition = "2018"
license = "Apache-2.0"
repository = "https://github.com/informalsystems/tendermint-rs"
readme = "README.md"
keywords = ["blockchain", "bft", "consensus", "cosmos", "tendermint"]

description = """
The Tendermint light-node wraps the light-client crate into a command-line interface tool.
It can be used as a standalone light client daemon and exposes a JSONRPC endpoint from which you can
query the current state of the light node.
"""

[dependencies]
abscissa_tokio = "0.5"
Expand Down
4 changes: 2 additions & 2 deletions light-node/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ use tendermint_light_client::supervisor::Handle;
use tendermint_light_client::supervisor::{Instance, Supervisor};

/// `start` subcommand
///
#[derive(Command, Debug, Options)]
pub struct StartCmd {
/// Path to configuration file
Expand Down Expand Up @@ -93,7 +92,8 @@ impl config::Override<LightNodeConfig> for StartCmd {
&self,
mut config: LightNodeConfig,
) -> Result<LightNodeConfig, FrameworkError> {
// TODO(liamsi): figure out if other options would be reasonable to overwrite via CLI arguments.
// TODO(liamsi): figure out if other options would be reasonable to overwrite via CLI
// arguments.
if let Some(addr) = self.listen_addr {
config.rpc_config.listen_addr = addr;
}
Expand Down
8 changes: 4 additions & 4 deletions light-node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ pub use sealed::{Client, Rpc, Server};

/// Run the given [`Server`] on the given address and blocks until closed.
///
/// n.b. The underlying server has semantics to close on drop. Also does it does not offer any way to
/// get the underlying Future to await, so we are left with this rather rudimentary way to control
/// the lifecycle. Should we be interested in a more controlled way to close the server we can
/// expose a handle in the future.
/// n.b. The underlying server has semantics to close on drop. Also does it does not offer any way
/// to get the underlying Future to await, so we are left with this rather rudimentary way to
/// control the lifecycle. Should we be interested in a more controlled way to close the server we
/// can expose a handle in the future.
pub fn run<H>(server: Server<H>, addr: &str) -> Result<(), error::Error>
where
H: Handle + Send + Sync + 'static,
Expand Down
6 changes: 3 additions & 3 deletions tendermint/src/lite_impl/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ mod test {
fn test_hash_height_1() {
// JSON extracted from https://github.com/tendermint/tendermint/tree/v0.33
// more precisely `curl`ed from locally build docker image of:
// git log --pretty=format:"%H" -1 15:35:44
// git log --pretty=format:"%H" -1
// 606d0a89ccabbd3e59cff521f9f4d875cc366ac9
// via
// curl -X GET "http://localhost:26657/commit?height=1" -H "accept: application/json" | jq .result.signed_header.header
Expand Down Expand Up @@ -135,8 +135,8 @@ mod test {
fn test_hash_height_2() {
// JSON test-vector extracted from https://github.com/tendermint/tendermint/tree/v0.33
// more precisely `curl`ed from locally build docker image of:
// git log --pretty=format:"%H" -1 15:35:44
// 606d0a89ccabbd3e59cff521f9f4d875cc366ac9
// git log --pretty=format:"%H" -1
// 15:35:44 606d0a89ccabbd3e59cff521f9f4d875cc366ac9
// via
// curl -X GET "http://localhost:26657/commit?height=2" -H "accept: application/json" | jq .result.signed_header.header
let json_data = r#"
Expand Down

0 comments on commit ad845de

Please sign in to comment.