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

pd: export storage state #2975

Merged
merged 4 commits into from
Sep 7, 2023
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
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/bin/pd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ metrics-util = "0.13"
clap = { version = "3", features = ["derive", "env"] }
rustls-acme = "0.6"
atty = "0.2"
fs_extra = "1.3.0"

[build-dependencies]
vergen = "5"
Expand Down
48 changes: 47 additions & 1 deletion crates/bin/pd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use penumbra_proto::client::v1alpha1::{
specific_query_service_server::SpecificQueryServiceServer,
tendermint_proxy_service_server::TendermintProxyServiceServer,
};
use penumbra_storage::Storage;
use penumbra_storage::{StateDelta, Storage};
use penumbra_tendermint_proxy::TendermintProxy;
use penumbra_tower_trace::remote_addr;
use rand::Rng;
Expand Down Expand Up @@ -119,6 +119,19 @@ enum RootCommand {
#[clap(subcommand)]
tn_cmd: TestnetCommand,
},

/// Export the storage state the full node.
Export {
/// The data directory of the full node.
#[clap(long, env = "PENUMBRA_PD_HOME", display_order = 100)]
data_path: PathBuf,
/// The directory that the exported state will be written to.
#[clap(long, display_order = 200)]
export_path: PathBuf,
/// Whether to prune the JMT tree.
#[clap(long, display_order = 300)]
prune: bool,
},
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -545,6 +558,39 @@ async fn main() -> anyhow::Result<()> {
);
t.write_configs()?;
}
RootCommand::Export {
mut data_path,
mut export_path,
prune,
} => {
use fs_extra;

tracing::info!("exporting state to {}", export_path.display());
let copy_opts = fs_extra::dir::CopyOptions::new();
data_path.push("rocksdb");
let from = [data_path.as_path()];
tracing::info!(
?data_path,
?export_path,
"copying from data dir to export dir",
);
fs_extra::copy_items(&from, export_path.as_path(), &copy_opts)?;

tracing::info!("done copying");
if !prune {
return Ok(());
}

tracing::info!("pruning JMT tree");
export_path.push("rocksdb");
let export = Storage::load(export_path).await?;
let _ = StateDelta::new(export.latest_snapshot());
// TODO:
// - add utilities in `penumbra_storage` to prune a tree
// - apply the delta to the exported storage
// - apply checks: root hash, size, etc.
todo!()
}
}
Ok(())
}