Skip to content

Commit

Permalink
Merge bitcoin#25259: test: check pre-segwit peer error in `getblockfr…
Browse files Browse the repository at this point in the history
…ompeer` RPC

7d0f67a test: check pre-segwit peer error in `getblockfrompeer` RPC (Sebastian Falbesoner)

Pull request description:

  This PR adds missing test coverage for the `getblockfrompeer` RPC, in the case that a block is tried to be fetched from a pre-segwit peer (i.e. a peer that doesn't signal the service bit `NODE_WITNESS`):

  https://github.com/bitcoin/bitcoin/blob/d4d9daff7ab60a9f0cae0a34f86be0bb497f62f4/src/net_processing.cpp#L1564-L1565

ACKs for top commit:
  MarcoFalke:
    cr ACK 7d0f67a

Tree-SHA512: bc330820686fe45577e7a53d66e2a0b339ee3ca4ef348ba3cab0a78ed891e47b3651cadf3c6c3c35d1e9a95779df010322c12d37b36700e828f6064ae35842fd
  • Loading branch information
MacroFake authored and PastaPastaPasta committed Aug 14, 2024
1 parent 7e87d97 commit 275e53b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/functional/rpc_getblockfrompeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"""Test the getblockfrompeer RPC."""

from test_framework.authproxy import JSONRPCException
from test_framework.messages import NODE_WITNESS
from test_framework.p2p import (
P2P_SERVICES,
P2PInterface,
)
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
Expand Down Expand Up @@ -61,6 +66,13 @@ def run_test(self):
for peer_id in [-1, peer_0_peer_1_id + 1]:
assert_raises_rpc_error(-1, "Peer does not exist", self.nodes[0].getblockfrompeer, short_tip, peer_id)

self.log.info("Fetching from pre-segwit peer generates error")
self.nodes[0].add_p2p_connection(P2PInterface(), services=P2P_SERVICES & ~NODE_WITNESS)
peers = self.nodes[0].getpeerinfo()
assert_equal(len(peers), 2)
presegwit_peer_id = peers[1]["id"]
assert_raises_rpc_error(-1, "Pre-SegWit peer", self.nodes[0].getblockfrompeer, short_tip, presegwit_peer_id)

self.log.info("Successful fetch")
result = self.nodes[0].getblockfrompeer(short_tip, peer_0_peer_1_id)
self.wait_until(lambda: self.check_for_block(short_tip), timeout=1)
Expand All @@ -71,5 +83,6 @@ def run_test(self):
assert("warnings" in result)
assert_equal(result["warnings"], "Block already downloaded")


if __name__ == '__main__':
GetBlockFromPeerTest().main()

0 comments on commit 275e53b

Please sign in to comment.