fix: drop stale subscription updates#1264
Conversation
📝 WalkthroughWalkthroughThis pull request implements a race-condition mitigation for account lifecycle management in the Chainlink validator. It introduces a per-pubkey subscription lock mechanism that prevents concurrent eviction and subscription acquisition for the same account. The pattern flows through three layers: a new Suggested reviewers
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@magicblock-chainlink/src/chainlink/fetch_cloner/tests.rs`:
- Around line 1666-1673: The test currently breaks out immediately because
clone_request_count() can be 0 at baseline; change the test to first observe
that a clone request was created (wait for
ctx.fetch_cloner.cloner().clone_request_count() to become > 0 or use a
deterministic post-send signal from the code path) then wait for it to drop back
to 0; in other words, gate the zero-check behind a confirmed prior increment (or
await a dedicated processing-complete signal/oneshot you add to the async drop
path) so the test actually exercises the async drop processing in tests.rs where
ctx.fetch_cloner.cloner() and clone_request_count() are used.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 6fd6c77b-e2fa-466c-a66d-497b39471bb0
📒 Files selected for processing (4)
magicblock-chainlink/src/chainlink/fetch_cloner/mod.rsmagicblock-chainlink/src/chainlink/fetch_cloner/tests.rsmagicblock-chainlink/src/chainlink/mod.rsmagicblock-chainlink/src/remote_account_provider/mod.rs
| tokio::time::timeout(Duration::from_secs(1), async { | ||
| loop { | ||
| tokio::time::sleep(Duration::from_millis(10)).await; | ||
| if ctx.fetch_cloner.cloner().clone_request_count() == 0 { | ||
| break; | ||
| } | ||
| } | ||
| }) |
There was a problem hiding this comment.
Test can pass before the stale update is actually processed
At Line 1669, clone_request_count() == 0 is true at baseline, so this loop can exit immediately and the test may pass without exercising the async drop path at all. Please gate on a post-send processing signal (or at least a deterministic barrier) before asserting zero clone requests.
Suggested adjustment
- tokio::time::timeout(Duration::from_secs(1), async {
- loop {
- tokio::time::sleep(Duration::from_millis(10)).await;
- if ctx.fetch_cloner.cloner().clone_request_count() == 0 {
- break;
- }
- }
- })
- .await
- .expect("timed out waiting for stale update to be dropped");
+ // Give the subscription task a chance to process the forwarded update.
+ tokio::time::sleep(Duration::from_millis(50)).await;
+ assert_eq!(ctx.fetch_cloner.cloner().clone_request_count(), 0);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@magicblock-chainlink/src/chainlink/fetch_cloner/tests.rs` around lines 1666 -
1673, The test currently breaks out immediately because clone_request_count()
can be 0 at baseline; change the test to first observe that a clone request was
created (wait for ctx.fetch_cloner.cloner().clone_request_count() to become > 0
or use a deterministic post-send signal from the code path) then wait for it to
drop back to 0; in other words, gate the zero-check behind a confirmed prior
increment (or await a dedicated processing-complete signal/oneshot you add to
the async drop path) so the test actually exercises the async drop processing in
tests.rs where ctx.fetch_cloner.cloner() and clone_request_count() are used.
Summary
Prevent stale forwarded subscription updates from recreating local bank state for accounts that are no longer watched by the remote account provider.
Details
magicblock-chainlink
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests