diff --git a/src/ripple/app/ledger/InboundLedger.h b/src/ripple/app/ledger/InboundLedger.h index e2dcde113b..68d8594785 100644 --- a/src/ripple/app/ledger/InboundLedger.h +++ b/src/ripple/app/ledger/InboundLedger.h @@ -39,9 +39,9 @@ class InboundLedger public: static char const* getCountedObjectName () { return "InboundLedger"; } - using pointer = std::shared_ptr ; - using PeerDataPairType = std::pair, - std::shared_ptr>; + using PeerDataPairType = std::pair< + std::weak_ptr, + std::shared_ptr>; // These are the reasons we might acquire a ledger enum fcReason @@ -62,10 +62,6 @@ public: // Called when another attempt is made to fetch this same ledger void update (std::uint32_t seq); - bool isHeader () const - { - return mHaveHeader; - } std::shared_ptr const& getLedger() const { @@ -76,11 +72,6 @@ public: return mSeq; } - enum class TriggerReason { trAdded, trReply, trTimeout }; - void trigger (Peer::ptr const&, TriggerReason); - - bool tryLocal (); - void addPeers (); bool checkLocal (); void init (ScopedLockType& collectionLock); @@ -89,17 +80,30 @@ public: using neededHash_t = std::pair ; - std::vector getNeededHashes (); - /** Return a Json::objectValue. */ Json::Value getJson (int); + void runData (); private: + enum class TriggerReason + { + added, + reply, + timeout + }; + void filterNodes ( std::vector>& nodes, TriggerReason reason); + void trigger (Peer::ptr const&, TriggerReason); + + std::vector getNeededHashes (); + + void addPeers (); + bool tryLocal (); + void done (); void onTimer (bool progress, ScopedLockType& peerSetLock); @@ -109,7 +113,7 @@ private: // For historical nodes, do not trigger too soon // since a fetch pack is probably coming if (mReason != fcHISTORY) - trigger (peer, TriggerReason::trAdded); + trigger (peer, TriggerReason::added); } std::weak_ptr pmDowncast (); @@ -131,6 +135,19 @@ private: SHAMapAddNode&); bool takeAsRootNode (Blob const& data, SHAMapAddNode&); + std::vector + neededTxHashes ( + int max, SHAMapSyncFilter* filter) const; + + std::vector + neededStateHashes ( + int max, SHAMapSyncFilter* filter) const; + + LedgerInfo + deserializeHeader ( + Slice data, + bool hasPrefix); + private: std::shared_ptr mLedger; bool mHaveHeader; diff --git a/src/ripple/app/ledger/InboundLedgers.h b/src/ripple/app/ledger/InboundLedgers.h index b246e95862..ba401b3042 100644 --- a/src/ripple/app/ledger/InboundLedgers.h +++ b/src/ripple/app/ledger/InboundLedgers.h @@ -47,10 +47,6 @@ public: virtual std::shared_ptr find (LedgerHash const& hash) = 0; - virtual bool hasLedger (LedgerHash const& ledgerHash) = 0; - - virtual void dropLedger (LedgerHash const& ledgerHash) = 0; - // VFALCO TODO Remove the dependency on the Peer object. // virtual bool gotLedgerData (LedgerHash const& ledgerHash, diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index 7f62d84c72..40702fdd43 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -58,6 +58,24 @@ namespace ripple { create_genesis_t const create_genesis {}; +static +uint256 +calculateLedgerHash (LedgerInfo const& info) +{ + // VFALCO This has to match addRaw in View.h. + return sha512Half( + HashPrefix::ledgerMaster, + std::uint32_t(info.seq), + std::uint64_t(info.drops.drops ()), + info.parentHash, + info.txHash, + info.accountHash, + std::uint32_t(info.parentCloseTime.time_since_epoch().count()), + std::uint32_t(info.closeTime.time_since_epoch().count()), + std::uint8_t(info.closeTimeResolution.count()), + std::uint8_t(info.closeFlags)); +} + //------------------------------------------------------------------------------ class Ledger::sles_iter_impl @@ -171,7 +189,7 @@ public: Ledger::Ledger (create_genesis_t, Config const& config, Family& family) : mImmutable (false) - , txMap_ (std::make_shared (SHAMapType::TRANSACTION, + , txMap_ (std::make_shared (SHAMapType::TRANSACTION, family, SHAMap::version{1})) , stateMap_ (std::make_shared (SHAMapType::STATE, family, SHAMap::version{1})) @@ -189,40 +207,22 @@ Ledger::Ledger (create_genesis_t, Config const& config, Family& family) sle->setFieldAmount (sfBalance, info_.drops); rawInsert(sle); stateMap_->flushDirty (hotACCOUNT_NODE, info_.seq); - updateHash(); setImmutable(config); - setup(config); } -Ledger::Ledger (uint256 const& parentHash, - uint256 const& transHash, - uint256 const& accountHash, - std::uint64_t totDrops, - NetClock::time_point closeTime, - NetClock::time_point parentCloseTime, - int closeFlags, - NetClock::duration closeResolution, - std::uint32_t ledgerSeq, - bool& loaded, - Config const& config, - Family& family, - beast::Journal j) +Ledger::Ledger ( + LedgerInfo const& info, + bool& loaded, + Config const& config, + Family& family, + beast::Journal j) : mImmutable (true) - , txMap_ (std::make_shared ( - SHAMapType::TRANSACTION, transHash, family, SHAMap::version{1})) - , stateMap_ (std::make_shared (SHAMapType::STATE, accountHash, - family, SHAMap::version{1})) + , txMap_ (std::make_shared (SHAMapType::TRANSACTION, + info.txHash, family, SHAMap::version{1})) + , stateMap_ (std::make_shared (SHAMapType::STATE, + info.accountHash, family, SHAMap::version{1})) + , info_ (info) { - info_.seq = ledgerSeq; - info_.parentCloseTime = parentCloseTime; - info_.closeTime = closeTime; - info_.drops = totDrops; - info_.txHash = transHash; - info_.accountHash = accountHash; - info_.parentHash = parentHash; - info_.closeTimeResolution = closeResolution; - info_.closeFlags = closeFlags; - loaded = true; if (info_.txHash.isNonZero () && @@ -247,7 +247,7 @@ Ledger::Ledger (uint256 const& parentHash, if (! loaded) { - updateHash (); + info_.hash = calculateLedgerHash(info_); family.missing_node (info_.hash); } } @@ -256,8 +256,10 @@ Ledger::Ledger (uint256 const& parentHash, Ledger::Ledger (Ledger const& prevLedger, NetClock::time_point closeTime) : mImmutable (false) - , txMap_ (std::make_shared (SHAMapType::TRANSACTION, - prevLedger.stateMap_->family(), prevLedger.stateMap_->get_version())) + , txMap_ (std::make_shared ( + SHAMapType::TRANSACTION, + prevLedger.stateMap_->family(), + prevLedger.stateMap_->get_version())) , stateMap_ (prevLedger.stateMap_->snapShot (true)) , fees_(prevLedger.fees_) , rules_(prevLedger.rules_) @@ -283,18 +285,17 @@ Ledger::Ledger (Ledger const& prevLedger, } } -Ledger::Ledger (void const* data, - std::size_t size, bool hasPrefix, - Config const& config, Family& family) +Ledger::Ledger ( + LedgerInfo const& info, + Family& family) : mImmutable (true) - , txMap_ (std::make_shared ( - SHAMapType::TRANSACTION, family, SHAMap::version{1})) - , stateMap_ (std::make_shared ( - SHAMapType::STATE, family, SHAMap::version{1})) + , txMap_ (std::make_shared (SHAMapType::TRANSACTION, + info.txHash, family, SHAMap::version{1})) + , stateMap_ (std::make_shared (SHAMapType::STATE, + info.accountHash, family, SHAMap::version{1})) + , info_ (info) { - SerialIter sit (data, size); - setRaw (sit, hasPrefix, family); - // Can't set up until the stateMap is filled in + info_.hash = calculateLedgerHash (info_); } Ledger::Ledger (std::uint32_t ledgerSeq, @@ -312,54 +313,22 @@ Ledger::Ledger (std::uint32_t ledgerSeq, setup(config); } -//------------------------------------------------------------------------------ - -Ledger::~Ledger () -{ -} - void Ledger::setImmutable (Config const& config) { // Force update, since this is the only // place the hash transitions to valid - updateHash (); - - mImmutable = true; - if (txMap_) - txMap_->setImmutable (); - if (stateMap_) - stateMap_->setImmutable (); - setup(config); -} - -void Ledger::updateHash() -{ if (! mImmutable) { - if (txMap_) - info_.txHash = txMap_->getHash ().as_uint256(); - else - info_.txHash.zero (); - - if (stateMap_) - info_.accountHash = stateMap_->getHash ().as_uint256(); - else - info_.accountHash.zero (); + info_.txHash = txMap_->getHash ().as_uint256(); + info_.accountHash = stateMap_->getHash ().as_uint256(); } - // VFALCO This has to match addRaw in View.h. - info_.hash = sha512Half( - HashPrefix::ledgerMaster, - std::uint32_t(info_.seq), - std::uint64_t(info_.drops.drops ()), - info_.parentHash, - info_.txHash, - info_.accountHash, - std::uint32_t(info_.parentCloseTime.time_since_epoch().count()), - std::uint32_t(info_.closeTime.time_since_epoch().count()), - std::uint8_t(info_.closeTimeResolution.count()), - std::uint8_t(info_.closeFlags)); - mValidHash = true; + info_.hash = calculateLedgerHash (info_); + + mImmutable = true; + txMap_->setImmutable (); + stateMap_->setImmutable (); + setup(config); } void @@ -415,15 +384,6 @@ deserializeTxPlusMeta (SHAMapItem const& item) return result; } -void Ledger::setAcquiring () -{ - if (!txMap_ || !stateMap_) - Throw ("invalid map"); - - txMap_->setSynching (); - stateMap_->setSynching (); -} - //------------------------------------------------------------------------------ bool @@ -620,9 +580,7 @@ Ledger::setup (Config const& config) try { - auto const sle = read(keylet::fees()); - - if (sle) + if (auto const sle = read(keylet::fees())) { // VFALCO NOTE Why getFieldIndex and not isFieldPresent? @@ -682,32 +640,6 @@ Ledger::peek (Keylet const& k) const //------------------------------------------------------------------------------ -static void visitHelper ( - std::function const&)>& callback, - std::shared_ptr const& item) -{ - callback(std::make_shared(SerialIter{item->data(), item->size()}, - item->key())); -} - -void Ledger::visitStateItems (std::function callback) const -{ - try - { - if (stateMap_) - { - stateMap_->visitLeaves( - std::bind(&visitHelper, std::ref(callback), - std::placeholders::_1)); - } - } - catch (SHAMapMissingNode&) - { - stateMap_->family().missing_node (info_.hash); - Throw(); - } -} - bool Ledger::walkLedger (beast::Journal j) const { std::vector missingNodes1; @@ -846,27 +778,6 @@ void Ledger::updateSkipList () rawReplace(sle); } -void Ledger::setRaw (SerialIter& sit, bool hasPrefix, Family& family) -{ - if (hasPrefix) - sit.get32 (); - - info_.seq = sit.get32 (); - info_.drops = sit.get64 (); - info_.parentHash = sit.get256 (); - info_.txHash = sit.get256 (); - info_.accountHash = sit.get256 (); - info_.parentCloseTime = NetClock::time_point{NetClock::duration{sit.get32()}}; - info_.closeTime = NetClock::time_point{NetClock::duration{sit.get32()}}; - info_.closeTimeResolution = NetClock::duration{sit.get8()}; - info_.closeFlags = sit.get8 (); - updateHash (); - txMap_ = std::make_shared (SHAMapType::TRANSACTION, info_.txHash, - family, SHAMap::version{1}); - stateMap_ = std::make_shared (SHAMapType::STATE, info_.accountHash, - family, SHAMap::version{1}); -} - static bool saveValidatedLedger ( Application& app, std::shared_ptr const& ledger, @@ -1166,40 +1077,6 @@ qualityDirDescriber ( } } -std::vector -Ledger::getNeededTransactionHashes ( - int max, SHAMapSyncFilter* filter) const -{ - std::vector ret; - - if (info_.txHash.isNonZero ()) - { - if (txMap_->getHash ().isZero ()) - ret.push_back (info_.txHash); - else - ret = txMap_->getNeededHashes (max, filter); - } - - return ret; -} - -std::vector -Ledger::getNeededAccountStateHashes ( - int max, SHAMapSyncFilter* filter) const -{ - std::vector ret; - - if (info_.accountHash.isNonZero ()) - { - if (stateMap_->getHash ().isZero ()) - ret.push_back (info_.accountHash); - else - ret = stateMap_->getNeededHashes (max, filter); - } - - return ret; -} - void Ledger::make_v2() { @@ -1207,7 +1084,9 @@ Ledger::make_v2() stateMap_ = stateMap_->make_v2(); txMap_ = txMap_->make_v2(); info_.validated = false; - updateHash(); + info_.accountHash = stateMap_->getHash ().as_uint256(); + info_.txHash = txMap_->getHash ().as_uint256(); + info_.hash = calculateLedgerHash (info_); } void @@ -1291,18 +1170,22 @@ loadLedgerHelper(std::string const& sqlSuffix, Application& app) using time_point = NetClock::time_point; using duration = NetClock::duration; + + LedgerInfo info; + info.parentHash = prevHash; + info.txHash = transHash; + info.accountHash = accountHash; + info.drops = totDrops.value_or(0); + info.closeTime = time_point{duration{closingTime.value_or(0)}}; + info.parentCloseTime = time_point{duration{prevClosingTime.value_or(0)}}; + info.closeFlags = closeFlags.value_or(0); + info.closeTimeResolution = duration{closeResolution.value_or(0)}; + info.seq = ledgerSeq; + bool loaded = false; auto ledger = std::make_shared( - prevHash, - transHash, - accountHash, - totDrops.value_or(0), - time_point{duration{closingTime.value_or(0)}}, - time_point{duration{prevClosingTime.value_or(0)}}, - closeFlags.value_or(0), - duration{closeResolution.value_or(0)}, - ledgerSeq, + info, loaded, app.config(), app.family(), diff --git a/src/ripple/app/ledger/Ledger.h b/src/ripple/app/ledger/Ledger.h index 40ff87b1b1..17e6e20726 100644 --- a/src/ripple/app/ledger/Ledger.h +++ b/src/ripple/app/ledger/Ledger.h @@ -97,15 +97,17 @@ public: */ Ledger (create_genesis_t, Config const& config, Family& family); + Ledger ( + LedgerInfo const& info, + Family& family); + // Used for ledgers loaded from JSON files - Ledger (uint256 const& parentHash, uint256 const& transHash, - uint256 const& accountHash, - std::uint64_t totDrops, NetClock::time_point closeTime, - NetClock::time_point parentCloseTime, int closeFlags, - NetClock::duration closeResolution, - std::uint32_t ledgerSeq, bool & loaded, Config const& config, - Family& family, - beast::Journal j); + Ledger ( + LedgerInfo const& info, + bool& loaded, + Config const& config, + Family& family, + beast::Journal j); /** Create a new ledger following a previous ledger @@ -116,16 +118,12 @@ public: Ledger (Ledger const& previous, NetClock::time_point closeTime); - Ledger (void const* data, - std::size_t size, bool hasPrefix, - Config const& config, Family& family); - // used for database ledgers Ledger (std::uint32_t ledgerSeq, NetClock::time_point closeTime, Config const& config, Family& family); - ~Ledger(); + ~Ledger() = default; // // ReadView @@ -292,22 +290,10 @@ public: // returns false on error bool addSLE (SLE const& sle); - // ledger sync functions - void setAcquiring (); - //-------------------------------------------------------------------------- void updateSkipList (); - void visitStateItems (std::function) const; - - - std::vector getNeededTransactionHashes ( - int max, SHAMapSyncFilter* filter) const; - - std::vector getNeededAccountStateHashes ( - int max, SHAMapSyncFilter* filter) const; - bool walkLedger (beast::Journal j) const; bool assertSane (beast::Journal ledgerJ); @@ -319,18 +305,12 @@ private: class sles_iter_impl; class txs_iter_impl; - void setRaw (SerialIter& sit, bool hasPrefix, Family& family); - bool setup (Config const& config); std::shared_ptr peek (Keylet const& k) const; - void - updateHash(); - - bool mValidHash = false; bool mImmutable; std::shared_ptr txMap_; diff --git a/src/ripple/app/ledger/impl/InboundLedger.cpp b/src/ripple/app/ledger/impl/InboundLedger.cpp index 771f33dbb3..5e1875d31c 100644 --- a/src/ripple/app/ledger/impl/InboundLedger.cpp +++ b/src/ripple/app/ledger/impl/InboundLedger.cpp @@ -79,20 +79,46 @@ InboundLedger::InboundLedger ( , mReason (reason) , mReceiveDispatched (false) { - JLOG (m_journal.trace()) << "Acquiring ledger " << mHash; } +void InboundLedger::init (ScopedLockType& collectionLock) +{ + ScopedLockType sl (mLock); + collectionLock.unlock (); + + if (!tryLocal ()) + { + addPeers (); + setTimer (); + } + else if (!isFailed ()) + { + JLOG (m_journal.debug()) << + "Acquiring ledger we already have locally: " << getHash (); + mLedger->setImmutable (app_.config()); + + if (mReason != fcHISTORY) + app_.getLedgerMaster ().storeLedger (mLedger); + + // Check if this could be a newer fully-validated ledger + if (mReason == fcVALIDATION || + mReason == fcCURRENT || + mReason == fcCONSENSUS) + { + app_.getLedgerMaster ().checkAccept (mLedger); + } + } +} + void InboundLedger::update (std::uint32_t seq) { ScopedLockType sl (mLock); + // If we didn't know the sequence number, but now do, save it if ((seq != 0) && (mSeq == 0)) - { - // If we didn't know the sequence number, but now do, save it mSeq = seq; - } // Prevent this from being swept touch (); @@ -130,33 +156,63 @@ InboundLedger::~InboundLedger () } } -void InboundLedger::init (ScopedLockType& collectionLock) +std::vector +InboundLedger::neededTxHashes ( + int max, SHAMapSyncFilter* filter) const { - ScopedLockType sl (mLock); - collectionLock.unlock (); + std::vector ret; - if (!tryLocal ()) + if (mLedger->info().txHash.isNonZero ()) { - addPeers (); - setTimer (); + if (mLedger->txMap().getHash().isZero ()) + ret.push_back (mLedger->info().txHash); + else + ret = mLedger->txMap().getNeededHashes (max, filter); } - else if (!isFailed ()) + + return ret; +} + +std::vector +InboundLedger::neededStateHashes ( + int max, SHAMapSyncFilter* filter) const +{ + std::vector ret; + + if (mLedger->info().accountHash.isNonZero ()) { - JLOG (m_journal.debug()) << - "Acquiring ledger we already have locally: " << getHash (); - mLedger->setImmutable (app_.config()); - - if (mReason != fcHISTORY) - app_.getLedgerMaster ().storeLedger (mLedger); - - // Check if this could be a newer fully-validated ledger - if (mReason == fcVALIDATION || - mReason == fcCURRENT || - mReason == fcCONSENSUS) - { - app_.getLedgerMaster ().checkAccept (mLedger); - } + if (mLedger->stateMap().getHash().isZero ()) + ret.push_back (mLedger->info().accountHash); + else + ret = mLedger->stateMap().getNeededHashes (max, filter); } + + return ret; +} + +LedgerInfo +InboundLedger::deserializeHeader ( + Slice data, + bool hasPrefix) +{ + SerialIter sit (data.data(), data.size()); + + if (hasPrefix) + sit.get32 (); + + LedgerInfo info; + + info.seq = sit.get32 (); + info.drops = sit.get64 (); + info.parentHash = sit.get256 (); + info.txHash = sit.get256 (); + info.accountHash = sit.get256 (); + info.parentCloseTime = NetClock::time_point{NetClock::duration{sit.get32()}}; + info.closeTime = NetClock::time_point{NetClock::duration{sit.get32()}}; + info.closeTimeResolution = NetClock::duration{sit.get8()}; + info.closeFlags = sit.get8 (); + + return info; } /** See how much of the ledger data, if any, is @@ -180,17 +236,19 @@ bool InboundLedger::tryLocal () JLOG (m_journal.trace()) << "Ledger header found in fetch pack"; + mLedger = std::make_shared ( - data.data(), data.size(), true, - app_.config(), app_.family()); + deserializeHeader (makeSlice(data), true), + app_.family()); + app_.getNodeStore ().store ( hotLEDGER, std::move (data), mHash); } else { mLedger = std::make_shared( - node->getData().data(), node->getData().size(), - true, app_.config(), app_.family()); + deserializeHeader (makeSlice (node->getData()), true), + app_.family()); } if (mLedger->info().hash != mHash) @@ -220,8 +278,7 @@ bool InboundLedger::tryLocal () if (mLedger->txMap().fetchRoot ( SHAMapHash{mLedger->info().txHash}, &filter)) { - auto h (mLedger->getNeededTransactionHashes (1, &filter)); - + auto h = neededTxHashes (1, &filter); if (h.empty ()) { JLOG (m_journal.trace()) << @@ -241,21 +298,18 @@ bool InboundLedger::tryLocal () mFailed = true; return true; } - else + + AccountStateSF filter(app_); + + if (mLedger->stateMap().fetchRoot ( + SHAMapHash{mLedger->info().accountHash}, &filter)) { - AccountStateSF filter(app_); - - if (mLedger->stateMap().fetchRoot ( - SHAMapHash{mLedger->info().accountHash}, &filter)) + auto h = neededStateHashes (1, &filter); + if (h.empty ()) { - auto h (mLedger->getNeededAccountStateHashes (1, &filter)); - - if (h.empty ()) - { - JLOG (m_journal.trace()) << - "Had full AS map locally"; - mHaveState = true; - } + JLOG (m_journal.trace()) << + "Had full AS map locally"; + mHaveState = true; } } } @@ -317,10 +371,10 @@ void InboundLedger::onTimer (bool wasProgress, ScopedLockType&) // otherwise, we need to trigger before we add // so each peer gets triggered once if (mReason != fcHISTORY) - trigger (Peer::ptr (), TriggerReason::trTimeout); + trigger (Peer::ptr (), TriggerReason::timeout); addPeers (); if (mReason == fcHISTORY) - trigger (Peer::ptr (), TriggerReason::trTimeout); + trigger (Peer::ptr (), TriggerReason::timeout); } } @@ -443,7 +497,7 @@ void InboundLedger::trigger (Peer::ptr const& peer, TriggerReason reason) tmBH.set_query (true); tmBH.set_ledgerhash (mHash.begin (), mHash.size ()); bool typeSet = false; - for (auto& p : need) + for (auto const& p : need) { JLOG (m_journal.warn()) << "Want: " << p.second; @@ -461,24 +515,17 @@ void InboundLedger::trigger (Peer::ptr const& peer, TriggerReason reason) } } - Message::pointer packet (std::make_shared ( - tmBH, protocol::mtGET_OBJECTS)); - { - for (auto it = mPeers.begin (), end = mPeers .end (); - it != end; ++it) - { - Peer::ptr iPeer ( - app_.overlay ().findPeerByShortID (it->first)); + auto packet = std::make_shared ( + tmBH, protocol::mtGET_OBJECTS); - if (iPeer) - { - mByHash = false; - iPeer->send (packet); - } + for (auto const& it : mPeers) + { + if (auto p = app_.overlay ().findPeerByShortID (it.first)) + { + mByHash = false; + p->send (packet); } } - JLOG (m_journal.info()) << - "Attempting by hash fetch for ledger " << mHash; } else { @@ -507,7 +554,7 @@ void InboundLedger::trigger (Peer::ptr const& peer, TriggerReason reason) if (mLedger) tmGL.set_ledgerseq (mLedger->info().seq); - if (reason != TriggerReason::trReply) + if (reason != TriggerReason::reply) { // If we're querying blind, don't query deep tmGL.set_querydepth (0); @@ -692,7 +739,7 @@ void InboundLedger::filterNodes ( JLOG (m_journal.trace()) << "filterNodes: all duplicates"; - if (reason != TriggerReason::trTimeout) + if (reason != TriggerReason::timeout) { nodes.clear (); return; @@ -706,7 +753,7 @@ void InboundLedger::filterNodes ( nodes.erase (dup, nodes.end()); } - std::size_t const limit = (reason == TriggerReason::trReply) + std::size_t const limit = (reason == TriggerReason::reply) ? reqNodesReply : reqNodes; @@ -731,8 +778,8 @@ bool InboundLedger::takeHeader (std::string const& data) return true; mLedger = std::make_shared( - data.data(), data.size(), false, - app_.config(), app_.family()); + deserializeHeader (makeSlice(data), false), + app_.family()); if (mLedger->info().hash != mHash) { @@ -757,7 +804,9 @@ bool InboundLedger::takeHeader (std::string const& data) if (mLedger->info().accountHash.isZero ()) mHaveState = true; - mLedger->setAcquiring (); + mLedger->txMap().setSynching (); + mLedger->stateMap().setSynching (); + return true; } @@ -944,7 +993,8 @@ bool InboundLedger::takeTxRootNode (Blob const& data, SHAMapAddNode& san) return san.isGood(); } -std::vector InboundLedger::getNeededHashes () +std::vector +InboundLedger::getNeededHashes () { std::vector ret; @@ -958,8 +1008,7 @@ std::vector InboundLedger::getNeededHashes () if (!mHaveState) { AccountStateSF filter(app_); - // VFALCO NOTE What's the number 4? - for (auto const& h : mLedger->getNeededAccountStateHashes (4, &filter)) + for (auto const& h : neededStateHashes (4, &filter)) { ret.push_back (std::make_pair ( protocol::TMGetObjectByHash::otSTATE_NODE, h)); @@ -969,8 +1018,7 @@ std::vector InboundLedger::getNeededHashes () if (!mHaveTransactions) { TransactionStateSF filter(app_); - // VFALCO NOTE What's the number 4? - for (auto const& h : mLedger->getNeededTransactionHashes (4, &filter)) + for (auto const& h : neededTxHashes (4, &filter)) { ret.push_back (std::make_pair ( protocol::TMGetObjectByHash::otTRANSACTION_NODE, h)); @@ -987,12 +1035,12 @@ std::vector InboundLedger::getNeededHashes () bool InboundLedger::gotData (std::weak_ptr peer, std::shared_ptr data) { - ScopedLockType sl (mReceivedDataLock); + std::lock_guard sl (mReceivedDataLock); if (isDone ()) return false; - mReceivedData.push_back (PeerDataPairType (peer, data)); + mReceivedData.emplace_back (peer, data); if (mReceiveDispatched) return false; @@ -1133,13 +1181,14 @@ void InboundLedger::runData () { data.clear(); { - ScopedLockType sl (mReceivedDataLock); + std::lock_guard sl (mReceivedDataLock); if (mReceivedData.empty ()) { mReceiveDispatched = false; break; } + data.swap(mReceivedData); } @@ -1161,7 +1210,7 @@ void InboundLedger::runData () } while (1); if (chosenPeer) - trigger (chosenPeer, TriggerReason::trReply); + trigger (chosenPeer, TriggerReason::reply); } Json::Value InboundLedger::getJson (int) @@ -1194,10 +1243,7 @@ Json::Value InboundLedger::getJson (int) if (mHaveHeader && !mHaveState) { Json::Value hv (Json::arrayValue); - - // VFALCO Why 16? - auto v = mLedger->getNeededAccountStateHashes (16, nullptr); - for (auto const& h : v) + for (auto const& h : neededStateHashes (16, nullptr)) { hv.append (to_string (h)); } @@ -1207,9 +1253,7 @@ Json::Value InboundLedger::getJson (int) if (mHaveHeader && !mHaveTransactions) { Json::Value hv (Json::arrayValue); - // VFALCO Why 16? - auto v = mLedger->getNeededTransactionHashes (16, nullptr); - for (auto const& h : v) + for (auto const& h : neededTxHashes (16, nullptr)) { hv.append (to_string (h)); } diff --git a/src/ripple/app/ledger/impl/InboundLedgers.cpp b/src/ripple/app/ledger/impl/InboundLedgers.cpp index cb86ce0c53..1cbd77eaf9 100644 --- a/src/ripple/app/ledger/impl/InboundLedgers.cpp +++ b/src/ripple/app/ledger/impl/InboundLedgers.cpp @@ -111,8 +111,7 @@ public: { ScopedLockType sl (mLock); - auto it = mLedgers. - find (hash); + auto it = mLedgers.find (hash); if (it != mLedgers.end ()) { ret = it->second; @@ -122,23 +121,6 @@ public: return ret; } - bool hasLedger (LedgerHash const& hash) - { - assert (hash.isNonZero ()); - - ScopedLockType sl (mLock); - return mLedgers.find (hash) != mLedgers.end (); - } - - void dropLedger (LedgerHash const& hash) - { - assert (hash.isNonZero ()); - - ScopedLockType sl (mLock); - mLedgers.erase (hash); - - } - /* This gets called when "We got some data from an inbound ledger"