Skip to content

Commit 6f49737

Browse files
committed
wallet: fix legacy spkm default birth time
To avoid scanning blocks, as assumed by a wallet with no generated keys or imported scripts, the default value for the birth time needs to be set to the maximum int64_t value. Once the first key is generated or the first script is imported, the legacy SPKM will update the birth time automatically.
1 parent 75fbf44 commit 6f49737

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ void LegacyScriptPubKeyMan::UpdateTimeFirstKey(int64_t nCreateTime)
709709
// Cannot determine birthday information, so set the wallet birthday to
710710
// the beginning of time.
711711
nTimeFirstKey = 1;
712-
} else if (!nTimeFirstKey || nCreateTime < nTimeFirstKey) {
712+
} else if (nTimeFirstKey == UNKNOWN_TIME || nCreateTime < nTimeFirstKey) {
713713
nTimeFirstKey = nCreateTime;
714714
}
715715

src/wallet/scriptpubkeyman.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class WalletStorage
5151
virtual bool IsLocked() const = 0;
5252
};
5353

54+
//! Constant representing an unknown spkm creation time
55+
static constexpr int64_t UNKNOWN_TIME = std::numeric_limits<int64_t>::max();
56+
5457
//! Default for -keypool
5558
static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000;
5659

@@ -286,7 +289,8 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
286289
WatchOnlySet setWatchOnly GUARDED_BY(cs_KeyStore);
287290
WatchKeyMap mapWatchKeys GUARDED_BY(cs_KeyStore);
288291

289-
int64_t nTimeFirstKey GUARDED_BY(cs_KeyStore) = 0;
292+
// By default, do not scan any block until keys/scripts are generated/imported
293+
int64_t nTimeFirstKey GUARDED_BY(cs_KeyStore) = UNKNOWN_TIME;
290294

291295
//! Number of pre-generated keys/scripts (part of the look-ahead process, used to detect payments)
292296
int64_t m_keypool_size GUARDED_BY(cs_KeyStore){DEFAULT_KEYPOOL_SIZE};

0 commit comments

Comments
 (0)