Skip to content

Commit 074296d

Browse files
furszyfanquake
authored andcommitted
refactor: rename FirstKeyTimeChanged to MaybeUpdateBirthTime
In the following-up commit, the wallet birth time will also be modified by the transactions scanning process. When a tx older than all descriptor's timestamp is detected. Github-Pull: #28920 Rebased-From: b4306e3
1 parent 35039ac commit 074296d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/wallet/wallet.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,11 +1763,11 @@ bool CWallet::ImportScriptPubKeys(const std::string& label, const std::set<CScri
17631763
return true;
17641764
}
17651765

1766-
void CWallet::FirstKeyTimeChanged(const ScriptPubKeyMan* spkm, int64_t new_birth_time)
1766+
void CWallet::MaybeUpdateBirthTime(int64_t time)
17671767
{
17681768
int64_t birthtime = m_birth_time.load();
1769-
if (new_birth_time < birthtime) {
1770-
m_birth_time = new_birth_time;
1769+
if (time < birthtime) {
1770+
m_birth_time = time;
17711771
}
17721772
}
17731773

@@ -3494,10 +3494,12 @@ LegacyScriptPubKeyMan* CWallet::GetOrCreateLegacyScriptPubKeyMan()
34943494

34953495
void CWallet::AddScriptPubKeyMan(const uint256& id, std::unique_ptr<ScriptPubKeyMan> spkm_man)
34963496
{
3497+
// Add spkm_man to m_spk_managers before calling any method
3498+
// that might access it.
34973499
const auto& spkm = m_spk_managers[id] = std::move(spkm_man);
34983500

34993501
// Update birth time if needed
3500-
FirstKeyTimeChanged(spkm.get(), spkm->GetTimeFirstKey());
3502+
MaybeUpdateBirthTime(spkm->GetTimeFirstKey());
35013503
}
35023504

35033505
void CWallet::SetupLegacyScriptPubKeyMan()
@@ -3530,7 +3532,7 @@ void CWallet::ConnectScriptPubKeyManNotifiers()
35303532
for (const auto& spk_man : GetActiveScriptPubKeyMans()) {
35313533
spk_man->NotifyWatchonlyChanged.connect(NotifyWatchonlyChanged);
35323534
spk_man->NotifyCanGetAddressesChanged.connect(NotifyCanGetAddressesChanged);
3533-
spk_man->NotifyFirstKeyTimeChanged.connect(std::bind(&CWallet::FirstKeyTimeChanged, this, std::placeholders::_1, std::placeholders::_2));
3535+
spk_man->NotifyFirstKeyTimeChanged.connect(std::bind(&CWallet::MaybeUpdateBirthTime, this, std::placeholders::_2));
35343536
}
35353537
}
35363538

src/wallet/wallet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,8 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
678678
bool ImportPubKeys(const std::vector<CKeyID>& ordered_pubkeys, const std::map<CKeyID, CPubKey>& pubkey_map, const std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>>& key_origins, const bool add_keypool, const bool internal, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
679679
bool ImportScriptPubKeys(const std::string& label, const std::set<CScript>& script_pub_keys, const bool have_solving_data, const bool apply_label, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
680680

681-
/** Updates wallet birth time if 'new_birth_time' is below it */
682-
void FirstKeyTimeChanged(const ScriptPubKeyMan* spkm, int64_t new_birth_time);
681+
/** Updates wallet birth time if 'time' is below it */
682+
void MaybeUpdateBirthTime(int64_t time);
683683

684684
CFeeRate m_pay_tx_fee{DEFAULT_PAY_TX_FEE};
685685
unsigned int m_confirm_target{DEFAULT_TX_CONFIRM_TARGET};

0 commit comments

Comments
 (0)