8
8
#include < logging.h>
9
9
#include < policy/policy.h>
10
10
#include < primitives/transaction.h>
11
+ #include < util/time.h>
11
12
12
13
#include < cassert>
13
14
14
- /* * Expiration time for orphan transactions in seconds */
15
- static constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60 ;
16
- /* * Minimum time between orphan transactions expire time checks in seconds */
17
- static constexpr int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60 ;
15
+ /* * Expiration time for orphan transactions */
16
+ static constexpr auto ORPHAN_TX_EXPIRE_TIME{20min} ;
17
+ /* * Minimum time between orphan transactions expire time checks */
18
+ static constexpr auto ORPHAN_TX_EXPIRE_INTERVAL{5min} ;
18
19
19
20
20
21
bool TxOrphanage::AddTx (const CTransactionRef& tx, NodeId peer)
@@ -40,7 +41,7 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
40
41
return false ;
41
42
}
42
43
43
- auto ret = m_orphans.emplace (wtxid, OrphanTx{tx, peer, GetTime () + ORPHAN_TX_EXPIRE_TIME, m_orphan_list.size ()});
44
+ auto ret = m_orphans.emplace (wtxid, OrphanTx{tx, peer, Now<NodeSeconds> () + ORPHAN_TX_EXPIRE_TIME, m_orphan_list.size ()});
44
45
assert (ret.second );
45
46
m_orphan_list.push_back (ret.first );
46
47
for (const CTxIn& txin : tx->vin ) {
@@ -90,7 +91,7 @@ int TxOrphanage::EraseTxNoLock(const Wtxid& wtxid)
90
91
// Time spent in orphanage = difference between current and entry time.
91
92
// Entry time is equal to ORPHAN_TX_EXPIRE_TIME earlier than entry's expiry.
92
93
LogPrint (BCLog::TXPACKAGES, " removed orphan tx %s (wtxid=%s) after %ds\n " , txid.ToString (), wtxid.ToString (),
93
- GetTime ( ) + ORPHAN_TX_EXPIRE_TIME - it->second .nTimeExpire );
94
+ Ticks<std::chrono::seconds>( NodeClock::now ( ) + ORPHAN_TX_EXPIRE_TIME - it->second .nTimeExpire ) );
94
95
m_orphan_list.pop_back ();
95
96
m_wtxid_to_orphan_it.erase (wtxid);
96
97
@@ -122,12 +123,12 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans, FastRandomContext& rng)
122
123
LOCK (m_mutex);
123
124
124
125
unsigned int nEvicted = 0 ;
125
- static int64_t nNextSweep;
126
- int64_t nNow = GetTime () ;
126
+ static NodeSeconds nNextSweep;
127
+ auto nNow{Now<NodeSeconds>()} ;
127
128
if (nNextSweep <= nNow) {
128
129
// Sweep out expired orphan pool entries:
129
130
int nErased = 0 ;
130
- int64_t nMinExpTime = nNow + ORPHAN_TX_EXPIRE_TIME - ORPHAN_TX_EXPIRE_INTERVAL;
131
+ auto nMinExpTime{ nNow + ORPHAN_TX_EXPIRE_TIME - ORPHAN_TX_EXPIRE_INTERVAL} ;
131
132
std::map<Wtxid, OrphanTx>::iterator iter = m_orphans.begin ();
132
133
while (iter != m_orphans.end ())
133
134
{
0 commit comments