-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat(cli): reth prune
#9055
Merged
Merged
feat(cli): reth prune
#9055
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0f26dec
wip
shekhirin 7b6c69d
feat(cli): prune
shekhirin e062165
fix clippy
shekhirin 4675123
update book, remove reth-prune-types dep
shekhirin 46e8f37
copy to static files first
shekhirin 2ebd986
grab config from --full flag too
shekhirin ad25e1e
update book
shekhirin 8eea28d
account for zero deposit contract block number
shekhirin c0893d6
pass segment
shekhirin f5c30f8
Revert "pass segment"
shekhirin acfb1e1
remove pruning args
shekhirin df5e8ab
update book
shekhirin 275f17d
add info logs, deduplicate copy to static files part
shekhirin 0edd522
part -> segment
shekhirin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//! Command that runs pruning without any limits. | ||
|
||
use crate::commands::common::{AccessRights, Environment, EnvironmentArgs}; | ||
use clap::Parser; | ||
use reth_provider::StageCheckpointReader; | ||
use reth_prune::PrunerBuilder; | ||
use reth_stages::StageId; | ||
use reth_static_file::{HighestStaticFiles, StaticFileProducer}; | ||
|
||
/// Prunes according to the configuration without any limits | ||
#[derive(Debug, Parser)] | ||
pub struct PruneCommand { | ||
#[command(flatten)] | ||
env: EnvironmentArgs, | ||
} | ||
|
||
impl PruneCommand { | ||
/// Execute the `prune` command | ||
pub async fn execute(self) -> eyre::Result<()> { | ||
let Environment { config, provider_factory, .. } = self.env.init(AccessRights::RW)?; | ||
let prune_config = config.prune.unwrap_or_default(); | ||
|
||
let static_file_producer = | ||
StaticFileProducer::new(provider_factory.clone(), prune_config.segments.clone()); | ||
let static_file_producer = static_file_producer.lock(); | ||
|
||
// Copies data from database to static files | ||
let lowest_static_file_height = { | ||
let provider = provider_factory.provider()?; | ||
let stages_checkpoints = [StageId::Headers, StageId::Execution, StageId::Bodies] | ||
.into_iter() | ||
.map(|stage| { | ||
provider.get_stage_checkpoint(stage).map(|c| c.map(|c| c.block_number)) | ||
}) | ||
.collect::<Result<Vec<_>, _>>()?; | ||
|
||
let targets = static_file_producer.get_static_file_targets(HighestStaticFiles { | ||
headers: stages_checkpoints[0], | ||
receipts: stages_checkpoints[1], | ||
transactions: stages_checkpoints[2], | ||
})?; | ||
static_file_producer.run(targets)?; | ||
shekhirin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
stages_checkpoints.into_iter().min().expect("exists") | ||
}; | ||
|
||
// Deletes data which has been copied to static files. | ||
if let Some(prune_tip) = lowest_static_file_height { | ||
// Run the pruner according to the configuration, and don't enforce any limits on it | ||
shekhirin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let mut pruner = PrunerBuilder::new(prune_config) | ||
.prune_delete_limit(usize::MAX) | ||
.build(provider_factory); | ||
|
||
pruner.run(prune_tip)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# reth prune | ||
|
||
Prune according to the configuration without any limits | ||
|
||
```bash | ||
$ reth prune --help | ||
Usage: reth prune [OPTIONS] | ||
|
||
Options: | ||
--instance <INSTANCE> | ||
Add a new instance of a node. | ||
|
||
Configures the ports of the node to avoid conflicts with the defaults. This is useful for running multiple nodes on the same machine. | ||
|
||
Max number of instances is 200. It is chosen in a way so that it's not possible to have port numbers that conflict with each other. | ||
|
||
Changes to the following port numbers: - `DISCOVERY_PORT`: default + `instance` - 1 - `AUTH_PORT`: default + `instance` * 100 - 100 - `HTTP_RPC_PORT`: default - `instance` + 1 - `WS_RPC_PORT`: default + `instance` * 2 - 2 | ||
|
||
[default: 1] | ||
|
||
-h, --help | ||
Print help (see a summary with '-h') | ||
|
||
Datadir: | ||
--datadir <DATA_DIR> | ||
The path to the data dir for all reth files and subdirectories. | ||
|
||
Defaults to the OS-specific data directory: | ||
|
||
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/` | ||
- Windows: `{FOLDERID_RoamingAppData}/reth/` | ||
- macOS: `$HOME/Library/Application Support/reth/` | ||
|
||
[default: default] | ||
|
||
--datadir.static_files <PATH> | ||
The absolute path to store static files in. | ||
|
||
--config <FILE> | ||
The path to the configuration file to use | ||
|
||
--chain <CHAIN_OR_PATH> | ||
The chain this node is running. | ||
Possible values are either a built-in chain or the path to a chain specification file. | ||
|
||
Built-in chains: | ||
mainnet, sepolia, goerli, holesky, dev | ||
|
||
[default: mainnet] | ||
|
||
Database: | ||
--db.log-level <LOG_LEVEL> | ||
Database logging level. Levels higher than "notice" require a debug build | ||
|
||
Possible values: | ||
- fatal: Enables logging for critical conditions, i.e. assertion failures | ||
- error: Enables logging for error conditions | ||
- warn: Enables logging for warning conditions | ||
- notice: Enables logging for normal but significant condition | ||
- verbose: Enables logging for verbose informational | ||
- debug: Enables logging for debug-level messages | ||
- trace: Enables logging for trace debug-level messages | ||
- extra: Enables logging for extra debug-level messages | ||
|
||
--db.exclusive <EXCLUSIVE> | ||
Open environment in exclusive/monopolistic mode. Makes it possible to open a database on an NFS volume | ||
|
||
[possible values: true, false] | ||
|
||
Logging: | ||
--log.stdout.format <FORMAT> | ||
The format to use for logs written to stdout | ||
|
||
[default: terminal] | ||
|
||
Possible values: | ||
- json: Represents JSON formatting for logs. This format outputs log records as JSON objects, making it suitable for structured logging | ||
- log-fmt: Represents logfmt (key=value) formatting for logs. This format is concise and human-readable, typically used in command-line applications | ||
- terminal: Represents terminal-friendly formatting for logs | ||
|
||
--log.stdout.filter <FILTER> | ||
The filter to use for logs written to stdout | ||
|
||
[default: ] | ||
|
||
--log.file.format <FORMAT> | ||
The format to use for logs written to the log file | ||
|
||
[default: terminal] | ||
|
||
Possible values: | ||
- json: Represents JSON formatting for logs. This format outputs log records as JSON objects, making it suitable for structured logging | ||
- log-fmt: Represents logfmt (key=value) formatting for logs. This format is concise and human-readable, typically used in command-line applications | ||
- terminal: Represents terminal-friendly formatting for logs | ||
|
||
--log.file.filter <FILTER> | ||
The filter to use for logs written to the log file | ||
|
||
[default: debug] | ||
|
||
--log.file.directory <PATH> | ||
The path to put log files in | ||
|
||
[default: <CACHE_DIR>/logs] | ||
|
||
--log.file.max-size <SIZE> | ||
The maximum size (in MB) of one log file | ||
|
||
[default: 200] | ||
|
||
--log.file.max-files <COUNT> | ||
The maximum amount of log files that will be stored. If set to 0, background file logging is disabled | ||
|
||
[default: 5] | ||
|
||
--log.journald | ||
Write logs to journald | ||
|
||
--log.journald.filter <FILTER> | ||
The filter to use for logs written to journald | ||
|
||
[default: error] | ||
|
||
--color <COLOR> | ||
Sets whether or not the formatter emits ANSI terminal escape codes for colors and other text formatting | ||
|
||
[default: always] | ||
|
||
Possible values: | ||
- always: Colors on | ||
- auto: Colors on | ||
- never: Colors off | ||
|
||
Display: | ||
-v, --verbosity... | ||
Set the minimum log level. | ||
|
||
-v Errors | ||
-vv Warnings | ||
-vvv Info | ||
-vvvv Debug | ||
-vvvvv Traces (warning: very verbose!) | ||
|
||
-q, --quiet | ||
Silence all log output | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we dedup the code with the one on pipeline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done