feat(rpc): add Other(String) variant to RethRpcModule for custom RPC modules#17758
feat(rpc): add Other(String) variant to RethRpcModule for custom RPC modules#17758
Conversation
634edcd to
7c0cd10
Compare
4c8b6a3 to
c231143
Compare
mattsse
left a comment
There was a problem hiding this comment.
introducing a new string based variant makes sense,
however we need a few additional cli level parse tests here that ensure that this behaves as expected,
and the validation part is a bit to restrict, if we skip ::Other then we likely dont need this?
however validation here is missing, the problematic part is something like --http.api eht which is clearly a typo that we currently dont catch,
since this is CLI specific, we need to make this behaviour somehow configurable.
my suggestion here would be introducing something liek
RethCliParsers {
type ChainSpec:
type RpcModules
}
and replacing C: ChainSpecParser with that
reth/crates/ethereum/cli/src/interface.rs
Line 30 in 6166209
then we can configure how rpc modules are parsed
makes total sense, done here 68f8abc |
mattsse
left a comment
There was a problem hiding this comment.
after reviewing I understood why we don't integrate an rpcmoduleparser, we can't really propagate the module parser down to the rpcserverargs because then we leak an unconstrained generic all over the place, right?
so perhaps we enforce this either when we do cli::parse or we enforce this in the Nodecommand::run somewhere early
so we do need to instead validate the parsed modules after somewhere, unsure where the proper location for that is.
maybe this should actually be enforced by the parser impl for the Cli itself?
| type ChainSpecParser: reth_cli::chainspec::ChainSpecParser + std::fmt::Debug; | ||
|
|
||
| /// The RPC module validator type. | ||
| type RpcModuleValidator: reth_rpc_server_types::RpcModuleValidator; |
There was a problem hiding this comment.
should we follow the same convention as ChainSpecParser here and move the parse_rpc_modules in the trait?
| /// Check if two strings are likely typos using edit distance. | ||
| fn is_likely_typo(input: &str, target: &str) -> bool { | ||
| // Quick check: if lengths differ by more than 2, unlikely to be a typo | ||
| if input.len().abs_diff(target.len()) > 2 { | ||
| return false; | ||
| } | ||
|
|
||
| let distance = edit_distance(input, target); | ||
|
|
||
| // Consider it a typo if: | ||
| // - Distance is 1 (single char difference) | ||
| // - Distance is 2 and strings are at least 3 chars (for transpositions like "eth" -> "eht") | ||
| match distance { | ||
| 1 => true, | ||
| 2 => input.len() >= 3 && target.len() >= 3, | ||
| _ => false, | ||
| } | ||
| } | ||
|
|
||
| /// Calculate edit distance between two strings. | ||
| fn edit_distance(s1: &str, s2: &str) -> usize { |
There was a problem hiding this comment.
dont think we need this
either the user input is valid, or it's not, no need to check for typos
crates/rpc/rpc-builder/src/lib.rs
Outdated
| // Skip Other variants - they should be registered via extend_rpc_modules | ||
| if matches!(namespace, RethRpcModule::Other(_)) { |
There was a problem hiding this comment.
I prefer introducing is_other functions than adding matches! for checks like
fgimenez
left a comment
There was a problem hiding this comment.
so perhaps we enforce this either when we do cli::parse or we enforce this in the Nodecommand::run somewhere early
thx, great catch! now this is done after cli parsing, in with_runner_and_components during NodeCommand::run, ptal
| type ChainSpecParser: reth_cli::chainspec::ChainSpecParser + std::fmt::Debug; | ||
|
|
||
| /// The RPC module validator type. | ||
| type RpcModuleValidator: reth_rpc_server_types::RpcModuleValidator; |
crates/rpc/rpc-builder/src/lib.rs
Outdated
| // Skip Other variants - they should be registered via extend_rpc_modules | ||
| if matches!(namespace, RethRpcModule::Other(_)) { |
| /// Check if two strings are likely typos using edit distance. | ||
| fn is_likely_typo(input: &str, target: &str) -> bool { | ||
| // Quick check: if lengths differ by more than 2, unlikely to be a typo | ||
| if input.len().abs_diff(target.len()) > 2 { | ||
| return false; | ||
| } | ||
|
|
||
| let distance = edit_distance(input, target); | ||
|
|
||
| // Consider it a typo if: | ||
| // - Distance is 1 (single char difference) | ||
| // - Distance is 2 and strings are at least 3 chars (for transpositions like "eth" -> "eht") | ||
| match distance { | ||
| 1 => true, | ||
| 2 => input.len() >= 3 && target.len() >= 3, | ||
| _ => false, | ||
| } | ||
| } | ||
|
|
||
| /// Calculate edit distance between two strings. | ||
| fn edit_distance(s1: &str, s2: &str) -> usize { |
| vergen_build_timestamp: Cow::Owned(env!("VERGEN_BUILD_TIMESTAMP").to_string()), | ||
| vergen_cargo_target_triple: Cow::Owned(env!("VERGEN_CARGO_TARGET_TRIPLE").to_string()), | ||
| vergen_cargo_features: Cow::Owned(env!("VERGEN_CARGO_FEATURES").to_string()), | ||
| vergen_cargo_features: Cow::Owned(String::new()), |
| #[command(author, version =version_metadata().short_version.as_ref(), long_version = version_metadata().long_version.as_ref(), about = "Reth", long_about = None)] | ||
| pub struct Cli<C: ChainSpecParser = EthereumChainSpecParser, Ext: clap::Args + fmt::Debug = NoArgs> | ||
| { | ||
| pub struct Cli<P: RethCliParsers = EthereumCliParsers, Ext: clap::Args + fmt::Debug = NoArgs> { |
There was a problem hiding this comment.
I'm wondering if a less invasive change would be to do Cli<C: ChainSpecParser = EthereumChainSpecParser, Ext: clap::Args + fmt::Debug = NoArgs, R: RpcModuleValidator = DefaultRpcModuleValidator>
That way we won't need to change most of the cli code
|
closing in favor of #18160 |
Adds support for custom RPC modules by introducing an
Other(String)variant toRethRpcModule. This allows users to configure and use RPC modules beyond the predefined set, enabling greater extensibility for custom implementations.The PR also includes validation to warn users when they configure RPC modules that haven't been registered with the RPC builder, helping catch configuration errors early.