mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: support ms for --builder.interval (#10168)
This commit is contained in:
6
book/cli/reth/node.md
vendored
6
book/cli/reth/node.md
vendored
@ -441,8 +441,10 @@ Builder:
|
|||||||
|
|
||||||
[default: 30000000]
|
[default: 30000000]
|
||||||
|
|
||||||
--builder.interval <SECONDS>
|
--builder.interval <DURATION>
|
||||||
The interval at which the job should build a new payload after the last (in seconds)
|
The interval at which the job should build a new payload after the last.
|
||||||
|
|
||||||
|
Interval is specified in seconds or in milliseconds if the value ends with `ms`: * `50ms` -> 50 milliseconds * `1` -> 1 second
|
||||||
|
|
||||||
[default: 1]
|
[default: 1]
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,10 @@ pub use load_secret_key::get_secret_key;
|
|||||||
|
|
||||||
/// Cli parsers functions.
|
/// Cli parsers functions.
|
||||||
pub mod parsers;
|
pub mod parsers;
|
||||||
pub use parsers::{hash_or_num_value_parser, parse_duration_from_secs, parse_socket_address};
|
pub use parsers::{
|
||||||
|
hash_or_num_value_parser, parse_duration_from_secs, parse_duration_from_secs_or_ms,
|
||||||
|
parse_socket_address,
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(all(unix, any(target_env = "gnu", target_os = "macos")))]
|
#[cfg(all(unix, any(target_env = "gnu", target_os = "macos")))]
|
||||||
pub mod sigsegv_handler;
|
pub mod sigsegv_handler;
|
||||||
|
|||||||
@ -12,6 +12,23 @@ pub fn parse_duration_from_secs(arg: &str) -> eyre::Result<Duration, std::num::P
|
|||||||
Ok(Duration::from_secs(seconds))
|
Ok(Duration::from_secs(seconds))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Helper to parse a [Duration] from seconds if it's a number or milliseconds if the input contains
|
||||||
|
/// a `ms` suffix:
|
||||||
|
/// * `5ms` -> 5 milliseconds
|
||||||
|
/// * `5` -> 5 seconds
|
||||||
|
/// * `5s` -> 5 seconds
|
||||||
|
pub fn parse_duration_from_secs_or_ms(
|
||||||
|
arg: &str,
|
||||||
|
) -> eyre::Result<Duration, std::num::ParseIntError> {
|
||||||
|
if arg.ends_with("ms") {
|
||||||
|
arg.trim_end_matches("ms").parse::<u64>().map(Duration::from_millis)
|
||||||
|
} else if arg.ends_with('s') {
|
||||||
|
arg.trim_end_matches('s').parse::<u64>().map(Duration::from_secs)
|
||||||
|
} else {
|
||||||
|
arg.parse::<u64>().map(Duration::from_secs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse [`BlockHashOrNumber`]
|
/// Parse [`BlockHashOrNumber`]
|
||||||
pub fn hash_or_num_value_parser(value: &str) -> eyre::Result<BlockHashOrNumber, eyre::Error> {
|
pub fn hash_or_num_value_parser(value: &str) -> eyre::Result<BlockHashOrNumber, eyre::Error> {
|
||||||
match B256::from_str(value) {
|
match B256::from_str(value) {
|
||||||
@ -93,4 +110,18 @@ mod tests {
|
|||||||
assert_eq!(socket_addr.port(), port);
|
assert_eq!(socket_addr.port(), port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_ms_or_seconds() {
|
||||||
|
let ms = parse_duration_from_secs_or_ms("5ms").unwrap();
|
||||||
|
assert_eq!(ms, Duration::from_millis(5));
|
||||||
|
|
||||||
|
let seconds = parse_duration_from_secs_or_ms("5").unwrap();
|
||||||
|
assert_eq!(seconds, Duration::from_secs(5));
|
||||||
|
|
||||||
|
let seconds = parse_duration_from_secs_or_ms("5s").unwrap();
|
||||||
|
assert_eq!(seconds, Duration::from_secs(5));
|
||||||
|
|
||||||
|
assert!(parse_duration_from_secs_or_ms("5ns").is_err());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use clap::{
|
|||||||
builder::{RangedU64ValueParser, TypedValueParser},
|
builder::{RangedU64ValueParser, TypedValueParser},
|
||||||
Arg, Args, Command,
|
Arg, Args, Command,
|
||||||
};
|
};
|
||||||
use reth_cli_util::parse_duration_from_secs;
|
use reth_cli_util::{parse_duration_from_secs, parse_duration_from_secs_or_ms};
|
||||||
use reth_primitives::constants::{
|
use reth_primitives::constants::{
|
||||||
ETHEREUM_BLOCK_GAS_LIMIT, MAXIMUM_EXTRA_DATA_SIZE, SLOT_DURATION,
|
ETHEREUM_BLOCK_GAS_LIMIT, MAXIMUM_EXTRA_DATA_SIZE, SLOT_DURATION,
|
||||||
};
|
};
|
||||||
@ -21,8 +21,12 @@ pub struct PayloadBuilderArgs {
|
|||||||
#[arg(long = "builder.gaslimit", default_value = "30000000", value_name = "GAS_LIMIT")]
|
#[arg(long = "builder.gaslimit", default_value = "30000000", value_name = "GAS_LIMIT")]
|
||||||
pub max_gas_limit: u64,
|
pub max_gas_limit: u64,
|
||||||
|
|
||||||
/// The interval at which the job should build a new payload after the last (in seconds).
|
/// The interval at which the job should build a new payload after the last.
|
||||||
#[arg(long = "builder.interval", value_parser = parse_duration_from_secs, default_value = "1", value_name = "SECONDS")]
|
///
|
||||||
|
/// Interval is specified in seconds or in milliseconds if the value ends with `ms`:
|
||||||
|
/// * `50ms` -> 50 milliseconds
|
||||||
|
/// * `1` -> 1 second
|
||||||
|
#[arg(long = "builder.interval", value_parser = parse_duration_from_secs_or_ms, default_value = "1", value_name = "DURATION")]
|
||||||
pub interval: Duration,
|
pub interval: Duration,
|
||||||
|
|
||||||
/// The deadline for when the payload builder job should resolve.
|
/// The deadline for when the payload builder job should resolve.
|
||||||
@ -154,4 +158,20 @@ mod tests {
|
|||||||
let args = CommandParser::<PayloadBuilderArgs>::parse_from(["reth"]).args;
|
let args = CommandParser::<PayloadBuilderArgs>::parse_from(["reth"]).args;
|
||||||
assert_eq!(args, default_args);
|
assert_eq!(args, default_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_args_with_s_interval() {
|
||||||
|
let args =
|
||||||
|
CommandParser::<PayloadBuilderArgs>::parse_from(["reth", "--builder.interval", "50"])
|
||||||
|
.args;
|
||||||
|
assert_eq!(args.interval, Duration::from_secs(50));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_args_with_ms_interval() {
|
||||||
|
let args =
|
||||||
|
CommandParser::<PayloadBuilderArgs>::parse_from(["reth", "--builder.interval", "50ms"])
|
||||||
|
.args;
|
||||||
|
assert_eq!(args.interval, Duration::from_millis(50));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user