Merge bitcoin/bitcoin#23644: wallet: Replace confusing getAdjustedTime() with GetTime()

fa37e798b2660d8e44e31c944a257b55aeef5de2 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 fa37e798b2660d8e44e31c944a257b55aeef5de2
  shaavan:
    crACK fa37e798b2660d8e44e31c944a257b55aeef5de2

Tree-SHA512: 8d020ba400521246b7aed4b6c41319fc70552e8c69e929a5994500375466a9edac02a0ae64b803dbc6695df22276489561a23bd6e030c44c97d288f7b9b2b3fa
This commit is contained in:
MarcoFalke 2021-12-07 09:01:59 +01:00 committed by PastaPastaPasta
parent b34db33a69
commit 7aea2e0955
4 changed files with 2 additions and 7 deletions

View File

@ -226,9 +226,6 @@ public:
//! Check if shutdown requested. //! Check if shutdown requested.
virtual bool shutdownRequested() = 0; virtual bool shutdownRequested() = 0;
//! Get adjusted time.
virtual int64_t getAdjustedTime() = 0;
//! Send init message. //! Send init message.
virtual void initMessage(const std::string& message) = 0; virtual void initMessage(const std::string& message) = 0;

View File

@ -785,7 +785,6 @@ public:
bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !::ChainstateActive().IsInitialBlockDownload(); } bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !::ChainstateActive().IsInitialBlockDownload(); }
bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); } bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); }
bool shutdownRequested() override { return ShutdownRequested(); } bool shutdownRequested() override { return ShutdownRequested(); }
int64_t getAdjustedTime() override { return GetAdjustedTime(); }
void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); } void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); }
void initWarning(const bilingual_str& message) override { InitWarning(message); } void initWarning(const bilingual_str& message) override { InitWarning(message); }
void initError(const bilingual_str& message) override { InitError(message); } void initError(const bilingual_str& message) override { InitError(message); }

View File

@ -183,7 +183,7 @@ static void WalletTxToJSON(interfaces::Chain& chain, const CWalletTx& wtx, UniVa
conflicts.push_back(conflict.GetHex()); conflicts.push_back(conflict.GetHex());
entry.pushKV("walletconflicts", conflicts); entry.pushKV("walletconflicts", conflicts);
entry.pushKV("time", wtx.GetTxTime()); entry.pushKV("time", wtx.GetTxTime());
entry.pushKV("timereceived", (int64_t)wtx.nTimeReceived); entry.pushKV("timereceived", int64_t{wtx.nTimeReceived});
for (const std::pair<const std::string, std::string>& item : wtx.mapValue) for (const std::pair<const std::string, std::string>& item : wtx.mapValue)
entry.pushKV(item.first, item.second); entry.pushKV(item.first, item.second);

View File

@ -864,7 +864,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
wtx.BindWallet(this); wtx.BindWallet(this);
bool fInsertedNew = ret.second; bool fInsertedNew = ret.second;
if (fInsertedNew) { if (fInsertedNew) {
wtx.nTimeReceived = chain().getAdjustedTime(); wtx.nTimeReceived = GetTime();
wtx.nOrderPos = IncOrderPosNext(&batch); wtx.nOrderPos = IncOrderPosNext(&batch);
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx)); wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx));
wtx.nTimeSmart = ComputeTimeSmart(wtx); wtx.nTimeSmart = ComputeTimeSmart(wtx);
@ -1277,7 +1277,6 @@ void CWallet::UpdatedBlockTip()
m_best_block_time = GetTime(); m_best_block_time = GetTime();
} }
void CWallet::BlockUntilSyncedToCurrentChain() const { void CWallet::BlockUntilSyncedToCurrentChain() const {
AssertLockNotHeld(cs_wallet); AssertLockNotHeld(cs_wallet);
// Skip the queue-draining stuff if we know we're caught up with // Skip the queue-draining stuff if we know we're caught up with