-
Notifications
You must be signed in to change notification settings - Fork 44
fix: Replace hardcoded solana_ prefix with BlockChainType lookup #426
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
base: main
Are you sure you want to change the base?
fix: Replace hardcoded solana_ prefix with BlockChainType lookup #426
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughReplaces hardcoded Solana network detection heuristics with runtime validation using actual network configurations. Introduces a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Please review my PR @shahnami |
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/repositories/monitor.rs`:
- Around line 447-538: Add a new unit test that constructs a Network (use the
same Network struct and set its blockchain_type to BlockchainType::Solana),
insert it into the networks HashMap used by
MonitorRepository::validate_monitor_references (or call validate_with_networks
if available), then create two monitors via MonitorBuilder: one Solana monitor
using a function/event signature without parentheses and one identical monitor
but validate against a non-Solana network; assert that validation succeeds when
the network's blockchain_type is Solana and that an error is returned when the
blockchain_type is not Solana (use MonitorRepository::<NetworkRepository,
TriggerRepository>::validate_monitor_references or validate_with_networks and
check result.is_ok()/unwrap_err()). Ensure the test references MonitorBuilder,
MonitorRepository::validate_monitor_references (or validate_with_networks), and
BlockchainType::Solana so reviewers can locate the changes.
🧹 Nitpick comments (4)
src/models/config/monitor_config.rs (2)
163-173: Misleading doc comment.The doc comment on lines 168-169 states this is "a public method exposed through an inherent impl on Monitor", but it appears to be defined inside the
impl ConfigLoader for Monitorblock. Ifvalidate_with_networksis part of theConfigLoadertrait, the comment should reflect that; if it's meant to be an inherent impl, it should be in a separateimpl Monitorblock.Suggested doc comment fix
- /// This is a public method exposed through an inherent impl on Monitor to allow - /// proper blockchain type detection in repository-level validation + /// This method enables proper blockchain type detection when network configurations + /// are available, falling back to heuristic detection for backward compatibility pub fn validate_with_networks(
446-463: Missing test coverage for network-aware validation.The new
validate_with_networks()method with actual network context (Some(&networks)) is not tested. Consider adding tests that verify:
- A monitor with a custom Solana network name (e.g., "my-solana-rpc") is correctly identified as a Solana monitor when network configs are provided
- Parenthesis-less signatures pass validation for custom-named Solana networks
Example test for network-aware validation
#[test] fn test_validate_with_networks_custom_solana_name() { use crate::models::{BlockChainType, Network}; // Create a network with custom name but Solana type let mut networks = HashMap::new(); // Note: You'll need to construct a Network with BlockChainType::Solana // networks.insert("my-custom-solana".to_string(), solana_network); let monitor = MonitorBuilder::new() .name("TestMonitor") .networks(vec!["my-custom-solana".to_string()]) .function("transferSol", None) // No parentheses - Solana style .build(); // Should pass with network context assert!(monitor.validate_with_networks(Some(&networks)).is_ok()); // Would fail without network context (heuristic doesn't match) assert!(monitor.validate_with_networks(None).is_err()); }src/repositories/monitor.rs (2)
103-114: Validation is now performed twice with potential redundancy.This block re-validates the entire monitor configuration, but most checks (name, networks, trigger conditions, script validation) already passed during
Monitor::load_from_path(). The only differentiation is the Solana detection mechanism.Consider either:
- Documenting why double validation is acceptable (e.g., "re-validates with network context for accurate blockchain type detection")
- Or extracting only the signature validation logic that benefits from network context into a separate method
This is acceptable as-is since the validation is fast, but the redundancy could cause confusion for future maintainers.
116-157: Duplicate trigger condition validation.This block validates script paths, extensions, and timeout, but identical checks already run in
Monitor::validate_with_networks()viavalidate_script_config()(lines 236-242 in monitor_config.rs). Both validate:
- Script path existence
- Extension matches language
- Timeout > 0
Since
validate_with_networks(Some(networks))is now called at line 105, this entire block is redundant and creates a maintenance burden.Consider removing redundant validation
// Validate monitor configuration with network context // This allows proper blockchain type detection instead of relying on naming conventions if let Err(e) = monitor.validate_with_networks(Some(networks)) { validation_errors.push(format!( "Monitor '{}' configuration validation failed: {}", monitor_name, e )); metadata.insert( format!("monitor_{}_validation_error", monitor_name), e.to_string(), ); } - - // Validate custom trigger conditions - for condition in &monitor.trigger_conditions { - let script_path = Path::new(&condition.script_path); - if !script_path.exists() { - validation_errors.push(format!( - "Monitor '{}' has a custom filter script that does not exist: {}", - monitor_name, condition.script_path - )); - } - // ... rest of duplicate validation ... - }
Thanks @ritik4ever, the |
thanks , i will fix it . |
|
I confirm that I have read and hereby agree to the OpenZeppelin Contributor License Agreement |
16f5f20 to
61c20fc
Compare
shahnami
left a comment
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.
Thanks for tackling the issue @ritik4ever!
The problem identification is spot-on, however I think there's a cleaner architectural approach we can take here.
Some concerns with the current approach:
- Monitors get validated twice: once in
load_from_path()→validate()(heuristic fallback), and again invalidate_monitor_references()with actual network types. - The
validate()path still falls back to prefix matching when networks isNone, so the bug persists for some code paths. validate_with_networksis added inside the trait impl but isn't part ofConfigLoader, which is a bit awkward.
If I can suggest an alternative approach..since signature validation is inherently context-dependent (needs network type), I'd suggest moving it entirely to the repository layer where that context already exists:
- Remove signature validation from
Monitor::validate()and keep it focused on monitor-intrinsic properties only. - Add a method on
BlockChainTypefor validation rules, something like:
pub struct SignatureRules {
pub requires_parentheses: bool,
// Future: pub max_signature_length: Option<usize>,
// Future: pub allowed_characters: &'static str,
}
impl BlockChainType {
pub fn signature_rules(&self) -> SignatureRules {
match self {
BlockChainType::EVM | BlockChainType::Stellar | BlockChainType::Midnight => {
SignatureRules { requires_parentheses: true }
}
BlockChainType::Solana => {
SignatureRules { requires_parentheses: false }
}
}
}
}
This pattern is nice because the exhaustive match forces handling new blockchain types, there is a single source of truth for per-chain behavior and it's easy to extend with more rules later.
- Add a helper in the repository for signature validation:
// In repositories/monitor.rs
fn validate_monitor_signatures(monitor, networks, errors) {
for network_slug in monitor.networks {
let rules = networks[network_slug].network_type.signature_rules();
if rules.requires_parentheses {
// validate function/event signatures have parens
}
}
}
and then call it from validate_monitor_references().
What do you think? Happy to discuss if you have questions about this approach!
@shahnami Thanks for the suggestions! Just want to confirm before I push: My plan:
Does this look right? Any preferences on where |
I think that's fine for now, alongside |
|
Hey @ritik4ever , looks like CI is failing. Can you please ensure you the pre-commit hooks installed? |
af835ce to
b9a362e
Compare
b9a362e to
58a0e14
Compare
|
@ritik4ever lets get those CI checks to pass. It looks like you need to update the lockfile? |
58a0e14 to
9263ff7
Compare
e09e55c to
a6fb849
Compare
|
@shahnami Rebased and conflicts resolved. The deploy preview failures are expected for external PRs. Ready for review when you have time! |
There's something wrong with the diff (~130k LoC). |
i will fix it. |
a6fb849 to
e065149
Compare
|
@ritik4ever can we work on updating lockfile for CI to pass (also make sure you pull latest |
e065149 to
f714af7
Compare
f714af7 to
c75537c
Compare
|
hii @shahnami Tests pass locally but CI is failing. Could you check if there's an issue with the CI workflow? The test output shows:
|
This commit addresses issue #409 by replacing the fragile string-based detection of Solana networks with proper blockchain type lookup.
Changes:
Benefits:
This builds on the Solana support added in #408 by making the network type detection more robust and flexible.
Fixes #409
I confirm that I have read and hereby agree to the OpenZeppelin Contributor License Agreement
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.