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

Feature-guard the sled light store and make the dependency on sled internal #781

Merged
merged 4 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## Unreleased

### BUG FIXES

* `[light-client]` The `sled`-backed lightstore is now feature-guarded under
the `lightstore-sled` feature, which is enabled by default for now. ([#772])

[#772]: https://github.com/informalsystems/tendermint-rs/pull/772

## v0.17.1

*Jan 11, 2021*
Expand Down
12 changes: 10 additions & 2 deletions light-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ description = """
[lib]
crate-type = ["cdylib", "rlib"]

# docs.rs-specific configuration
[package.metadata.docs.rs]
# document all features
all-features = true
# defines the configuration attribute `docsrs`
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["rpc-client"]
default = ["rpc-client", "lightstore-sled"]
rpc-client = ["tokio", "tendermint-rpc/http-client"]
secp256k1 = ["tendermint/secp256k1", "tendermint-rpc/secp256k1"]
lightstore-sled = ["sled"]

[dependencies]
tendermint = { version = "0.17.1", path = "../tendermint" }
Expand All @@ -38,7 +46,7 @@ futures = "0.3.4"
serde = "1.0.106"
serde_cbor = "0.11.1"
serde_derive = "1.0.106"
sled = "0.34.3"
sled = { version = "0.34.3", optional = true }
static_assertions = "1.1.0"
thiserror = "1.0.15"
tokio = { version = "0.2", optional = true }
Expand Down
4 changes: 1 addition & 3 deletions light-client/examples/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ fn make_instance(
db_path: impl AsRef<Path>,
opts: &SyncOpts,
) -> Result<Instance, BoxError> {
let db = sled::open(db_path)?;

let light_store = SledStore::new(db);
let light_store = SledStore::open(db_path)?;
let rpc_client = rpc::HttpClient::new(addr).unwrap();
let options = light_client::Options {
trust_threshold: TrustThreshold::default(),
Expand Down
4 changes: 4 additions & 0 deletions light-client/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Interface and implementations of the light block store.
//!
//! See the `memory` and `sled` modules for:
//!
//! - a transient, in-memory implementation for testing purposes
//! - a persistent, on-disk, sled-backed implementation for production

Expand All @@ -10,6 +11,9 @@ use crate::types::{Height, LightBlock, Status};
use crate::utils::std_ext;

pub mod memory;

#[cfg(feature = "lightstore-sled")]
#[cfg_attr(docsrs, doc(cfg(feature = "lightstore-sled")))]
pub mod sled;

/// Store for light blocks.
Expand Down
9 changes: 8 additions & 1 deletion light-client/src/store/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

pub mod utils;

use std::path::Path;

use crate::{
store::sled::utils::*,
types::{Height, LightBlock},
Expand All @@ -26,7 +28,12 @@ pub struct SledStore {
}

impl SledStore {
/// Create a new persistent store from a sled database
/// Open a sled database and create a new persistent store from it.
pub fn open(db: impl AsRef<Path>) -> Result<Self, sled::Error> {
Ok(Self::new(sled::open(db)?))
}

/// Create a new persistent store from a sled database that is already open.
pub fn new(db: SledDb) -> Self {
Self {
db,
Expand Down
7 changes: 3 additions & 4 deletions light-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ name = "tendermint-light-node"
path = "src/bin/tendermint-light-node/main.rs"

[dependencies]
anomaly = { version = "0.2", features = [ "serializer" ] }
anomaly = { version = "0.2", features = ["serializer"] }
async-trait = "0.1"
gumdrop = "0.7"
jsonrpc-core = "14.2"
Expand All @@ -36,10 +36,9 @@ jsonrpc-http-server = "14.2"
jsonrpc-derive = "14.2"
serde = { version = "1", features = ["serde_derive"] }
serde_json = "1.0"
sled = "0.34.3"
tendermint = { version = "0.17.1", path = "../tendermint" }
tendermint-light-client = { version = "0.17.1", path = "../light-client" }
tendermint-rpc = { version = "0.17.1", path = "../rpc", features = [ "http-client" ] }
tendermint-light-client = { version = "0.17.1", path = "../light-client", features = ["lightstore-sled"] }
tendermint-rpc = { version = "0.17.1", path = "../rpc", features = ["http-client"] }
thiserror = "1.0"
tokio = { version = "0.2", features = ["full"] }

Expand Down
6 changes: 2 additions & 4 deletions light-node/src/commands/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ fn initialize_subjectively(
config: &LightClientConfig,
timeout: Option<Duration>,
) -> Result<Instance, String> {
let db = sled::open(config.db_path.clone())
.map_err(|e| format!("could not open database: {}", e))?;

let light_store = SledStore::new(db);
let light_store =
SledStore::open(&config.db_path).map_err(|e| format!("could not open database: {}", e))?;

if let Some(trusted_state) = light_store.latest_trusted_or_verified() {
status_warn!(
Expand Down
13 changes: 6 additions & 7 deletions light-node/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ impl config::Override<LightNodeConfig> for StartCmd {

impl StartCmd {
fn assert_init_was_run() -> Result<(), String> {
let db_path = app_config().light_clients.first().unwrap().db_path.clone();
let db = sled::open(db_path).map_err(|e| format!("could not open database: {}", e))?;
let config = app_config();
let db_path = &config.light_clients.first().unwrap().db_path;
let primary_store =
SledStore::open(db_path).map_err(|e| format!("could not open database: {}", e))?;

let primary_store = SledStore::new(db);
if primary_store.latest_trusted_or_verified().is_none() {
return Err("no trusted or verified state in store for primary, please initialize with the `initialize` subcommand first".to_string());
}
Expand Down Expand Up @@ -127,10 +128,8 @@ impl StartCmd {
let rpc_client = tendermint_rpc::HttpClient::new(light_config.address.clone())
.map_err(|e| format!("failed to create HTTP client: {}", e))?;

let db_path = light_config.db_path.clone();
let db = sled::open(db_path).map_err(|e| format!("could not open database: {}", e))?;

let light_store = SledStore::new(db);
let light_store = SledStore::open(&light_config.db_path)
.map_err(|e| format!("could not open database: {}", e))?;

let builder = LightClientBuilder::prod(
light_config.peer_id,
Expand Down