mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-26 14:05:51 +00:00
Use abstract_clock
This commit is contained in:
@@ -31,9 +31,10 @@ public:
|
||||
|
||||
static char const* getCountedObjectName () { return "LedgerConsensus"; }
|
||||
|
||||
LedgerConsensusImp (LedgerHash const & prevLCLHash,
|
||||
LedgerConsensusImp (clock_type& clock, LedgerHash const & prevLCLHash,
|
||||
Ledger::ref previousLedger, uint32 closeTime)
|
||||
: mState (lcsPRE_CLOSE)
|
||||
: m_clock (clock)
|
||||
, mState (lcsPRE_CLOSE)
|
||||
, mCloseTime (closeTime)
|
||||
, mPrevLedgerHash (prevLCLHash)
|
||||
, mPreviousLedger (previousLedger)
|
||||
@@ -280,7 +281,8 @@ public:
|
||||
return empty;
|
||||
}
|
||||
|
||||
acquiring = boost::make_shared<TransactionAcquire> (hash);
|
||||
acquiring = boost::make_shared<TransactionAcquire> (
|
||||
std::ref (m_clock), hash);
|
||||
startAcquiring (acquiring);
|
||||
}
|
||||
}
|
||||
@@ -1855,6 +1857,8 @@ private:
|
||||
val->setFieldU32(sfLoadFee, fee);
|
||||
}
|
||||
private:
|
||||
clock_type& m_clock;
|
||||
|
||||
// VFALCO TODO Rename these to look pretty
|
||||
enum LCState
|
||||
{
|
||||
@@ -1910,12 +1914,9 @@ LedgerConsensus::~LedgerConsensus ()
|
||||
{
|
||||
}
|
||||
|
||||
boost::shared_ptr <LedgerConsensus> LedgerConsensus::New(LedgerHash const & prevLCLHash,
|
||||
Ledger::ref previousLedger, uint32 closeTime)
|
||||
boost::shared_ptr <LedgerConsensus> LedgerConsensus::New (clock_type& clock,
|
||||
LedgerHash const &prevLCLHash, Ledger::ref previousLedger, uint32 closeTime)
|
||||
{
|
||||
return boost::make_shared <LedgerConsensusImp> (
|
||||
prevLCLHash, previousLedger,closeTime);
|
||||
clock, prevLCLHash, previousLedger,closeTime);
|
||||
}
|
||||
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -28,7 +28,9 @@
|
||||
class LedgerConsensus
|
||||
{
|
||||
public:
|
||||
static shared_ptr <LedgerConsensus> New(
|
||||
typedef abstract_clock <std::chrono::seconds> clock_type;
|
||||
|
||||
static boost::shared_ptr <LedgerConsensus> New (clock_type& clock,
|
||||
LedgerHash const & prevLCLHash, Ledger::ref previousLedger,
|
||||
uint32 closeTime);
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ SETUP_LOG (InboundLedger)
|
||||
#define LEDGER_TIMEOUT_COUNT 10 // how many timeouts before we giveup
|
||||
#define LEDGER_TIMEOUT_AGGRESSIVE 6 // how many timeouts before we get aggressive
|
||||
|
||||
InboundLedger::InboundLedger (uint256 const& hash, uint32 seq)
|
||||
: PeerSet (hash, LEDGER_ACQUIRE_TIMEOUT, false)
|
||||
InboundLedger::InboundLedger (clock_type& clock, uint256 const& hash, uint32 seq)
|
||||
: PeerSet (clock, hash, LEDGER_ACQUIRE_TIMEOUT, false)
|
||||
, mHaveBase (false)
|
||||
, mHaveState (false)
|
||||
, mHaveTransactions (false)
|
||||
|
||||
@@ -34,9 +34,9 @@ public:
|
||||
typedef std::pair < boost::weak_ptr<Peer>, boost::shared_ptr<protocol::TMLedgerData> > PeerDataPairType;
|
||||
|
||||
public:
|
||||
InboundLedger (uint256 const& hash, uint32 seq);
|
||||
InboundLedger (clock_type& clock, uint256 const& hash, uint32 seq);
|
||||
|
||||
virtual ~InboundLedger ();
|
||||
~InboundLedger ();
|
||||
|
||||
bool isBase () const
|
||||
{
|
||||
|
||||
@@ -28,12 +28,12 @@ public:
|
||||
// How long before we try again to acquire the same ledger
|
||||
static const int kReacquireIntervalSeconds = 300;
|
||||
|
||||
explicit InboundLedgersImp (Stoppable& parent)
|
||||
InboundLedgersImp (clock_type& clock, Stoppable& parent)
|
||||
: Stoppable ("InboundLedgers", parent)
|
||||
, m_clock (clock)
|
||||
, mLock (this, "InboundLedger", __FILE__, __LINE__)
|
||||
, mRecentFailures ("LedgerAcquireRecentFailures",
|
||||
get_abstract_clock <std::chrono::steady_clock, std::chrono::seconds> (),
|
||||
0, kReacquireIntervalSeconds)
|
||||
clock, 0, kReacquireIntervalSeconds)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = boost::make_shared<InboundLedger> (hash, seq);
|
||||
ret = boost::make_shared <InboundLedger> (std::ref (m_clock), hash, seq);
|
||||
assert (ret);
|
||||
mLedgers.insert (std::make_pair (hash, ret));
|
||||
ret->init (sl, couldBeNew);
|
||||
@@ -335,7 +335,7 @@ public:
|
||||
{
|
||||
mRecentFailures.sweep ();
|
||||
|
||||
int const now = UptimeTimer::getInstance ().getElapsedSeconds ();
|
||||
clock_type::time_point const now (m_clock.now());
|
||||
|
||||
// Make a list of things to sweep, while holding the lock
|
||||
std::vector <MapType::mapped_type> stuffToSweep;
|
||||
@@ -353,7 +353,7 @@ public:
|
||||
it->second->touch ();
|
||||
++it;
|
||||
}
|
||||
else if ((it->second->getLastAction () + 60) < now)
|
||||
else if ((it->second->getLastAction () + std::chrono::minutes (1)) < now)
|
||||
{
|
||||
stuffToSweep.push_back (it->second);
|
||||
// shouldn't cause the actual final delete
|
||||
@@ -383,6 +383,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
clock_type& m_clock;
|
||||
|
||||
typedef boost::unordered_map <uint256, InboundLedger::pointer> MapType;
|
||||
|
||||
typedef RippleRecursiveMutex LockType;
|
||||
@@ -390,7 +392,7 @@ private:
|
||||
LockType mLock;
|
||||
|
||||
MapType mLedgers;
|
||||
KeyCache <uint256, UptimeTimerAdapter> mRecentFailures;
|
||||
KeyCache <uint256> mRecentFailures;
|
||||
|
||||
uint256 mConsensusLedger;
|
||||
uint256 mValidationLedger;
|
||||
@@ -402,9 +404,9 @@ InboundLedgers::~InboundLedgers()
|
||||
{
|
||||
}
|
||||
|
||||
InboundLedgers* InboundLedgers::New (Stoppable& parent)
|
||||
InboundLedgers* InboundLedgers::New (clock_type& clock, Stoppable& parent)
|
||||
{
|
||||
return new InboundLedgersImp (parent);
|
||||
return new InboundLedgersImp (clock, parent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,9 +27,14 @@
|
||||
class InboundLedgers
|
||||
{
|
||||
public:
|
||||
typedef abstract_clock <std::chrono::seconds> clock_type;
|
||||
|
||||
virtual ~InboundLedgers() = 0;
|
||||
|
||||
static InboundLedgers* New (Stoppable& parent);
|
||||
// VFALCO TODO Make this a free function outside the class:
|
||||
// std::unique_ptr <InboundLedger> make_InboundLedgers (...)
|
||||
//
|
||||
static InboundLedgers* New (clock_type& clock, Stoppable& parent);
|
||||
|
||||
// VFALCO TODO Should this be called findOrAdd ?
|
||||
//
|
||||
|
||||
@@ -220,8 +220,9 @@ public:
|
||||
*m_jobQueue, LogPartition::getJournal <LedgerMaster> ()))
|
||||
|
||||
// VFALCO NOTE Does NetworkOPs depend on LedgerMaster?
|
||||
, m_networkOPs (NetworkOPs::New (
|
||||
*m_ledgerMaster, *m_jobQueue, LogPartition::getJournal <NetworkOPsLog> ()))
|
||||
, m_networkOPs (NetworkOPs::New (get_abstract_clock <
|
||||
std::chrono::steady_clock, std::chrono::seconds> (), *m_ledgerMaster,
|
||||
*m_jobQueue, LogPartition::getJournal <NetworkOPsLog> ()))
|
||||
|
||||
// VFALCO NOTE LocalCredentials starts the deprecated UNL service
|
||||
, m_deprecatedUNL (UniqueNodeList::New (*m_jobQueue))
|
||||
@@ -238,7 +239,8 @@ public:
|
||||
|
||||
, m_sntpClient (SNTPClient::New (*this))
|
||||
|
||||
, m_inboundLedgers (InboundLedgers::New (*m_jobQueue))
|
||||
, m_inboundLedgers (InboundLedgers::New (get_abstract_clock <
|
||||
std::chrono::steady_clock, std::chrono::seconds> (), *m_jobQueue))
|
||||
|
||||
, m_txQueue (TxQueue::New ())
|
||||
|
||||
|
||||
@@ -33,8 +33,10 @@ public:
|
||||
public:
|
||||
// VFALCO TODO Make LedgerMaster a SharedPtr or a reference.
|
||||
//
|
||||
NetworkOPsImp (LedgerMaster& ledgerMaster, Stoppable& parent, Journal journal)
|
||||
NetworkOPsImp (clock_type& clock, LedgerMaster& ledgerMaster,
|
||||
Stoppable& parent, Journal journal)
|
||||
: NetworkOPs (parent)
|
||||
, m_clock (clock)
|
||||
, m_journal (journal)
|
||||
, mLock (this, "NetOPs", __FILE__, __LINE__)
|
||||
, mMode (omDISCONNECTED)
|
||||
@@ -407,6 +409,8 @@ private:
|
||||
void pubServer ();
|
||||
|
||||
private:
|
||||
clock_type& m_clock;
|
||||
|
||||
typedef boost::unordered_map <uint160, SubMapType> SubInfoMapType;
|
||||
typedef boost::unordered_map <uint160, SubMapType>::iterator SubInfoMapIterator;
|
||||
|
||||
@@ -1410,7 +1414,7 @@ int NetworkOPsImp::beginConsensus (uint256 const& networkClosed, Ledger::pointer
|
||||
assert (!mConsensus);
|
||||
prevLedger->setImmutable ();
|
||||
|
||||
mConsensus = LedgerConsensus::New(
|
||||
mConsensus = LedgerConsensus::New (m_clock,
|
||||
networkClosed, prevLedger,
|
||||
m_ledgerMaster.getCurrentLedger ()->getCloseTimeNC ());
|
||||
|
||||
@@ -3104,10 +3108,14 @@ NetworkOPs::NetworkOPs (Stoppable& parent)
|
||||
{
|
||||
}
|
||||
|
||||
NetworkOPs::~NetworkOPs ()
|
||||
{
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
NetworkOPs* NetworkOPs::New (LedgerMaster& ledgerMaster,
|
||||
NetworkOPs* NetworkOPs::New (clock_type& clock, LedgerMaster& ledgerMaster,
|
||||
Stoppable& parent, Journal journal)
|
||||
{
|
||||
return new NetworkOPsImp (ledgerMaster, parent, journal);
|
||||
return new NetworkOPsImp (clock, ledgerMaster, parent, journal);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ protected:
|
||||
explicit NetworkOPs (Stoppable& parent);
|
||||
|
||||
public:
|
||||
typedef abstract_clock <std::chrono::seconds> clock_type;
|
||||
|
||||
enum Fault
|
||||
{
|
||||
// exceptions these functions can throw
|
||||
@@ -80,10 +82,10 @@ public:
|
||||
public:
|
||||
// VFALCO TODO Make LedgerMaster a SharedPtr or a reference.
|
||||
//
|
||||
static NetworkOPs* New (LedgerMaster& ledgerMaster,
|
||||
static NetworkOPs* New (clock_type& clock, LedgerMaster& ledgerMaster,
|
||||
Stoppable& parent, Journal journal);
|
||||
|
||||
virtual ~NetworkOPs () { }
|
||||
virtual ~NetworkOPs () = 0;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
|
||||
class InboundLedger;
|
||||
|
||||
PeerSet::PeerSet (uint256 const& hash, int interval, bool txnData)
|
||||
PeerSet::PeerSet (clock_type& clock_,
|
||||
uint256 const& hash, int interval, bool txnData)
|
||||
: mLock (this, "PeerSet", __FILE__, __LINE__)
|
||||
, mHash (hash)
|
||||
, mTimerInterval (interval)
|
||||
@@ -30,11 +31,21 @@ PeerSet::PeerSet (uint256 const& hash, int interval, bool txnData)
|
||||
, mTxnData (txnData)
|
||||
, mProgress (false)
|
||||
, mTimer (getApp().getIOService ())
|
||||
, m_clock (clock_)
|
||||
{
|
||||
mLastAction = UptimeTimer::getInstance ().getElapsedSeconds ();
|
||||
mLastAction = clock().now();
|
||||
assert ((mTimerInterval > 10) && (mTimerInterval < 30000));
|
||||
}
|
||||
|
||||
PeerSet::~PeerSet ()
|
||||
{
|
||||
}
|
||||
|
||||
PeerSet::clock_type& PeerSet::clock ()
|
||||
{
|
||||
return m_clock;
|
||||
}
|
||||
|
||||
bool PeerSet::peerHas (Peer::ref ptr)
|
||||
{
|
||||
ScopedLockType sl (mLock, __FILE__, __LINE__);
|
||||
@@ -139,7 +150,7 @@ void PeerSet::sendRequest (const protocol::TMGetLedger& tmGL)
|
||||
|
||||
PackedMessage::pointer packet = boost::make_shared<PackedMessage> (tmGL, protocol::mtGET_LEDGER);
|
||||
|
||||
for (boost::unordered_map<uint64, int>::iterator it = mPeers.begin (), end = mPeers.end (); it != end; ++it)
|
||||
for (Map::iterator it = mPeers.begin (), end = mPeers.end (); it != end; ++it)
|
||||
{
|
||||
Peer::pointer peer = getApp().getPeers ().getPeerById (it->first);
|
||||
|
||||
@@ -153,7 +164,7 @@ int PeerSet::takePeerSetFrom (const PeerSet& s)
|
||||
int ret = 0;
|
||||
mPeers.clear ();
|
||||
|
||||
for (boost::unordered_map<uint64, int>::const_iterator it = s.mPeers.begin (), end = s.mPeers.end ();
|
||||
for (Map::const_iterator it = s.mPeers.begin (), end = s.mPeers.end ();
|
||||
it != end; ++it)
|
||||
{
|
||||
mPeers.insert (std::make_pair (it->first, 0));
|
||||
@@ -167,7 +178,7 @@ int PeerSet::getPeerCount () const
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
for (boost::unordered_map<uint64, int>::const_iterator it = mPeers.begin (), end = mPeers.end (); it != end; ++it)
|
||||
for (Map::const_iterator it = mPeers.begin (), end = mPeers.end (); it != end; ++it)
|
||||
if (getApp().getPeers ().hasPeer (it->first))
|
||||
++ret;
|
||||
|
||||
|
||||
@@ -27,42 +27,52 @@
|
||||
class PeerSet : LeakChecked <PeerSet>
|
||||
{
|
||||
public:
|
||||
typedef abstract_clock <std::chrono::seconds> clock_type;
|
||||
|
||||
uint256 const& getHash () const
|
||||
{
|
||||
return mHash;
|
||||
}
|
||||
|
||||
bool isComplete () const
|
||||
{
|
||||
return mComplete;
|
||||
}
|
||||
|
||||
bool isFailed () const
|
||||
{
|
||||
return mFailed;
|
||||
}
|
||||
|
||||
int getTimeouts () const
|
||||
{
|
||||
return mTimeouts;
|
||||
}
|
||||
|
||||
bool isActive ();
|
||||
|
||||
void progress ()
|
||||
{
|
||||
mProgress = true;
|
||||
mAggressive = false;
|
||||
}
|
||||
|
||||
void clearProgress ()
|
||||
{
|
||||
mProgress = false;
|
||||
}
|
||||
|
||||
bool isProgress ()
|
||||
{
|
||||
return mProgress;
|
||||
}
|
||||
|
||||
void touch ()
|
||||
{
|
||||
mLastAction = UptimeTimer::getInstance ().getElapsedSeconds ();
|
||||
mLastAction = clock().now();
|
||||
}
|
||||
int getLastAction ()
|
||||
|
||||
clock_type::time_point getLastAction () const
|
||||
{
|
||||
return mLastAction;
|
||||
}
|
||||
@@ -92,13 +102,15 @@ private:
|
||||
static void TimerEntry (boost::weak_ptr<PeerSet>, const boost::system::error_code& result);
|
||||
static void TimerJobEntry (Job&, boost::shared_ptr<PeerSet>);
|
||||
|
||||
// VFALCO TODO try to make some of these private
|
||||
protected:
|
||||
clock_type& clock ();
|
||||
|
||||
// VFALCO TODO try to make some of these private
|
||||
typedef RippleRecursiveMutex LockType;
|
||||
typedef LockType::ScopedLockType ScopedLockType;
|
||||
|
||||
PeerSet (uint256 const& hash, int interval, bool txnData);
|
||||
virtual ~PeerSet () { }
|
||||
PeerSet (clock_type& clock, uint256 const& hash, int interval, bool txnData);
|
||||
virtual ~PeerSet () = 0;
|
||||
|
||||
virtual void newPeer (Peer::ref) = 0;
|
||||
virtual void onTimer (bool progress, ScopedLockType&) = 0;
|
||||
@@ -127,7 +139,7 @@ protected:
|
||||
bool mFailed;
|
||||
bool mAggressive;
|
||||
bool mTxnData;
|
||||
int mLastAction;
|
||||
clock_type::time_point mLastAction;
|
||||
bool mProgress;
|
||||
|
||||
|
||||
@@ -137,7 +149,11 @@ protected:
|
||||
// VFALCO TODO Verify that these are used in the way that the names suggest.
|
||||
typedef uint64 PeerIdentifier;
|
||||
typedef int ReceivedChunkCount;
|
||||
boost::unordered_map <PeerIdentifier, ReceivedChunkCount> mPeers;
|
||||
typedef boost::unordered_map <PeerIdentifier, ReceivedChunkCount> Map;
|
||||
Map mPeers;
|
||||
|
||||
private:
|
||||
clock_type& m_clock;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -267,7 +267,7 @@ public:
|
||||
typedef std::pair<uint256, SHAMapNode> TNIndex;
|
||||
|
||||
private:
|
||||
static KeyCache <uint256, UptimeTimerAdapter> fullBelowCache;
|
||||
static KeyCache <uint256> fullBelowCache;
|
||||
|
||||
static TaggedCacheType <TNIndex, SHAMapTreeNode> treeNodeCache;
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
|
||||
static const uint256 uZero;
|
||||
|
||||
KeyCache <uint256, UptimeTimerAdapter> SHAMap::fullBelowCache (
|
||||
// VFALCO TODO Put these globals into a singleton and make the clock a parameter
|
||||
KeyCache <uint256> SHAMap::fullBelowCache (
|
||||
"fullBelowCache",
|
||||
get_abstract_clock <std::chrono::steady_clock, std::chrono::seconds> (),
|
||||
524288, 240);
|
||||
|
||||
@@ -24,13 +24,17 @@ SETUP_LOG (TransactionAcquire)
|
||||
typedef std::map<uint160, LedgerProposal::pointer>::value_type u160_prop_pair;
|
||||
typedef std::map<uint256, DisputedTx::pointer>::value_type u256_lct_pair;
|
||||
|
||||
TransactionAcquire::TransactionAcquire (uint256 const& hash)
|
||||
: PeerSet (hash, TX_ACQUIRE_TIMEOUT, true)
|
||||
TransactionAcquire::TransactionAcquire (clock_type& clock, uint256 const& hash)
|
||||
: PeerSet (clock, hash, TX_ACQUIRE_TIMEOUT, true)
|
||||
, mHaveRoot (false)
|
||||
{
|
||||
mMap = boost::make_shared<SHAMap> (smtTRANSACTION, hash);
|
||||
}
|
||||
|
||||
TransactionAcquire::~TransactionAcquire ()
|
||||
{
|
||||
}
|
||||
|
||||
static void TACompletionHandler (uint256 hash, SHAMap::pointer map)
|
||||
{
|
||||
{
|
||||
|
||||
@@ -33,11 +33,8 @@ public:
|
||||
typedef boost::shared_ptr<TransactionAcquire> pointer;
|
||||
|
||||
public:
|
||||
explicit TransactionAcquire (uint256 const& hash);
|
||||
virtual ~TransactionAcquire ()
|
||||
{
|
||||
;
|
||||
}
|
||||
TransactionAcquire (clock_type& clock, uint256 const& hash);
|
||||
~TransactionAcquire ();
|
||||
|
||||
SHAMap::ref getMap ()
|
||||
{
|
||||
|
||||
@@ -58,7 +58,7 @@ private:
|
||||
clock_type::time_point last_access;
|
||||
};
|
||||
|
||||
typedef std::unordered_map <key_type, Entry> map_type;
|
||||
typedef std::unordered_map <key_type, Entry, Hash, KeyEqual> map_type;
|
||||
typedef typename map_type::iterator iterator;
|
||||
typedef std::lock_guard <Mutex> lock_guard;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user