mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-15 11:36:00 -05:00
txmempool: Make entry time type-safe (std::chrono)
This commit is contained in:
parent
faaa1f01da
commit
faec689bed
6 changed files with 16 additions and 15 deletions
|
@ -761,7 +761,7 @@ public:
|
||||||
// Used for BIP35 mempool sending
|
// Used for BIP35 mempool sending
|
||||||
bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
|
bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
|
||||||
// Last time a "MEMPOOL" request was serviced.
|
// Last time a "MEMPOOL" request was serviced.
|
||||||
std::atomic<int64_t> timeLastMempoolReq{0};
|
std::atomic<std::chrono::seconds> m_last_mempool_req{std::chrono::seconds{0}};
|
||||||
int64_t nNextInvSend{0};
|
int64_t nNextInvSend{0};
|
||||||
|
|
||||||
CCriticalSection cs_feeFilter;
|
CCriticalSection cs_feeFilter;
|
||||||
|
|
|
@ -1541,11 +1541,11 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
|
||||||
if (mi != mapRelay.end()) {
|
if (mi != mapRelay.end()) {
|
||||||
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *mi->second));
|
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *mi->second));
|
||||||
push = true;
|
push = true;
|
||||||
} else if (pfrom->m_tx_relay->timeLastMempoolReq) {
|
} else if (pfrom->m_tx_relay->m_last_mempool_req.load().count()) {
|
||||||
auto txinfo = mempool.info(inv.hash);
|
auto txinfo = mempool.info(inv.hash);
|
||||||
// To protect privacy, do not answer getdata using the mempool when
|
// To protect privacy, do not answer getdata using the mempool when
|
||||||
// that TX couldn't have been INVed in reply to a MEMPOOL request.
|
// that TX couldn't have been INVed in reply to a MEMPOOL request.
|
||||||
if (txinfo.tx && txinfo.nTime <= pfrom->m_tx_relay->timeLastMempoolReq) {
|
if (txinfo.tx && txinfo.m_time <= pfrom->m_tx_relay->m_last_mempool_req.load()) {
|
||||||
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *txinfo.tx));
|
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *txinfo.tx));
|
||||||
push = true;
|
push = true;
|
||||||
}
|
}
|
||||||
|
@ -3873,7 +3873,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
vInv.clear();
|
vInv.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pto->m_tx_relay->timeLastMempoolReq = GetTime();
|
pto->m_tx_relay->m_last_mempool_req = GetTime<std::chrono::seconds>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine transactions to relay
|
// Determine transactions to relay
|
||||||
|
|
|
@ -418,7 +418,7 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
|
||||||
info.pushKV("weight", (int)e.GetTxWeight());
|
info.pushKV("weight", (int)e.GetTxWeight());
|
||||||
info.pushKV("fee", ValueFromAmount(e.GetFee()));
|
info.pushKV("fee", ValueFromAmount(e.GetFee()));
|
||||||
info.pushKV("modifiedfee", ValueFromAmount(e.GetModifiedFee()));
|
info.pushKV("modifiedfee", ValueFromAmount(e.GetModifiedFee()));
|
||||||
info.pushKV("time", e.GetTime());
|
info.pushKV("time", count_seconds(e.GetTime()));
|
||||||
info.pushKV("height", (int)e.GetHeight());
|
info.pushKV("height", (int)e.GetHeight());
|
||||||
info.pushKV("descendantcount", e.GetCountWithDescendants());
|
info.pushKV("descendantcount", e.GetCountWithDescendants());
|
||||||
info.pushKV("descendantsize", e.GetSizeWithDescendants());
|
info.pushKV("descendantsize", e.GetSizeWithDescendants());
|
||||||
|
|
|
@ -917,7 +917,8 @@ void CTxMemPool::RemoveStaged(setEntries &stage, bool updateDescendants, MemPool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CTxMemPool::Expire(int64_t time) {
|
int CTxMemPool::Expire(std::chrono::seconds time)
|
||||||
|
{
|
||||||
AssertLockHeld(cs);
|
AssertLockHeld(cs);
|
||||||
indexed_transaction_set::index<entry_time>::type::iterator it = mapTx.get<entry_time>().begin();
|
indexed_transaction_set::index<entry_time>::type::iterator it = mapTx.get<entry_time>().begin();
|
||||||
setEntries toremove;
|
setEntries toremove;
|
||||||
|
|
|
@ -102,7 +102,7 @@ public:
|
||||||
const CAmount& GetFee() const { return nFee; }
|
const CAmount& GetFee() const { return nFee; }
|
||||||
size_t GetTxSize() const;
|
size_t GetTxSize() const;
|
||||||
size_t GetTxWeight() const { return nTxWeight; }
|
size_t GetTxWeight() const { return nTxWeight; }
|
||||||
int64_t GetTime() const { return nTime; }
|
std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
|
||||||
unsigned int GetHeight() const { return entryHeight; }
|
unsigned int GetHeight() const { return entryHeight; }
|
||||||
int64_t GetSigOpCost() const { return sigOpCost; }
|
int64_t GetSigOpCost() const { return sigOpCost; }
|
||||||
int64_t GetModifiedFee() const { return nFee + feeDelta; }
|
int64_t GetModifiedFee() const { return nFee + feeDelta; }
|
||||||
|
@ -332,7 +332,7 @@ struct TxMempoolInfo
|
||||||
CTransactionRef tx;
|
CTransactionRef tx;
|
||||||
|
|
||||||
/** Time the transaction entered the mempool. */
|
/** Time the transaction entered the mempool. */
|
||||||
int64_t nTime;
|
std::chrono::seconds m_time;
|
||||||
|
|
||||||
/** Feerate of the transaction. */
|
/** Feerate of the transaction. */
|
||||||
CFeeRate feeRate;
|
CFeeRate feeRate;
|
||||||
|
@ -657,7 +657,7 @@ public:
|
||||||
void TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
void TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
|
||||||
/** Expire all transaction (and their dependencies) in the mempool older than time. Return the number of removed transactions. */
|
/** Expire all transaction (and their dependencies) in the mempool older than time. Return the number of removed transactions. */
|
||||||
int Expire(int64_t time) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
int Expire(std::chrono::seconds time) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the ancestor and descendant count for the given transaction.
|
* Calculate the ancestor and descendant count for the given transaction.
|
||||||
|
|
|
@ -314,10 +314,10 @@ bool CheckSequenceLocks(const CTxMemPool& pool, const CTransaction& tx, int flag
|
||||||
// Returns the script flags which should be checked for a given block
|
// Returns the script flags which should be checked for a given block
|
||||||
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& chainparams);
|
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& chainparams);
|
||||||
|
|
||||||
static void LimitMempoolSize(CTxMemPool& pool, size_t limit, unsigned long age)
|
static void LimitMempoolSize(CTxMemPool& pool, size_t limit, std::chrono::seconds age)
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(pool.cs, ::cs_main)
|
EXCLUSIVE_LOCKS_REQUIRED(pool.cs, ::cs_main)
|
||||||
{
|
{
|
||||||
int expired = pool.Expire(GetTime() - age);
|
int expired = pool.Expire(GetTime<std::chrono::seconds>() - age);
|
||||||
if (expired != 0) {
|
if (expired != 0) {
|
||||||
LogPrint(BCLog::MEMPOOL, "Expired %i transactions from the memory pool\n", expired);
|
LogPrint(BCLog::MEMPOOL, "Expired %i transactions from the memory pool\n", expired);
|
||||||
}
|
}
|
||||||
|
@ -389,7 +389,7 @@ static void UpdateMempoolForReorg(DisconnectedBlockTransactions& disconnectpool,
|
||||||
// We also need to remove any now-immature transactions
|
// We also need to remove any now-immature transactions
|
||||||
mempool.removeForReorg(&::ChainstateActive().CoinsTip(), ::ChainActive().Tip()->nHeight + 1, STANDARD_LOCKTIME_VERIFY_FLAGS);
|
mempool.removeForReorg(&::ChainstateActive().CoinsTip(), ::ChainActive().Tip()->nHeight + 1, STANDARD_LOCKTIME_VERIFY_FLAGS);
|
||||||
// Re-limit mempool size, in case we added any transactions
|
// Re-limit mempool size, in case we added any transactions
|
||||||
LimitMempoolSize(mempool, gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60);
|
LimitMempoolSize(mempool, gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, std::chrono::hours{gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to avoid mempool polluting consensus critical paths if CCoinsViewMempool
|
// Used to avoid mempool polluting consensus critical paths if CCoinsViewMempool
|
||||||
|
@ -1011,7 +1011,7 @@ bool MemPoolAccept::Finalize(ATMPArgs& args, Workspace& ws)
|
||||||
|
|
||||||
// trim mempool and check if tx was trimmed
|
// trim mempool and check if tx was trimmed
|
||||||
if (!bypass_limits) {
|
if (!bypass_limits) {
|
||||||
LimitMempoolSize(m_pool, gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60);
|
LimitMempoolSize(m_pool, gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, std::chrono::hours{gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
|
||||||
if (!m_pool.exists(hash))
|
if (!m_pool.exists(hash))
|
||||||
return state.Invalid(ValidationInvalidReason::TX_MEMPOOL_POLICY, false, REJECT_INSUFFICIENTFEE, "mempool full");
|
return state.Invalid(ValidationInvalidReason::TX_MEMPOOL_POLICY, false, REJECT_INSUFFICIENTFEE, "mempool full");
|
||||||
}
|
}
|
||||||
|
@ -4992,8 +4992,8 @@ bool DumpMempool(const CTxMemPool& pool)
|
||||||
file << (uint64_t)vinfo.size();
|
file << (uint64_t)vinfo.size();
|
||||||
for (const auto& i : vinfo) {
|
for (const auto& i : vinfo) {
|
||||||
file << *(i.tx);
|
file << *(i.tx);
|
||||||
file << (int64_t)i.nTime;
|
file << int64_t{count_seconds(i.m_time)};
|
||||||
file << (int64_t)i.nFeeDelta;
|
file << int64_t{i.nFeeDelta};
|
||||||
mapDeltas.erase(i.tx->GetHash());
|
mapDeltas.erase(i.tx->GetHash());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue