aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.cpp
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2022-03-28 17:29:20 +0200
committerMacroFake <falke.marco@gmail.com>2022-05-25 10:57:08 +0200
commitfa27ee88edbf696b7eef2efbfcf1446ec522fd85 (patch)
tree6e0246e5742576384c5dd34937d02bd104782f3e /src/addrman.cpp
parent8c721fff3a007db613b22464b40fe7cd6b1ead80 (diff)
downloadbitcoin-fa27ee88edbf696b7eef2efbfcf1446ec522fd85.tar.xz
Get time less often in AddrManImpl::ResolveCollisions_()
This makes the code less verbose. Also, future changes that change how to get the time are less verbose. Moreover, GetAdjustedTime() might arbitrarily change the value during the execution of this function. For example, the system time advances over a second boundary, or the network adjusts the time arbitrarily. Most of the time however the value will not change, so it seems better to always lock the value in this scope for clarity.
Diffstat (limited to 'src/addrman.cpp')
-rw-r--r--src/addrman.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f74729d47b..ed823eeb05 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -866,25 +866,27 @@ void AddrManImpl::ResolveCollisions_()
int id_old = vvTried[tried_bucket][tried_bucket_pos];
AddrInfo& info_old = mapInfo[id_old];
+ const auto current_time{GetAdjustedTime()};
+
// Has successfully connected in last X hours
- if (GetAdjustedTime() - info_old.nLastSuccess < ADDRMAN_REPLACEMENT_HOURS*(60*60)) {
+ if (current_time - info_old.nLastSuccess < ADDRMAN_REPLACEMENT_HOURS*(60*60)) {
erase_collision = true;
- } else if (GetAdjustedTime() - info_old.nLastTry < ADDRMAN_REPLACEMENT_HOURS*(60*60)) { // attempted to connect and failed in last X hours
+ } else if (current_time - info_old.nLastTry < ADDRMAN_REPLACEMENT_HOURS*(60*60)) { // attempted to connect and failed in last X hours
// Give address at least 60 seconds to successfully connect
- if (GetAdjustedTime() - info_old.nLastTry > 60) {
+ if (current_time - info_old.nLastTry > 60) {
LogPrint(BCLog::ADDRMAN, "Replacing %s with %s in tried table\n", info_old.ToString(), info_new.ToString());
// Replaces an existing address already in the tried table with the new address
- Good_(info_new, false, GetAdjustedTime());
+ Good_(info_new, false, current_time);
erase_collision = true;
}
- } else if (GetAdjustedTime() - info_new.nLastSuccess > ADDRMAN_TEST_WINDOW) {
+ } else if (current_time - info_new.nLastSuccess > ADDRMAN_TEST_WINDOW) {
// If the collision hasn't resolved in some reasonable amount of time,
// just evict the old entry -- we must not be able to
// connect to it for some reason.
LogPrint(BCLog::ADDRMAN, "Unable to test; replacing %s with %s in tried table anyway\n", info_old.ToString(), info_new.ToString());
- Good_(info_new, false, GetAdjustedTime());
+ Good_(info_new, false, current_time);
erase_collision = true;
}
} else { // Collision is not actually a collision anymore