test: fix intermittent failure in p2p_addr_selfannouncement
What changed, and why it matters
This is a one-line fix inside a single automated test file. The test was occasionally failing because the test's internal expected timestamp was being read after the simulated clock had already advanced, so the expected value could be slightly newer than the test anticipated. The fix simply records the expected time before advancing the simulated clock. It does not change any production code, network behavior, or wallet logic.
No security action required. This is a routine test reliability fix; review and merge as normal.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies test/functional/p2p_addr_selfannouncement.py. Previously the code bumped mocktime and then set addr_receiver.expected.time to the post-bump mocktime. Because the self-announcement may be emitted during bumpmocktime/sync, the captured expected time could be newer than the actual announcement timestamp, causing an intermittent assertion failure. The fix swaps the order: set expected.time to the current mocktime + 20 days, then bump mocktime by the same amount. This is purely a test synchronization correction.
Changed components
test/functional/p2p_addr_selfannouncement.pyInspect captured patch +1 / −1
diff --git a/test/functional/p2p_addr_selfannouncement.py b/test/functional/p2p_addr_selfannouncement.py
index 1fb91e0a..89e7a887 100755
--- a/test/functional/p2p_addr_selfannouncement.py
+++ b/test/functional/p2p_addr_selfannouncement.py
@@ -128,8 +128,8 @@ class AddrSelfAnnouncementTest(BitcoinTestFramework):
# self-announcements are sent on an exponential distribution with mean interval of 24h.
# Setting the mocktime 20d forward gives a probability of (1 - e^-(480/24)) that
# the event will occur (i.e. this fails once in ~500 million repeats).
+ addr_receiver.expected.time = self.nodes[0].mocktime + 20 * ONE_DAY
self.nodes[0].bumpmocktime(20 * ONE_DAY)
- addr_receiver.expected.time = self.nodes[0].mocktime
addr_receiver.sync_with_ping()
assert_equal(addr_receiver.self_announcements_received, last_self_announcements_received + 1)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.