diff --git a/Cargo.lock b/Cargo.lock index f126871c..902598d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2250,7 +2250,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "merk" version = "2.0.0" -source = "git+https://github.com/turbofish-org/merk?rev=84261c2c0fdcc09792cede6b21ba72b6d008fea6#84261c2c0fdcc09792cede6b21ba72b6d008fea6" +source = "git+https://github.com/turbofish-org/merk?rev=97fca3d9b8d05fb265bbd0c07100bdcddcbdfd37#97fca3d9b8d05fb265bbd0c07100bdcddcbdfd37" dependencies = [ "colored", "ed 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index bb942d69..ee1f594f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ tendermint-rpc = { version = "0.38.0", features = [ ], optional = true } tendermint = { version = "0.38.0", optional = true } tendermint-proto = { version = "0.38.0" } -merk = { git = "https://github.com/turbofish-org/merk", rev = "84261c2c0fdcc09792cede6b21ba72b6d008fea6", optional = true, default-features = false } +merk = { git = "https://github.com/turbofish-org/merk", rev = "97fca3d9b8d05fb265bbd0c07100bdcddcbdfd37", optional = true, default-features = false } orga-macros = { path = "macros", version = "0.3.1" } log = "0.4.17" hex-literal = "0.4.1" diff --git a/src/abci/node.rs b/src/abci/node.rs index d53c7530..cd97c8bb 100644 --- a/src/abci/node.rs +++ b/src/abci/node.rs @@ -8,7 +8,7 @@ use crate::migrate::Migrate; use crate::plugins::{ABCICall, ABCIPlugin}; use crate::query::Query; use crate::state::State; -use crate::store::{BackingStore, Read, Shared, Store, Write}; +use crate::store::{BackingStore, BufStore, Read, Shared, Store, Write}; use crate::tendermint::Child as TendermintChild; use crate::tendermint::Tendermint; use crate::{Error, Result}; @@ -354,8 +354,10 @@ impl Node { Context::add(crate::plugins::ChainId(chain_id.to_string())); log::info!("Migrating store data... (This might take a while)"); - let store = Shared::new(merk_store); - let mut store = Store::new(BackingStore::Merk(store)); + let store = Shared::new(BufStore::wrap(Shared::new(BufStore::wrap(Shared::new( + merk_store, + ))))); + let mut store = Store::new(BackingStore::WrappedMerk(store)); let bytes = store.get(&[]).unwrap().unwrap(); orga::set_compat_mode(compat_mode); @@ -374,8 +376,13 @@ impl Node { [vec![version.len() as u8], version.clone()].concat(), ) .unwrap(); - if let BackingStore::Merk(merk_store) = store.into_backing_store().into_inner() { - let mut store = merk_store.into_inner(); + if let BackingStore::WrappedMerk(wrapper) = store.into_backing_store().into_inner() { + let mut wrapper = wrapper.into_inner(); + wrapper.flush().unwrap(); + let mut wrapper = wrapper.into_inner().into_inner(); + wrapper.flush().unwrap(); + let mut store = wrapper.into_inner().into_inner(); + store .write(vec![(b"consensus_version".to_vec(), Some(version))]) .unwrap(); diff --git a/src/merk/store.rs b/src/merk/store.rs index 07fb4be1..20ea8600 100644 --- a/src/merk/store.rs +++ b/src/merk/store.rs @@ -53,14 +53,14 @@ impl MerkStore { } /// Opens a `MerkStore` at the provided path for read-only access. - pub fn open_readonly>(home: P) -> Self { + pub fn open_readonly>(home: P) -> Result { let home = home.as_ref().to_path_buf(); - let merk = Merk::open_readonly(home.join("db")).unwrap(); + let merk = Merk::open_readonly(home.join("db"))?; // TODO: populate snapshots, if we can do it safely concurrently with // other processes - MerkStore { + Ok(MerkStore { map: Some(Default::default()), merk: Some(merk), snapshots: snapshot::Snapshots::default(), @@ -68,7 +68,7 @@ impl MerkStore { target_snapshot: None, restorer: None, mem_snapshots: BTreeMap::new(), - } + }) } pub fn initialized>(home: P) -> bool { diff --git a/src/store/bufstore.rs b/src/store/bufstore.rs index 83de5d88..8c96b432 100644 --- a/src/store/bufstore.rs +++ b/src/store/bufstore.rs @@ -70,6 +70,10 @@ impl BufStore { &self.store } + pub fn into_inner(self) -> S { + self.store + } + /// Consumes the `BufStore`'s in-memory buffer and writes all of its values /// to the underlying store. ///