Skip to content

Commit b4306e3

Browse files
committed
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.
1 parent d752349 commit b4306e3

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
@@ -1747,11 +1747,11 @@ bool CWallet::ImportScriptPubKeys(const std::string& label, const std::set<CScri
17471747
return true;
17481748
}
17491749

1750-
void CWallet::FirstKeyTimeChanged(const ScriptPubKeyMan* spkm, int64_t new_birth_time)
1750+
void CWallet::MaybeUpdateBirthTime(int64_t time)
17511751
{
17521752
int64_t birthtime = m_birth_time.load();
1753-
if (new_birth_time < birthtime) {
1754-
m_birth_time = new_birth_time;
1753+
if (time < birthtime) {
1754+
m_birth_time = time;
17551755
}
17561756
}
17571757

@@ -3480,10 +3480,12 @@ LegacyScriptPubKeyMan* CWallet::GetOrCreateLegacyScriptPubKeyMan()
34803480

34813481
void CWallet::AddScriptPubKeyMan(const uint256& id, std::unique_ptr<ScriptPubKeyMan> spkm_man)
34823482
{
3483+
// Add spkm_man to m_spk_managers before calling any method
3484+
// that might access it.
34833485
const auto& spkm = m_spk_managers[id] = std::move(spkm_man);
34843486

34853487
// Update birth time if needed
3486-
FirstKeyTimeChanged(spkm.get(), spkm->GetTimeFirstKey());
3488+
MaybeUpdateBirthTime(spkm->GetTimeFirstKey());
34873489
}
34883490

34893491
void CWallet::SetupLegacyScriptPubKeyMan()
@@ -3516,7 +3518,7 @@ void CWallet::ConnectScriptPubKeyManNotifiers()
35163518
for (const auto& spk_man : GetActiveScriptPubKeyMans()) {
35173519
spk_man->NotifyWatchonlyChanged.connect(NotifyWatchonlyChanged);
35183520
spk_man->NotifyCanGetAddressesChanged.connect(NotifyCanGetAddressesChanged);
3519-
spk_man->NotifyFirstKeyTimeChanged.connect(std::bind(&CWallet::FirstKeyTimeChanged, this, std::placeholders::_1, std::placeholders::_2));
3521+
spk_man->NotifyFirstKeyTimeChanged.connect(std::bind(&CWallet::MaybeUpdateBirthTime, this, std::placeholders::_2));
35203522
}
35213523
}
35223524

src/wallet/wallet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,8 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
685685
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);
686686
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);
687687

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

691691
CFeeRate m_pay_tx_fee{DEFAULT_PAY_TX_FEE};
692692
unsigned int m_confirm_target{DEFAULT_TX_CONFIRM_TARGET};

0 commit comments

Comments
 (0)