Skip to content

Commit 42b2502

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23644: wallet: Replace confusing getAdjustedTime() with GetTime()
fa37e79 wallet: Replace confusing getAdjustedTime() with GetTime() (MarcoFalke) Pull request description: Setting `nTimeReceived` to the adjusted time has several issues: * `m_best_block_time` is set to the "unadjusted" time, thus a comparison of the two times is like comparing apples to oranges. In the worst case this opens up an attack vector where remote peers can force a premature re-broadcast of wallet txs. * The RPC documentation for `"timereceived"` doesn't mention that the network adjusted time is used, possibly confusing users when the time reported by RPC is off by a few seconds compared to their local timestamp. Fix all issues by replacing the call with `GetTime()`. Also a style fix: Use non-narrowing integer conversion in the RPC method. ACKs for top commit: theStack: Code-review ACK fa37e79 shaavan: crACK fa37e79 Tree-SHA512: 8d020ba400521246b7aed4b6c41319fc70552e8c69e929a5994500375466a9edac02a0ae64b803dbc6695df22276489561a23bd6e030c44c97d288f7b9b2b3fa
2 parents 08dcc59 + fa37e79 commit 42b2502

File tree

4 files changed

+2
-7
lines changed

4 files changed

+2
-7
lines changed

src/interfaces/chain.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,6 @@ class Chain
217217
//! Check if shutdown requested.
218218
virtual bool shutdownRequested() = 0;
219219

220-
//! Get adjusted time.
221-
virtual int64_t getAdjustedTime() = 0;
222-
223220
//! Send init message.
224221
virtual void initMessage(const std::string& message) = 0;
225222

src/node/interfaces.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,6 @@ class ChainImpl : public Chain
656656
return chainman().ActiveChainstate().IsInitialBlockDownload();
657657
}
658658
bool shutdownRequested() override { return ShutdownRequested(); }
659-
int64_t getAdjustedTime() override { return GetAdjustedTime(); }
660659
void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); }
661660
void initWarning(const bilingual_str& message) override { InitWarning(message); }
662661
void initError(const bilingual_str& message) override { InitError(message); }

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void WalletTxToJSON(const CWallet& wallet, const CWalletTx& wtx, UniValue
8181
conflicts.push_back(conflict.GetHex());
8282
entry.pushKV("walletconflicts", conflicts);
8383
entry.pushKV("time", wtx.GetTxTime());
84-
entry.pushKV("timereceived", (int64_t)wtx.nTimeReceived);
84+
entry.pushKV("timereceived", int64_t{wtx.nTimeReceived});
8585

8686
// Add opt-in RBF status
8787
std::string rbfStatus = "no";

src/wallet/wallet.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
915915
bool fInsertedNew = ret.second;
916916
bool fUpdated = update_wtx && update_wtx(wtx, fInsertedNew);
917917
if (fInsertedNew) {
918-
wtx.nTimeReceived = chain().getAdjustedTime();
918+
wtx.nTimeReceived = GetTime();
919919
wtx.nOrderPos = IncOrderPosNext(&batch);
920920
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx));
921921
wtx.nTimeSmart = ComputeTimeSmart(wtx, rescanning_old_block);
@@ -1303,7 +1303,6 @@ void CWallet::updatedBlockTip()
13031303
m_best_block_time = GetTime();
13041304
}
13051305

1306-
13071306
void CWallet::BlockUntilSyncedToCurrentChain() const {
13081307
AssertLockNotHeld(cs_wallet);
13091308
// Skip the queue-draining stuff if we know we're caught up with

0 commit comments

Comments
 (0)