Skip to content

Commit

Permalink
Feature-guard backward verification behind "unstable" flag
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Jan 21, 2021
1 parent 15c7f22 commit 2474ed9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions light-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ default = ["rpc-client", "lightstore-sled"]
rpc-client = ["tokio", "tendermint-rpc/http-client"]
secp256k1 = ["tendermint/secp256k1", "tendermint-rpc/secp256k1"]
lightstore-sled = ["sled"]
unstable = []

[dependencies]
tendermint = { version = "0.17.1", path = "../tendermint" }
Expand All @@ -50,6 +51,7 @@ sled = { version = "0.34.3", optional = true }
static_assertions = "1.1.0"
thiserror = "1.0.15"
tokio = { version = "1.0", features = ["rt"], optional = true }
cfg-if = "1.0.0"

[dev-dependencies]
tendermint-testgen = { path = "../testgen"}
Expand Down
37 changes: 26 additions & 11 deletions light-client/src/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@
//!
//! [1]: https://github.com/informalsystems/tendermint-rs/blob/master/docs/spec/lightclient/verification/verification.md

use std::{fmt, time::Duration};

use cfg_if::cfg_if;
use contracts::*;
use derive_more::Display;
use serde::{Deserialize, Serialize};
use std::{convert::TryFrom, fmt, time::Duration};

use crate::contracts::*;
use crate::{
bail,
components::{clock::Clock, io::*, scheduler::*, verifier::*},
contracts::*,
errors::{Error, ErrorKind},
operations::Hasher,
state::State,
types::{Height, LightBlock, PeerId, Status, TrustThreshold},
};
use crate::{
components::{clock::Clock, io::*, scheduler::*, verifier::*},
operations::Hasher,
};

/// Verification parameters
///
/// TODO: Find a better name than `Options`
#[derive(Copy, Clone, Debug, PartialEq, Display, Serialize, Deserialize)]
#[display(fmt = "{:?}", self)]
pub struct Options {
Expand Down Expand Up @@ -56,11 +54,15 @@ pub struct LightClient {
pub peer: PeerId,
/// Options for this light client
pub options: Options,

clock: Box<dyn Clock>,
scheduler: Box<dyn Scheduler>,
verifier: Box<dyn Verifier>,
hasher: Box<dyn Hasher>,
io: Box<dyn Io>,

// Only used in verify_backwards when "unstable" feature is enabled
#[allow(dead_code)]
hasher: Box<dyn Hasher>,
}

impl fmt::Debug for LightClient {
Expand Down Expand Up @@ -182,8 +184,18 @@ impl LightClient {
// Perform forward verification with bisection
self.verify_bisection(target_height, state)
} else {
// Perform sequential backward verification
self.verify_backwards(target_height, state)
cfg_if! {
if #[cfg(feature = "unstable")] {
// Perform sequential backward verification
self.verify_backwards(target_height, state)
} else {
Err(ErrorKind::TargetLowerThanTrustedState {
target_height,
trusted_height: highest.height(),
}
.into())
}
}
}
}

Expand Down Expand Up @@ -269,11 +281,14 @@ impl LightClient {
}

/// Perform sequential backward verification
#[cfg(feature = "unstable")]
fn verify_backwards(
&self,
target_height: Height,
state: &mut State,
) -> Result<LightBlock, Error> {
use std::convert::TryFrom;

let root = state
.light_store
.latest_trusted_or_verified()
Expand Down

0 comments on commit 2474ed9

Please sign in to comment.