Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/rpc/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,9 @@ static RPCHelpMan setmocktime()
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime cannot be negative: %s.", time));
}
SetMockTime(time);
if (auto* node_context = GetContext<NodeContext>(request.context)) {
for (const auto& chain_client : node_context->chain_clients) {
chain_client->setMockTime(time);
}
const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
for (const auto& chain_client : node_context.chain_clients) {
chain_client->setMockTime(time);
}

return UniValue::VNULL;
Expand Down Expand Up @@ -842,10 +841,9 @@ static RPCHelpMan mockscheduler()
throw std::runtime_error("delta_time must be between 1 and 3600 seconds (1 hr)");
}

auto* node_context = CHECK_NONFATAL(GetContext<NodeContext>(request.context));
// protect against null pointer dereference
CHECK_NONFATAL(node_context->scheduler);
node_context->scheduler->MockForward(std::chrono::seconds(delta_seconds));
const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
CHECK_NONFATAL(node_context.scheduler)->MockForward(std::chrono::seconds{delta_seconds});
SyncWithValidationInterfaceQueue();

return UniValue::VNULL;
},
Expand Down
9 changes: 2 additions & 7 deletions test/functional/p2p_getaddr_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test addr response caching"""

from test_framework.messages import msg_getaddr
from test_framework.p2p import (
P2PInterface,
p2p_lock
Expand All @@ -19,6 +18,7 @@
MAX_ADDR_TO_SEND = 1000
MAX_PCT_ADDR_TO_SEND = 23


class AddrReceiver(P2PInterface):

def __init__(self):
Expand Down Expand Up @@ -68,11 +68,8 @@ def run_test(self):
cur_mock_time = self.mocktime
for i in range(N):
addr_receiver_local = self.nodes[0].add_p2p_connection(AddrReceiver())
addr_receiver_local.send_and_ping(msg_getaddr())
addr_receiver_onion1 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port1)
addr_receiver_onion1.send_and_ping(msg_getaddr())
addr_receiver_onion2 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port2)
addr_receiver_onion2.send_and_ping(msg_getaddr())

# Trigger response
cur_mock_time += 5 * 60
Expand Down Expand Up @@ -103,11 +100,8 @@ def run_test(self):

self.log.info('After time passed, see a new response to addr request')
addr_receiver_local = self.nodes[0].add_p2p_connection(AddrReceiver())
addr_receiver_local.send_and_ping(msg_getaddr())
addr_receiver_onion1 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port1)
addr_receiver_onion1.send_and_ping(msg_getaddr())
addr_receiver_onion2 = self.nodes[0].add_p2p_connection(AddrReceiver(), dstport=self.onion_port2)
addr_receiver_onion2.send_and_ping(msg_getaddr())

# Trigger response
cur_mock_time += 5 * 60
Expand All @@ -121,5 +115,6 @@ def run_test(self):
assert(set(last_response_on_onion_bind1) != set(addr_receiver_onion1.get_received_addrs()))
assert(set(last_response_on_onion_bind2) != set(addr_receiver_onion2.get_received_addrs()))


if __name__ == '__main__':
AddrTest().main()
5 changes: 3 additions & 2 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,11 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, send_version=Tru
p2p_conn.sync_with_ping()

# Consistency check that the node received our user agent string.
# Find our connection in getpeerinfo by our address:port, as it is unique.
# Find our connection in getpeerinfo by our address:port and theirs, as this combination is unique.
sockname = p2p_conn._transport.get_extra_info("socket").getsockname()
our_addr_and_port = f"{sockname[0]}:{sockname[1]}"
info = [peer for peer in self.getpeerinfo() if peer["addr"] == our_addr_and_port]
dst_addr_and_port = f"{p2p_conn.dstaddr}:{p2p_conn.dstport}"
info = [peer for peer in self.getpeerinfo() if peer["addr"] == our_addr_and_port and peer["addrbind"] == dst_addr_and_port]
assert_equal(len(info), 1)
assert_equal(info[0]["subver"], p2p_conn.strSubVer)

Expand Down
Loading