Skip to content

Commit 75fbf44

Browse files
committed
wallet: birth time update during tx scanning
As the user could have imported a descriptor with a newer timestamp (by blindly setting 'timestamp=now'), the wallet needs to update the birth time when it detects a transaction older than the oldest descriptor timestamp.
1 parent b4306e3 commit 75fbf44

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,9 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
10801080
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx));
10811081
wtx.nTimeSmart = ComputeTimeSmart(wtx, rescanning_old_block);
10821082
AddToSpends(wtx, &batch);
1083+
1084+
// Update birth time when tx time is older than it.
1085+
MaybeUpdateBirthTime(wtx.GetTxTime());
10831086
}
10841087

10851088
if (!fInsertedNew)
@@ -1199,6 +1202,10 @@ bool CWallet::LoadToWallet(const uint256& hash, const UpdateWalletTxFn& fill_wtx
11991202
}
12001203
}
12011204
}
1205+
1206+
// Update birth time when tx time is older than it.
1207+
MaybeUpdateBirthTime(wtx.GetTxTime());
1208+
12021209
return true;
12031210
}
12041211

@@ -3087,7 +3094,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
30873094
int64_t time = spk_man->GetTimeFirstKey();
30883095
if (!time_first_key || time < *time_first_key) time_first_key = time;
30893096
}
3090-
if (time_first_key) walletInstance->m_birth_time = *time_first_key;
3097+
if (time_first_key) walletInstance->MaybeUpdateBirthTime(*time_first_key);
30913098

30923099
if (chain && !AttachChain(walletInstance, *chain, rescan_required, error, warnings)) {
30933100
return nullptr;

0 commit comments

Comments
 (0)