Skip to content
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
18 changes: 12 additions & 6 deletions crates/cli/commands/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,22 @@ impl<C: ChainSpecParser> EnvironmentArgs<C> {
// commands can proceed.
debug!(target: "reth::cli", ?rocksdb_path, "RocksDB not found, initializing empty database");
reth_fs_util::create_dir_all(&rocksdb_path)?;
RocksDBProvider::builder(data_dir.rocksdb())
let mut builder = RocksDBProvider::builder(data_dir.rocksdb())
.with_default_tables()
.with_database_log_level(self.db.log_level)
.build()?
.with_database_log_level(self.db.log_level);
if let Some(cache_size) = self.db.rocksdb_block_cache_size {
builder = builder.with_block_cache_size(cache_size);
}
builder.build()?
} else {
RocksDBProvider::builder(data_dir.rocksdb())
let mut builder = RocksDBProvider::builder(data_dir.rocksdb())
.with_default_tables()
.with_database_log_level(self.db.log_level)
.with_read_only(!access.is_read_write())
.build()?
.with_read_only(!access.is_read_write());
if let Some(cache_size) = self.db.rocksdb_block_cache_size {
builder = builder.with_block_cache_size(cache_size);
}
builder.build()?
};

let provider_factory =
Expand Down
35 changes: 18 additions & 17 deletions crates/cli/commands/src/re_execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use reth_provider::{
};
use reth_revm::database::StateProviderDatabase;
use reth_stages::stages::calculate_gas_used_from_headers;
use reth_storage_api::{DBProvider, TryIntoHistoricalStateProvider};
use reth_storage_api::DBProvider;
use std::{
sync::{
atomic::{AtomicU64, Ordering},
Expand Down Expand Up @@ -69,13 +69,18 @@ impl<C: ChainSpecParser> Command<C> {
impl<C: ChainSpecParser<ChainSpec: EthChainSpec + Hardforks + EthereumHardforks>> Command<C> {
/// Execute `re-execute` command
pub async fn execute<N>(
self,
mut self,
components: impl CliComponentsBuilder<N>,
runtime: reth_tasks::Runtime,
) -> eyre::Result<()>
where
N: CliNodeTypes<ChainSpec = C::ChainSpec>,
{
// Default to 4GB RocksDB block cache for re-execute unless explicitly set.
if self.env.db.rocksdb_block_cache_size.is_none() {
self.env.db.rocksdb_block_cache_size = Some(4 << 30);
}

let Environment { provider_factory, .. } = self.env.init::<N>(AccessRights::RO, runtime)?;

let components = components(provider_factory.chain_spec());
Expand Down Expand Up @@ -109,20 +114,6 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + Hardforks + EthereumHardforks>
min_block..=max_block,
)?;

let db_at = {
let provider_factory = provider_factory.clone();
move |block_number: u64| {
StateProviderDatabase(
provider_factory
.provider()
.unwrap()
.disable_long_read_transaction_safety()
.try_into_history_at_block(block_number)
.unwrap(),
)
}
};

let skip_invalid_blocks = self.skip_invalid_blocks;
let blocks_per_chunk = self.blocks_per_chunk;
let (stats_tx, mut stats_rx) = mpsc::unbounded_channel();
Expand All @@ -138,13 +129,23 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + Hardforks + EthereumHardforks>
let provider_factory = provider_factory.clone();
let evm_config = components.evm_config().clone();
let consensus = components.consensus().clone();
let db_at = db_at.clone();
let stats_tx = stats_tx.clone();
let info_tx = info_tx.clone();
let cancellation = cancellation.clone();
let next_block = Arc::clone(&next_block);
tasks.spawn_blocking(move || {
let executor_lifetime = Duration::from_secs(600);
let provider = provider_factory.database_provider_ro()?.disable_long_read_transaction_safety();

let db_at = {
|block_number: u64| {
StateProviderDatabase(
provider
.history_by_block_number(block_number)
.unwrap(),
)
}
};

loop {
if cancellation.is_cancelled() {
Expand Down
7 changes: 7 additions & 0 deletions crates/node/core/src/args/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ pub struct DatabaseArgs {
value_parser = value_parser!(SyncMode),
)]
pub sync_mode: Option<SyncMode>,
/// `RocksDB` block cache size (e.g., 512MB, 4GB).
///
/// Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks.
/// A larger cache reduces repeated decompression of hot blocks, improving read
/// performance for history lookups.
#[arg(long = "db.rocksdb-block-cache-size", value_parser = parse_byte_size)]
pub rocksdb_block_cache_size: Option<usize>,
}

impl DatabaseArgs {
Expand Down
10 changes: 9 additions & 1 deletion crates/storage/provider/src/providers/database/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,16 @@ impl<TX: DbTx + 'static, N: NodeTypes> DatabaseProvider<TX, N> {
&'a self,
block_hash: BlockHash,
) -> ProviderResult<Box<dyn StateProvider + 'a>> {
let mut block_number =
let block_number =
self.block_number(block_hash)?.ok_or(ProviderError::BlockHashNotFound(block_hash))?;
self.history_by_block_number(block_number)
}

/// Storage provider for state at that given block number
pub fn history_by_block_number<'a>(
&'a self,
mut block_number: BlockNumber,
) -> ProviderResult<Box<dyn StateProvider + 'a>> {
if block_number == self.best_block_number().unwrap_or_default() &&
block_number == self.last_block_number().unwrap_or_default()
{
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/db.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Static Files:
--static-files.blocks-per-file.headers <BLOCKS_PER_FILE_HEADERS>
Number of blocks per file for the headers segment
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/db/diff.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

--table <TABLE>
The table name to diff. If not specified, all tables are diffed.

Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/download.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Static Files:
--static-files.blocks-per-file.headers <BLOCKS_PER_FILE_HEADERS>
Number of blocks per file for the headers segment
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/export-era.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Static Files:
--static-files.blocks-per-file.headers <BLOCKS_PER_FILE_HEADERS>
Number of blocks per file for the headers segment
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/import-era.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Static Files:
--static-files.blocks-per-file.headers <BLOCKS_PER_FILE_HEADERS>
Number of blocks per file for the headers segment
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/import.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Static Files:
--static-files.blocks-per-file.headers <BLOCKS_PER_FILE_HEADERS>
Number of blocks per file for the headers segment
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/init-state.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Static Files:
--static-files.blocks-per-file.headers <BLOCKS_PER_FILE_HEADERS>
Number of blocks per file for the headers segment
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/init.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Static Files:
--static-files.blocks-per-file.headers <BLOCKS_PER_FILE_HEADERS>
Number of blocks per file for the headers segment
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Dev testnet:
--dev
Start the node in dev mode
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/prune.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Static Files:
--static-files.blocks-per-file.headers <BLOCKS_PER_FILE_HEADERS>
Number of blocks per file for the headers segment
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/re-execute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Static Files:
--static-files.blocks-per-file.headers <BLOCKS_PER_FILE_HEADERS>
Number of blocks per file for the headers segment
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/stage/drop.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Static Files:
--static-files.blocks-per-file.headers <BLOCKS_PER_FILE_HEADERS>
Number of blocks per file for the headers segment
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/stage/dump.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Static Files:
--static-files.blocks-per-file.headers <BLOCKS_PER_FILE_HEADERS>
Number of blocks per file for the headers segment
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/stage/run.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Static Files:
--static-files.blocks-per-file.headers <BLOCKS_PER_FILE_HEADERS>
Number of blocks per file for the headers segment
Expand Down
5 changes: 5 additions & 0 deletions docs/vocs/docs/pages/cli/reth/stage/unwind.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ Database:
--db.sync-mode <SYNC_MODE>
Controls how aggressively the database synchronizes data to disk

--db.rocksdb-block-cache-size <ROCKSDB_BLOCK_CACHE_SIZE>
`RocksDB` block cache size (e.g., 512MB, 4GB).

Controls the size of the in-memory LRU cache for decompressed `RocksDB` blocks. A larger cache reduces repeated decompression of hot blocks, improving read performance for history lookups.

Static Files:
--static-files.blocks-per-file.headers <BLOCKS_PER_FILE_HEADERS>
Number of blocks per file for the headers segment
Expand Down
Loading