Skip to content

Commit ed79e4f

Browse files
committed
Optimize GetOldestKeyPoolTime(), return as soon as we have both oldest keys
1 parent 771a304 commit ed79e4f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/wallet/wallet.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,12 +3069,18 @@ int64_t CWallet::GetOldestKeyPoolTime()
30693069

30703070
for(const int64_t& id : setKeyPool)
30713071
{
3072-
if (!walletdb.ReadPool(id, keypool))
3072+
if (!walletdb.ReadPool(id, keypool)) {
30733073
throw std::runtime_error(std::string(__func__) + ": read failed");
3074-
if (keypool.fInternal && keypool.nTime < oldest_internal)
3074+
}
3075+
if (keypool.fInternal && keypool.nTime < oldest_internal) {
30753076
oldest_internal = keypool.nTime;
3076-
else if (!keypool.fInternal && keypool.nTime < oldest_external)
3077+
}
3078+
else if (!keypool.fInternal && keypool.nTime < oldest_external) {
30773079
oldest_external = keypool.nTime;
3080+
}
3081+
if (oldest_internal != now && oldest_external != now) {
3082+
break;
3083+
}
30783084
}
30793085
return std::max(oldest_internal, oldest_external);
30803086
}

0 commit comments

Comments
 (0)