Skip to content

Commit 1221f45

Browse files
laanwjPastaPastaPasta
authored andcommitted
Merge bitcoin#25314: p2p: always set nTime for self-advertisements
99b9e5f p2p: always set nTime for self-advertisements (Martin Zumsande) Pull request description: This logic was recently changed in bitcoin@0cfc0cd to overwrite `addrLocal` with the address they gave us when self-advertising to an inbound peer. But if we don't also change `nTime` again from the default `TIME_INIT`, our peer will not relay our advertised address any further. ACKs for top commit: naumenkogs: ACK 99b9e5f laanwj: Code review ACK 99b9e5f vasild: ACK 99b9e5f Tree-SHA512: 4c7ea51cc77ddaa4b3537962ad2ad085f7ef5322982d3b1f5baecb852719eb99dd578436ca63432cb6b0a4fbd8b59fca793caf326c4663a4d6f34301e8146aa2
1 parent c2b3f4b commit 1221f45

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/net.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ std::optional<CAddress> GetLocalAddrForPeer(CNode *pnode)
273273
if (pnode->IsInboundConn()) {
274274
// For inbound connections, assume both the address and the port
275275
// as seen from the peer.
276-
addrLocal = CAddress{pnode->GetAddrLocal(), addrLocal.nServices};
276+
addrLocal = CAddress{pnode->GetAddrLocal(), addrLocal.nServices, addrLocal.nTime};
277277
} else {
278278
// For outbound connections, assume just the address as seen from
279279
// the peer and leave the port in `addrLocal` as returned by

src/test/net_tests.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,13 @@ BOOST_AUTO_TEST_CASE(get_local_addr_for_peer_port)
676676
const uint16_t bind_port = 20001;
677677
m_node.args->ForceSetArg("-bind", strprintf("3.4.5.6:%u", bind_port));
678678

679+
const uint32_t current_time = static_cast<uint32_t>(GetAdjustedTime());
680+
SetMockTime(current_time);
681+
679682
// Our address:port as seen from the peer, completely different from the above.
680683
in_addr peer_us_addr;
681684
peer_us_addr.s_addr = htonl(0x02030405);
682-
const CAddress peer_us{CService{peer_us_addr, 20002}, NODE_NETWORK};
685+
const CAddress peer_us{CService{peer_us_addr, 20002}, NODE_NETWORK, current_time};
683686

684687
// Create a peer with a routable IPv4 address (outbound).
685688
in_addr peer_out_in_addr;
@@ -700,7 +703,7 @@ BOOST_AUTO_TEST_CASE(get_local_addr_for_peer_port)
700703
// Without the fix peer_us:8333 is chosen instead of the proper peer_us:bind_port.
701704
auto chosen_local_addr = GetLocalAddrForPeer(&peer_out);
702705
BOOST_REQUIRE(chosen_local_addr);
703-
const CService expected{peer_us_addr, bind_port};
706+
const CAddress expected{CService{peer_us_addr, bind_port}, NODE_NETWORK, current_time};
704707
BOOST_CHECK(*chosen_local_addr == expected);
705708

706709
// Create a peer with a routable IPv4 address (inbound).

0 commit comments

Comments
 (0)