Skip to content

Feat/peer blacklisting#113

Merged
SIDDHANTCOOKIE merged 8 commits into
mainfrom
feat/peer-blacklisting
Jul 3, 2026
Merged

Feat/peer blacklisting#113
SIDDHANTCOOKIE merged 8 commits into
mainfrom
feat/peer-blacklisting

Conversation

@SIDDHANTCOOKIE

@SIDDHANTCOOKIE SIDDHANTCOOKIE commented Jul 3, 2026

Copy link
Copy Markdown
Member

Addressed Issues:

Fixes #(TODO:issue number)

Screenshots/Recordings:

TODO: If applicable, add screenshots or recordings that demonstrate the interface before and after the changes.

Additional Notes:

AI Usage Disclosure:

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: TODO

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

  • New Features

    • Improved peer misbehavior handling with automatic bans, disconnects, and gradual counter decay.
    • Node data persistence now preserves banned peer state across restarts.
  • Bug Fixes

    • Block acceptance and chain sync now rely on explicit validation results, improving consistency.
    • Transaction processing now rejects malformed, invalid, and failed messages more reliably.
    • Transaction fees are now validated as non-negative values.

g-k-s-03 and others added 8 commits June 28, 2026 23:32
Signed-off-by: g-k-s-03 <govindsingh97704@gmail.com>
Signed-off-by: g-k-s-03 <govindsingh97704@gmail.com>
…lean bug and apply_transaction malformed guard

Signed-off-by: g-k-s-03 <govindsingh97704@gmail.com>
Signed-off-by: g-k-s-03 <govindsingh97704@gmail.com>
Signed-off-by: g-k-s-03 <govindsingh97704@gmail.com>
Signed-off-by: g-k-s-03 <govindsingh97704@gmail.com>
…unters, defer mark_seen, cap buffer size

Signed-off-by: g-k-s-03 <govindsingh97704@gmail.com>
feat: implement P2P interception layer for peer misbehavior detection
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 15540d1b-5274-428a-b3de-a22f3ef7909b

📥 Commits

Reviewing files that changed from the base of the PR and between 569b728 and 9bf70b6.

📒 Files selected for processing (6)
  • main.py
  • minichain/chain.py
  • minichain/p2p.py
  • minichain/state.py
  • tests/test_difficulty.py
  • tests/test_persistence_runtime.py

Walkthrough

This PR propagates explicit ValidationStatus values through block/transaction processing in main.py, minichain/chain.py, and minichain/state.py (including new fee validation), adds configurable misbehavior tracking/thresholds and framing to minichain/p2p.py, and threads a datadir parameter through CLI/node persistence, with corresponding test updates.

Changes

ValidationStatus, fee validation, and datadir wiring

Layer / File(s) Summary
Fee validation and apply refactor
minichain/state.py
Adds non-negative integer fee validation to validate_and_apply, validate_and_apply_with_status, and apply_transaction, and introduces _apply_validated_tx to avoid redundant verification.
Reorg receipts consistency check
minichain/chain.py
Adds a receipts equality check during reorg block rebuild in resolve_conflicts, rejecting the reorg on mismatch.
Block/tx handler ValidationStatus propagation
main.py
Imports ValidationStatus, updates mining acceptance, tx/block network message handling, and linear chain catch-up to compare against explicit status values.
P2P misbehavior tracking and framing
minichain/p2p.py
Adds configurable malformed/failed/invalid thresholds, per-peer counters, decay task, policy enforcement (ban/disconnect), max-frame buffering, and safer command write/disconnect handling.
CLI/node datadir persistence wiring
main.py
Extends cli_loop with optional datadir, passes it to ban/unban/list-banned path arguments and P2PNetwork construction, and disconnects peers immediately on ban.
Test updates
tests/test_difficulty.py, tests/test_persistence_runtime.py
Updates assertions to check ValidationStatus.VALID and updates test doubles to accept **kwargs/optional datadir.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Peer
  participant NetworkHandler
  participant Mempool
  participant Chain
  participant P2PNetwork

  Peer->>NetworkHandler: tx message
  NetworkHandler->>Mempool: add_transaction(tx)
  Mempool-->>NetworkHandler: accepted/rejected
  NetworkHandler-->>P2PNetwork: ValidationStatus (VALID/INVALID/MALFORMED/FAILED)
  P2PNetwork->>P2PNetwork: _handle_validation_status(peer, status)
  alt threshold reached
    P2PNetwork->>Peer: ban + disconnect
  else within threshold
    P2PNetwork-->>Peer: no action
  end

  Peer->>NetworkHandler: block message
  NetworkHandler->>Chain: add_block(block)
  Chain-->>NetworkHandler: status
  NetworkHandler-->>P2PNetwork: status
Loading

Possibly related PRs

  • StabilityNexus/MiniChain#106: Both PRs align on switching Blockchain.add_block() acceptance checks to explicit ValidationStatus comparisons across mining, chain-response, and tests.
  • StabilityNexus/MiniChain#91: Both update fee validation and receipts-based checks in minichain/state.py and minichain/chain.py.
  • StabilityNexus/MiniChain#61: Both introduce/propagate an optional datadir through main.py node startup and CLI persistence wiring.

Suggested labels: Python Lang

Suggested reviewers: Zahnentferner

Poem

A rabbit hops through code so neat,
ValidationStatus makes bans complete,
Fees now checked, receipts compared,
Datadirs kept, no peer unspared,
Thump-thump goes my happy little feet! 🐇✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/peer-blacklisting

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@SIDDHANTCOOKIE SIDDHANTCOOKIE merged commit 4334478 into main Jul 3, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants