Skip to content

Add P2P addr/addrv2 tests + oversized/spam message checks#897

Open
moisesPompilio wants to merge 6 commits intogetfloresta:masterfrom
moisesPompilio:add-test-p2p
Open

Add P2P addr/addrv2 tests + oversized/spam message checks#897
moisesPompilio wants to merge 6 commits intogetfloresta:masterfrom
moisesPompilio:add-test-p2p

Conversation

@moisesPompilio
Copy link
Copy Markdown
Collaborator

Description and Notes

This PR introduces the p2p test suite to the integration tests for the Floresta project. The main enhancements include:

  • Integration of Bitcoin Core's P2P Testing Framework: Added files that provide a P2P interface for communication between nodes. This allows testing scenarios such as sending unexpected messages and ensuring proper handling.
  • Address Relay Tests: Added the p2p_addr_relay.py test to verify the behavior of Floresta regarding the handling of addr, addrv2, sendaddr2, and getaddr messages. This includes the following fixes:
    • Corrected a bug where Floresta was accepting sendaddrv2 messages after the P2P handshake.
    • Updated the behavior of Floresta to send addr messages (instead of addrv2) to peers that do not signal support for addrv2.
  • Resilience Tests: Added tests for scenarios involving:
    • Oversized messages exceeding the node's permissible limits (p2p_oversized_msg.py).
    • Spam of unwanted or unexpected messages to stress test Floresta's resilience (p2p_spam_msg.py).

These resilience tests ensure robustness and address potential vulnerabilities. Note that the oversized/spam message tests depend on the changes in PR #880 to function correctly.

How to verify the changes you have done?

To verify the changes, execute the functional tests as follows:

  1. ./tests/run.sh -t p2p -k p2p_addr_relay.py: Run the P2P Address Relay test.
  2. ./tests/run.sh -t p2p -k p2p_oversized_msg.py: Run the P2P Oversized Message test.
  3. ./tests/run.sh -t p2p -k p2p_spam_msg.py: Run the P2P Spam Message test.

Ensure that all tests pass successfully and validate the scenarios introduced in this PR. Note that p2p_oversized_msg.py and p2p_spam_msg.py require PR #880 to run properly.

@moisesPompilio moisesPompilio requested review from Davidson-Souza, JoseSK999, jaoleal and qlrd and removed request for qlrd March 15, 2026 16:12
@moisesPompilio moisesPompilio self-assigned this Mar 15, 2026
@moisesPompilio moisesPompilio added chore Cleaning, refactoring, reducing complexity functional tests labels Mar 15, 2026
@moisesPompilio moisesPompilio force-pushed the add-test-p2p branch 4 times, most recently from 8c42d8c to 7a7e8ff Compare March 17, 2026 18:26
…in getblock/gettxout

Replaced manual waiting logic with the `wait_until` utility in the getblock and
gettxout tests. The `wait_until` function periodically evaluates a given predicate
and returns `True` when the condition is met. If the condition is not met within
the timeout, it raises an exception.
…dle GetAddr properly

Fixed the handling of SendAddrV2 messages received after the handshake. Peers that
send this message post-handshake are now disconnected, as this behavior is not
allowed.

Adjusted the response to GetAddr messages to conditionally send AddrV2 or Addr
based on the peer's support for AddrV2. If the peer does not support AddrV2, the
node will now send Addr instead.
…nection functions

Added a file from the Bitcoin Core project related to P2P testing. This includes
utilities for simulating P2P nodes and interacting with the P2P protocol in
integration tests.

Exposed functions to connect a node with the P2P interface, enabling the use of
a simulated node to send and receive P2P messages during functional tests.
Added a test suite for P2P address relay functionality in Floresta. The test verifies
that Floresta correctly handles address messages (addr and addrv2), enforces message
size limits, and responds appropriately to getaddr requests.

The suite also tests Floresta's tolerance to oversized messages and its behavior
when receiving sendaddrv2 messages after the handshake between nodes.
Add TestP2pOversizedMessages to verify Floresta correctly rejects and
disconnects peers sending messages exceeding MAX_PROTOCOL_MESSAGE_LENGTH.
Tests all message types across v1 and v2 P2P protocol versions.
Add TestP2pSpamMessages to verify Floresta correctly disconnects peers
that flood the node with excessive messages exceeding MAX_MSG_PER_SECOND.
Tests all message types across v1 and v2 P2P protocol versions.
@moisesPompilio moisesPompilio marked this pull request as ready for review April 10, 2026 21:10
Copilot AI review requested due to automatic review settings April 10, 2026 21:10
@moisesPompilio moisesPompilio added ecosystem support Enable interoperability, compatibility and practical integration with the broader Bitcoin ecosystem testing & validation and removed chore Cleaning, refactoring, reducing complexity functional tests labels Apr 10, 2026
@moisesPompilio moisesPompilio added this to the Q2/2026 milestone Apr 10, 2026
@github-project-automation github-project-automation bot moved this to Backlog in Floresta Apr 10, 2026
@moisesPompilio moisesPompilio moved this from Backlog to Needs review in Floresta Apr 10, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a Bitcoin Core-derived P2P testing framework to Floresta’s integration tests and introduces new P2P-focused functional tests, while also adjusting Floresta’s peer behavior for addr/addrv2 and SendAddrV2 handling.

Changes:

  • Add a P2P test framework layer (P2PConnection/P2PInterface, BIP324 v2 transport helpers, message/crypto primitives) and integrate a new p2p suite into the test runner.
  • Add functional tests covering addr/addrv2 relay semantics, oversized-message handling, and spam/rate-limit resilience.
  • Update Floresta peer logic to (a) reject SendAddrV2 after handshake and (b) respond to getaddr with addr vs addrv2 based on peer preference.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
tests/test_runner.py Adds the new p2p suite tests to the default runner and suite counting.
tests/test_framework/init.py Introduces P2P connection management helpers used by the new tests.
tests/test_framework/p2p.py Adds the (Bitcoin Core-derived) P2P connection/interface implementation used by tests.
tests/test_framework/v2_p2p.py Adds BIP324 (v2) handshake + packet encryption/decryption helpers.
tests/test_framework/messages.py Adds Bitcoin P2P message/primitive definitions used by the P2P framework and tests.
tests/test_framework/netutil.py Adds networking utilities needed by the P2P framework (ports/interfaces).
tests/test_framework/util.py Adds wait-until helpers reused across tests/framework.
tests/test_framework/rpc/base.py Makes disconnectnode easier to call with node_id-only usage.
tests/test_framework/node.py Adds connect_node_by_url used by P2P connection helpers.
tests/test_framework/key.py Fixes crypto import path to use package-relative imports.
tests/test_framework/crypto/siphash.py Adds SipHash implementation required by message primitives.
tests/test_framework/crypto/poly1305.py Adds Poly1305 implementation used for BIP324 AEAD in tests.
tests/test_framework/crypto/hkdf.py Adds HKDF-SHA256 used for BIP324 key derivation in tests.
tests/test_framework/crypto/ellswift.py Adds ElligatorSwift helpers for BIP324 handshake in tests.
tests/test_framework/crypto/chacha20.py Adds ChaCha20 + FSChaCha20 used in BIP324 transport tests.
tests/test_framework/crypto/bip324_cipher.py Adds ChaCha20-Poly1305 + FSChaCha20Poly1305 used by v2 transport.
tests/p2p/p2p_addr_relay.py Adds functional test for addr/addrv2/getaddr behavior and SendAddrV2 post-handshake rejection.
tests/p2p/p2p_oversized_msg.py Adds functional test for oversized P2P message disconnect behavior.
tests/p2p/p2p_spam_msg.py Adds functional test for message-spam/rate-limit disconnect behavior.
tests/floresta-cli/gettxout.py Refactors sync wait loop to use the new wait_until helper.
tests/floresta-cli/getblock.py Refactors sync wait loop to use the new wait_until helper.
crates/floresta-wire/src/p2p_wire/peer.rs Updates peer behavior for GetAddr response type and rejects SendAddrV2 after handshake.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ecosystem support Enable interoperability, compatibility and practical integration with the broader Bitcoin ecosystem testing & validation

Projects

Status: Needs review

Development

Successfully merging this pull request may close these issues.

2 participants