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 ) {
@@ -87,7 +88,7 @@ int TxOrphanage::EraseTxNoLock(const Wtxid& wtxid)
87
88
// Time spent in orphanage = difference between current and entry time.
88
89
// Entry time is equal to ORPHAN_TX_EXPIRE_TIME earlier than entry's expiry.
89
90
LogPrint (BCLog::TXPACKAGES, " removed orphan tx %s (wtxid=%s) after %ds\n " , txid.ToString (), wtxid.ToString (),
90
- GetTime ( ) + ORPHAN_TX_EXPIRE_TIME - it->second .nTimeExpire );
91
+ Ticks<std::chrono::seconds>( NodeClock::now ( ) + ORPHAN_TX_EXPIRE_TIME - it->second .nTimeExpire ) );
91
92
m_orphan_list.pop_back ();
92
93
93
94
m_orphans.erase (it);
@@ -118,12 +119,12 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans, FastRandomContext& rng)
118
119
LOCK (m_mutex);
119
120
120
121
unsigned int nEvicted = 0 ;
121
- static int64_t nNextSweep;
122
- int64_t nNow = GetTime () ;
122
+ static NodeSeconds nNextSweep;
123
+ auto nNow{Now<NodeSeconds>()} ;
123
124
if (nNextSweep <= nNow) {
124
125
// Sweep out expired orphan pool entries:
125
126
int nErased = 0 ;
126
- int64_t nMinExpTime = nNow + ORPHAN_TX_EXPIRE_TIME - ORPHAN_TX_EXPIRE_INTERVAL;
127
+ auto nMinExpTime{ nNow + ORPHAN_TX_EXPIRE_TIME - ORPHAN_TX_EXPIRE_INTERVAL} ;
127
128
std::map<Wtxid, OrphanTx>::iterator iter = m_orphans.begin ();
128
129
while (iter != m_orphans.end ())
129
130
{
0 commit comments