mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add ETL to HistoryStages (#7249)
This commit is contained in:
@ -10,11 +10,8 @@ use crate::{
|
||||
};
|
||||
use clap::Parser;
|
||||
use itertools::Itertools;
|
||||
use reth_db::{
|
||||
database::Database, open_db, static_file::iter_static_files, tables, transaction::DbTxMut,
|
||||
DatabaseEnv,
|
||||
};
|
||||
use reth_node_core::init::{insert_genesis_header, insert_genesis_state};
|
||||
use reth_db::{open_db, static_file::iter_static_files, tables, transaction::DbTxMut, DatabaseEnv};
|
||||
use reth_node_core::init::{insert_genesis_header, insert_genesis_history, insert_genesis_state};
|
||||
use reth_primitives::{
|
||||
fs, stage::StageId, static_file::find_fixed_range, ChainSpec, StaticFileSegment,
|
||||
};
|
||||
@ -91,124 +88,125 @@ impl Command {
|
||||
}
|
||||
}
|
||||
|
||||
tool.provider_factory.db_ref().update(|tx| {
|
||||
match self.stage {
|
||||
StageEnum::Headers => {
|
||||
tx.clear::<tables::CanonicalHeaders>()?;
|
||||
tx.clear::<tables::Headers>()?;
|
||||
tx.clear::<tables::HeaderTerminalDifficulties>()?;
|
||||
tx.clear::<tables::HeaderNumbers>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::Headers.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
insert_genesis_header::<DatabaseEnv>(tx, &static_file_provider, self.chain)?;
|
||||
}
|
||||
StageEnum::Bodies => {
|
||||
tx.clear::<tables::BlockBodyIndices>()?;
|
||||
tx.clear::<tables::Transactions>()?;
|
||||
tx.clear::<tables::TransactionBlocks>()?;
|
||||
tx.clear::<tables::BlockOmmers>()?;
|
||||
tx.clear::<tables::BlockWithdrawals>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::Bodies.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
insert_genesis_header::<DatabaseEnv>(tx, &static_file_provider, self.chain)?;
|
||||
}
|
||||
StageEnum::Senders => {
|
||||
tx.clear::<tables::TransactionSenders>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::SenderRecovery.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
}
|
||||
StageEnum::Execution => {
|
||||
tx.clear::<tables::PlainAccountState>()?;
|
||||
tx.clear::<tables::PlainStorageState>()?;
|
||||
tx.clear::<tables::AccountChangeSets>()?;
|
||||
tx.clear::<tables::StorageChangeSets>()?;
|
||||
tx.clear::<tables::Bytecodes>()?;
|
||||
tx.clear::<tables::Receipts>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::Execution.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
insert_genesis_state::<DatabaseEnv>(tx, self.chain.genesis())?;
|
||||
}
|
||||
StageEnum::AccountHashing => {
|
||||
tx.clear::<tables::HashedAccounts>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::AccountHashing.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
}
|
||||
StageEnum::StorageHashing => {
|
||||
tx.clear::<tables::HashedStorages>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::StorageHashing.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
}
|
||||
StageEnum::Hashing => {
|
||||
// Clear hashed accounts
|
||||
tx.clear::<tables::HashedAccounts>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::AccountHashing.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
let provider_rw = tool.provider_factory.provider_rw()?;
|
||||
let tx = provider_rw.tx_ref();
|
||||
|
||||
// Clear hashed storages
|
||||
tx.clear::<tables::HashedStorages>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::StorageHashing.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
}
|
||||
StageEnum::Merkle => {
|
||||
tx.clear::<tables::AccountsTrie>()?;
|
||||
tx.clear::<tables::StoragesTrie>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::MerkleExecute.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::MerkleUnwind.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
tx.delete::<tables::StageCheckpointProgresses>(
|
||||
StageId::MerkleExecute.to_string(),
|
||||
None,
|
||||
)?;
|
||||
}
|
||||
StageEnum::AccountHistory | StageEnum::StorageHistory => {
|
||||
tx.clear::<tables::AccountsHistory>()?;
|
||||
tx.clear::<tables::StoragesHistory>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::IndexAccountHistory.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::IndexStorageHistory.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
}
|
||||
StageEnum::TxLookup => {
|
||||
tx.clear::<tables::TransactionHashNumbers>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::TransactionLookup.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
insert_genesis_header::<DatabaseEnv>(tx, &static_file_provider, self.chain)?;
|
||||
}
|
||||
match self.stage {
|
||||
StageEnum::Headers => {
|
||||
tx.clear::<tables::CanonicalHeaders>()?;
|
||||
tx.clear::<tables::Headers>()?;
|
||||
tx.clear::<tables::HeaderTerminalDifficulties>()?;
|
||||
tx.clear::<tables::HeaderNumbers>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::Headers.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
insert_genesis_header::<DatabaseEnv>(tx, &static_file_provider, self.chain)?;
|
||||
}
|
||||
StageEnum::Bodies => {
|
||||
tx.clear::<tables::BlockBodyIndices>()?;
|
||||
tx.clear::<tables::Transactions>()?;
|
||||
tx.clear::<tables::TransactionBlocks>()?;
|
||||
tx.clear::<tables::BlockOmmers>()?;
|
||||
tx.clear::<tables::BlockWithdrawals>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::Bodies.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
insert_genesis_header::<DatabaseEnv>(tx, &static_file_provider, self.chain)?;
|
||||
}
|
||||
StageEnum::Senders => {
|
||||
tx.clear::<tables::TransactionSenders>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::SenderRecovery.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
}
|
||||
StageEnum::Execution => {
|
||||
tx.clear::<tables::PlainAccountState>()?;
|
||||
tx.clear::<tables::PlainStorageState>()?;
|
||||
tx.clear::<tables::AccountChangeSets>()?;
|
||||
tx.clear::<tables::StorageChangeSets>()?;
|
||||
tx.clear::<tables::Bytecodes>()?;
|
||||
tx.clear::<tables::Receipts>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::Execution.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
insert_genesis_state::<DatabaseEnv>(tx, self.chain.genesis())?;
|
||||
}
|
||||
StageEnum::AccountHashing => {
|
||||
tx.clear::<tables::HashedAccounts>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::AccountHashing.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
}
|
||||
StageEnum::StorageHashing => {
|
||||
tx.clear::<tables::HashedStorages>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::StorageHashing.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
}
|
||||
StageEnum::Hashing => {
|
||||
// Clear hashed accounts
|
||||
tx.clear::<tables::HashedAccounts>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::AccountHashing.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
|
||||
tx.put::<tables::StageCheckpoints>(StageId::Finish.to_string(), Default::default())?;
|
||||
// Clear hashed storages
|
||||
tx.clear::<tables::HashedStorages>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::StorageHashing.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
}
|
||||
StageEnum::Merkle => {
|
||||
tx.clear::<tables::AccountsTrie>()?;
|
||||
tx.clear::<tables::StoragesTrie>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::MerkleExecute.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::MerkleUnwind.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
tx.delete::<tables::StageCheckpointProgresses>(
|
||||
StageId::MerkleExecute.to_string(),
|
||||
None,
|
||||
)?;
|
||||
}
|
||||
StageEnum::AccountHistory | StageEnum::StorageHistory => {
|
||||
tx.clear::<tables::AccountsHistory>()?;
|
||||
tx.clear::<tables::StoragesHistory>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::IndexAccountHistory.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::IndexStorageHistory.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
insert_genesis_history(&provider_rw, &self.chain.genesis)?;
|
||||
}
|
||||
StageEnum::TxLookup => {
|
||||
tx.clear::<tables::TransactionHashNumbers>()?;
|
||||
tx.put::<tables::StageCheckpoints>(
|
||||
StageId::TransactionLookup.to_string(),
|
||||
Default::default(),
|
||||
)?;
|
||||
insert_genesis_header::<DatabaseEnv>(tx, &static_file_provider, self.chain)?;
|
||||
}
|
||||
}
|
||||
|
||||
static_file_provider.commit()?;
|
||||
tx.put::<tables::StageCheckpoints>(StageId::Finish.to_string(), Default::default())?;
|
||||
|
||||
Ok::<_, eyre::Error>(())
|
||||
})??;
|
||||
static_file_provider.commit()?;
|
||||
provider_rw.commit()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user