Skip to content

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

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

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.

…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.
@moisesPompilio moisesPompilio force-pushed the add-test-p2p branch 3 times, most recently from cb4c249 to 8c42d8c Compare March 17, 2026 18:06
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Cleaning, refactoring, reducing complexity functional tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant