Skip to content

Commit

Permalink
Merge pull request #277 from turbofish-org/merk-migration
Browse files Browse the repository at this point in the history
Merk migration
  • Loading branch information
keppel authored Nov 16, 2024
2 parents 8d9bf57 + b4add30 commit b111255
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 12 additions & 5 deletions src/abci/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -354,8 +354,10 @@ impl<A: App> Node<A> {
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);
Expand All @@ -374,8 +376,13 @@ impl<A: App> Node<A> {
[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();
Expand Down
8 changes: 4 additions & 4 deletions src/merk/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ impl MerkStore {
}

/// Opens a `MerkStore` at the provided path for read-only access.
pub fn open_readonly<P: AsRef<Path>>(home: P) -> Self {
pub fn open_readonly<P: AsRef<Path>>(home: P) -> Result<Self> {
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(),
home,
target_snapshot: None,
restorer: None,
mem_snapshots: BTreeMap::new(),
}
})
}

pub fn initialized<P: AsRef<Path>>(home: P) -> bool {
Expand Down
4 changes: 4 additions & 0 deletions src/store/bufstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ impl<S> BufStore<S> {
&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.
///
Expand Down

0 comments on commit b111255

Please sign in to comment.