fix: evict balance-failing transactions from mempool at admission and mining time#122
fix: evict balance-failing transactions from mempool at admission and mining time#122g-k-s-03 wants to merge 2 commits into
Conversation
… mining time Signed-off-by: g-k-s-03 <govindsingh97704@gmail.com>
|
Warning Review limit reached
Next review available in: 47 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughMempool now supports an optional ChangesMempool DoS fix
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ 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 `@minichain/mempool.py`:
- Line 3: Ruff flagged two small style issues in the mempool module: the import
of Callable should come from collections.abc instead of typing, and __init__ is
missing an explicit -> None return annotation. Update the imports in mempool.py
accordingly, and add the None return annotation to the __init__ method (and the
other affected __init__ at the referenced location) while keeping the existing
TYPE_CHECKING and Optional usage unchanged.
🪄 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: 05baf8db-4346-4fe2-bc5e-c70330e31e8a
📒 Files selected for processing (3)
main.pyminichain/mempool.pytests/test_core.py
Signed-off-by: g-k-s-03 <govindsingh97704@gmail.com>
|
@coderabbitai review |
✅ Action performedReview finished.
|
Addressed Issues: Fixes #121
summary
Transactions that passed signature verification but failed balance checks during mining were never evicted from the mempool. This allowed an attacker with zero funds to permanently fill the mempool with validly signed but unfunded transactions at no cost, blocking all future legitimate transactions.
What Was Fixed
Added an optional state_provider callable to Mempool.init(). When configured, add_transaction() now rejects transactions whose sender cannot afford amount + fee immediately at admission time, before they ever enter the mempool. If no state_provider is configured, the mempool falls back to signature-only admission, preserving backward compatibility.
mine_and_process_block() now explicitly tracks transactions that are permanently stuck (nonce matches but balance is insufficient) and evicts them after each mining cycle instead of silently skipping them. Higher-nonce transactions are left in the mempool for future cycles as before.
Mempool is now instantiated with state_provider=lambda: chain.state so it always observes the latest state, even after chain reorganizations or block mining replace the state wholesale.
Testing
Two new tests added to tests/test_core.py:
test_mempool_rejects_unfunded_transaction — confirms balance-failing transactions are rejected at admission
test_unminable_transaction_evicted_during_mining — confirms stuck transactions are evicted during a mining cycle
py -3.11 -m pytest tests/ -v
76 passed, 0 failed
Summary by CodeRabbit