Skip to content

Commit 152b0a0

Browse files
committed
Refactor: Move nTimeFirstKey accesses out of CWallet
This commit does not change behavior.
1 parent 7ef47b8 commit 152b0a0

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,12 @@ unsigned int LegacyScriptPubKeyMan::GetKeyPoolSize() const
470470
return setInternalKeyPool.size() + setExternalKeyPool.size();
471471
}
472472

473+
int64_t LegacyScriptPubKeyMan::GetTimeFirstKey() const
474+
{
475+
AssertLockHeld(cs_wallet);
476+
return nTimeFirstKey;
477+
}
478+
473479
const CKeyMetadata* LegacyScriptPubKeyMan::GetMetadata(uint160 id) const
474480
{
475481
AssertLockHeld(cs_wallet);

src/wallet/scriptpubkeyman.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ class ScriptPubKeyMan
184184
virtual size_t KeypoolCountExternalKeys() { return 0; }
185185
virtual unsigned int GetKeyPoolSize() const { return 0; }
186186

187+
virtual int64_t GetTimeFirstKey() const { return 0; }
188+
187189
virtual const CKeyMetadata* GetMetadata(uint160 id) const { return nullptr; }
188190
};
189191

@@ -298,6 +300,8 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
298300
size_t KeypoolCountExternalKeys() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
299301
unsigned int GetKeyPoolSize() const override;
300302

303+
int64_t GetTimeFirstKey() const override;
304+
301305
const CKeyMetadata* GetMetadata(uint160 id) const override;
302306

303307
bool CanGetAddresses(bool internal = false) override;

src/wallet/wallet.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3804,8 +3804,13 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
38043804

38053805
// No need to read and scan block if block was created before
38063806
// our wallet birthday (as adjusted for block time variability)
3807-
if (walletInstance->nTimeFirstKey) {
3808-
if (Optional<int> first_block = locked_chain->findFirstBlockWithTimeAndHeight(walletInstance->nTimeFirstKey - TIMESTAMP_WINDOW, rescan_height, nullptr)) {
3807+
Optional<int64_t> time_first_key;
3808+
if (auto spk_man = walletInstance->m_spk_man.get()) {
3809+
int64_t time = spk_man->GetTimeFirstKey();
3810+
if (!time_first_key || time < *time_first_key) time_first_key = time;
3811+
}
3812+
if (time_first_key) {
3813+
if (Optional<int> first_block = locked_chain->findFirstBlockWithTimeAndHeight(*time_first_key - TIMESTAMP_WINDOW, rescan_height, nullptr)) {
38093814
rescan_height = *first_block;
38103815
}
38113816
}

src/wallet/wallet.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,6 @@ class CWallet final : public WalletStorage, private interfaces::Chain::Notificat
11271127
LegacyScriptPubKeyMan::WatchOnlySet& setWatchOnly GUARDED_BY(cs_KeyStore) = m_spk_man->setWatchOnly;
11281128
LegacyScriptPubKeyMan::WatchKeyMap& mapWatchKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapWatchKeys;
11291129
WalletBatch*& encrypted_batch GUARDED_BY(cs_wallet) = m_spk_man->encrypted_batch;
1130-
int64_t& nTimeFirstKey GUARDED_BY(cs_wallet) = m_spk_man->nTimeFirstKey;
11311130
using CryptedKeyMap = LegacyScriptPubKeyMan::CryptedKeyMap;
11321131
};
11331132

0 commit comments

Comments
 (0)