Add P2P addr/addrv2 tests + oversized/spam message checks#897
Open
moisesPompilio wants to merge 6 commits intogetfloresta:masterfrom
Open
Add P2P addr/addrv2 tests + oversized/spam message checks#897moisesPompilio wants to merge 6 commits intogetfloresta:masterfrom
moisesPompilio wants to merge 6 commits intogetfloresta:masterfrom
Conversation
3aae2a5 to
3c64367
Compare
8c42d8c to
7a7e8ff
Compare
…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.
7a7e8ff to
fb04180
Compare
There was a problem hiding this comment.
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
p2psuite 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
SendAddrV2after handshake and (b) respond togetaddrwithaddrvsaddrv2based 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description and Notes
This PR introduces the
p2ptest suite to the integration tests for the Floresta project. The main enhancements include:p2p_addr_relay.pytest to verify the behavior of Floresta regarding the handling ofaddr,addrv2,sendaddr2, andgetaddrmessages. This includes the following fixes:sendaddrv2messages after the P2P handshake.addrmessages (instead ofaddrv2) to peers that do not signal support foraddrv2.p2p_oversized_msg.py).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:
./tests/run.sh -t p2p -k p2p_addr_relay.py: Run the P2P Address Relay test../tests/run.sh -t p2p -k p2p_oversized_msg.py: Run the P2P Oversized Message test../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.pyandp2p_spam_msg.pyrequire PR #880 to run properly.