mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-30 03:01:58 -04:00
chore: remove migrate-trie-to-packed example (#23385)
Co-authored-by: Sergei Shulepov <2205845+pepyakin@users.noreply.github.com> Co-authored-by: Sergei Shulepov <s.pepyakin@gmail.com>
This commit is contained in:
29
Cargo.lock
generated
29
Cargo.lock
generated
@@ -1544,7 +1544,7 @@ version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cffb0e931875b666fc4fcb20fee52e9bbd1ef836fd9e9e04ec21555f9f85f7ef"
|
||||
dependencies = [
|
||||
"fastrand 2.4.0",
|
||||
"fastrand 2.4.1",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@@ -3746,19 +3746,6 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "example-migrate-trie-to-packed"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"eyre",
|
||||
"reth-db",
|
||||
"reth-db-api",
|
||||
"reth-trie-common",
|
||||
"reth-trie-db",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "example-network"
|
||||
version = "0.0.0"
|
||||
@@ -3910,9 +3897,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.4.0"
|
||||
version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a043dc74da1e37d6afe657061213aa6f425f855399a11d3463c6ecccc4dfda1f"
|
||||
checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6"
|
||||
|
||||
[[package]]
|
||||
name = "fastrlp"
|
||||
@@ -4179,7 +4166,7 @@ version = "2.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad"
|
||||
dependencies = [
|
||||
"fastrand 2.4.0",
|
||||
"fastrand 2.4.1",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"parking",
|
||||
@@ -6584,7 +6571,7 @@ version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "135ace3a761e564ec88c03a77317a7c6b80bb7f7135ef2544dbe054243b89737"
|
||||
dependencies = [
|
||||
"fastrand 2.4.0",
|
||||
"fastrand 2.4.1",
|
||||
"phf_shared",
|
||||
]
|
||||
|
||||
@@ -11872,7 +11859,7 @@ version = "3.27.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
|
||||
dependencies = [
|
||||
"fastrand 2.4.0",
|
||||
"fastrand 2.4.1",
|
||||
"getrandom 0.4.2",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
@@ -12259,9 +12246,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.25.10+spec-1.1.0"
|
||||
version = "0.25.11+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a82418ca169e235e6c399a84e395ab6debeb3bc90edc959bf0f48647c6a32d1b"
|
||||
checksum = "0b59c4d22ed448339746c59b905d24568fcbb3ab65a500494f7b8c3e97739f2b"
|
||||
dependencies = [
|
||||
"indexmap 2.13.1",
|
||||
"toml_datetime 1.1.1+spec-1.1.0",
|
||||
|
||||
@@ -134,7 +134,6 @@ members = [
|
||||
"examples/exex-subscription",
|
||||
"examples/exex-test",
|
||||
"examples/full-contract-state",
|
||||
"examples/migrate-trie-to-packed",
|
||||
"examples/manual-p2p/",
|
||||
"examples/network-txpool/",
|
||||
"examples/network/",
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
[package]
|
||||
name = "example-migrate-trie-to-packed"
|
||||
version = "0.0.0"
|
||||
publish = false
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
reth-db = { workspace = true, features = ["mdbx"] }
|
||||
reth-db-api = { workspace = true }
|
||||
reth-trie-db = { workspace = true }
|
||||
reth-trie-common = { workspace = true }
|
||||
eyre.workspace = true
|
||||
serde_json.workspace = true
|
||||
clap = { workspace = true, features = ["derive"] }
|
||||
@@ -1,133 +0,0 @@
|
||||
#![allow(unused_crate_dependencies)]
|
||||
|
||||
//! Migrates reth trie tables from legacy (v1, 65-byte nibble keys) to packed (v2, 33-byte nibble
|
||||
//! keys).
|
||||
//!
|
||||
//! This reads all entries from `AccountsTrie` and `StoragesTrie` using the legacy encoding,
|
||||
//! clears both tables, and rewrites them using packed encoding. Finally, it updates the
|
||||
//! `StorageSettings` metadata entry to v2.
|
||||
//!
|
||||
//! **Back up your datadir before running this.**
|
||||
//!
|
||||
//! Usage:
|
||||
//! ```sh
|
||||
//! cargo run -p example-migrate-trie-to-packed -- --datadir ~/.local/share/reth/mainnet
|
||||
//! ```
|
||||
|
||||
use clap::Parser;
|
||||
use eyre::Result;
|
||||
use reth_db::{mdbx::DatabaseArguments, open_db};
|
||||
use reth_db_api::{
|
||||
cursor::{DbCursorRO, DbCursorRW},
|
||||
database::Database,
|
||||
models::StorageSettings,
|
||||
tables,
|
||||
transaction::{DbTx, DbTxMut},
|
||||
};
|
||||
use reth_trie_common::{PackedStorageTrieEntry, PackedStoredNibbles, PackedStoredNibblesSubKey};
|
||||
use reth_trie_db::{PackedAccountsTrie, PackedStoragesTrie};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(about = "Migrate trie tables from legacy to packed nibble encoding")]
|
||||
struct Cli {
|
||||
/// Path to the reth datadir (e.g. ~/.local/share/reth/mainnet)
|
||||
#[arg(long)]
|
||||
datadir: PathBuf,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let cli = Cli::parse();
|
||||
let db_path = cli.datadir.join("db");
|
||||
|
||||
println!("Opening database at {}", db_path.display());
|
||||
let db = open_db(db_path, DatabaseArguments::default())?;
|
||||
let tx = db.tx_mut()?;
|
||||
|
||||
// -- AccountsTrie --
|
||||
println!("Reading AccountsTrie (legacy encoding)...");
|
||||
let account_entries = {
|
||||
let mut cursor = tx.cursor_read::<tables::AccountsTrie>()?;
|
||||
let mut entries = Vec::new();
|
||||
let walker = cursor.walk(None)?;
|
||||
for result in walker {
|
||||
let (key, value) = result?;
|
||||
entries.push((key, value));
|
||||
if entries.len() % 100_000 == 0 {
|
||||
println!(" read {} AccountsTrie entries", entries.len());
|
||||
}
|
||||
}
|
||||
entries
|
||||
};
|
||||
let account_count = account_entries.len();
|
||||
println!("Read {account_count} AccountsTrie entries");
|
||||
|
||||
println!("Clearing AccountsTrie...");
|
||||
tx.clear::<tables::AccountsTrie>()?;
|
||||
|
||||
println!("Writing AccountsTrie (packed encoding)...");
|
||||
{
|
||||
let mut cursor = tx.cursor_write::<PackedAccountsTrie>()?;
|
||||
for (i, (key, value)) in account_entries.into_iter().enumerate() {
|
||||
let packed_key = PackedStoredNibbles(key.0);
|
||||
cursor.upsert(packed_key, &value)?;
|
||||
if (i + 1) % 100_000 == 0 {
|
||||
println!(" wrote {} AccountsTrie entries", i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("Wrote {account_count} AccountsTrie entries (packed)");
|
||||
|
||||
// -- StoragesTrie --
|
||||
println!("Reading StoragesTrie (legacy encoding)...");
|
||||
let storage_entries = {
|
||||
let mut cursor = tx.cursor_read::<tables::StoragesTrie>()?;
|
||||
let mut entries = Vec::new();
|
||||
let walker = cursor.walk(None)?;
|
||||
for result in walker {
|
||||
let (key, value) = result?;
|
||||
entries.push((key, value));
|
||||
if entries.len() % 100_000 == 0 {
|
||||
println!(" read {} StoragesTrie entries", entries.len());
|
||||
}
|
||||
}
|
||||
entries
|
||||
};
|
||||
let storage_count = storage_entries.len();
|
||||
println!("Read {storage_count} StoragesTrie entries");
|
||||
|
||||
println!("Clearing StoragesTrie...");
|
||||
tx.clear::<tables::StoragesTrie>()?;
|
||||
|
||||
println!("Writing StoragesTrie (packed encoding)...");
|
||||
{
|
||||
let mut cursor = tx.cursor_write::<PackedStoragesTrie>()?;
|
||||
for (i, (key, value)) in storage_entries.into_iter().enumerate() {
|
||||
let packed_entry = PackedStorageTrieEntry {
|
||||
nibbles: PackedStoredNibblesSubKey(value.nibbles.0),
|
||||
node: value.node,
|
||||
};
|
||||
cursor.upsert(key, &packed_entry)?;
|
||||
if (i + 1) % 100_000 == 0 {
|
||||
println!(" wrote {} StoragesTrie entries", i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("Wrote {storage_count} StoragesTrie entries (packed)");
|
||||
|
||||
// -- Update StorageSettings metadata --
|
||||
println!("Updating StorageSettings to v2...");
|
||||
let settings = StorageSettings::v2();
|
||||
let settings_json = serde_json::to_vec(&settings)?;
|
||||
tx.put::<tables::Metadata>("storage_settings".to_string(), settings_json)?;
|
||||
|
||||
println!("Committing transaction...");
|
||||
tx.commit()?;
|
||||
|
||||
println!("Migration complete!");
|
||||
println!(" AccountsTrie: {account_count} entries migrated");
|
||||
println!(" StoragesTrie: {storage_count} entries migrated");
|
||||
println!(" StorageSettings: updated to v2");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user