Skip to content

Commit 6c996c2

Browse files
committed
Add documentation describing CWallet::nTimeSmart.
Most of the text comes from the 2012 Luke Dashjr <[email protected]> c3f95ef commit message.
1 parent 1f98abe commit 6c996c2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/wallet/wallet.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,6 +3454,27 @@ void CWallet::GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) c
34543454
mapKeyBirth[it->first] = it->second->GetBlockTime() - 7200; // block times can be 2h off
34553455
}
34563456

3457+
/**
3458+
* Compute smart timestamp for a transaction being added to the wallet.
3459+
*
3460+
* Logic:
3461+
* - If sending a transaction, assign its timestamp to the current time.
3462+
* - If receiving a transaction outside a block, assign its timestamp to the
3463+
* current time.
3464+
* - If receiving a block with a future timestamp, assign all its (not already
3465+
* known) transactions' timestamps to the current time.
3466+
* - If receiving a block with a past timestamp, before the most recent known
3467+
* transaction (that we care about), assign all its (not already known)
3468+
* transactions' timestamps to the same timestamp as that most-recent-known
3469+
* transaction.
3470+
* - If receiving a block with a past timestamp, but after the most recent known
3471+
* transaction, assign all its (not already known) transactions' timestamps to
3472+
* the block time.
3473+
*
3474+
* For more information see CWalletTx::nTimeSmart,
3475+
* https://bitcointalk.org/?topic=54527, or
3476+
* https://github.com/bitcoin/bitcoin/pull/1393.
3477+
*/
34573478
unsigned int CWallet::ComputeTimeSmart(const CWalletTx& wtx) const
34583479
{
34593480
unsigned int nTimeSmart = wtx.nTimeReceived;

src/wallet/wallet.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ class CWalletTx : public CMerkleTx
260260
std::vector<std::pair<std::string, std::string> > vOrderForm;
261261
unsigned int fTimeReceivedIsTxTime;
262262
unsigned int nTimeReceived; //!< time received by this node
263+
/**
264+
* Stable timestamp that never changes, and reflects the order a transaction
265+
* was added to the wallet. Timestamp is based on the block time for a
266+
* transaction added as part of a block, or else the time when the
267+
* transaction was received if it wasn't part of a block, with the timestamp
268+
* adjusted in both cases so timestamp order matches the order transactions
269+
* were added to the wallet. More details can be found in
270+
* CWallet::ComputeTimeSmart().
271+
*/
263272
unsigned int nTimeSmart;
264273
/**
265274
* From me flag is set to 1 for transactions that were created by the wallet

0 commit comments

Comments
 (0)