20 #include <ripple/app/ledger/AccountStateSF.h>
21 #include <ripple/app/ledger/InboundLedger.h>
22 #include <ripple/app/ledger/InboundLedgers.h>
23 #include <ripple/app/ledger/LedgerMaster.h>
24 #include <ripple/app/ledger/TransactionStateSF.h>
25 #include <ripple/app/main/Application.h>
26 #include <ripple/app/misc/NetworkOPs.h>
27 #include <ripple/basics/Log.h>
28 #include <ripple/core/JobQueue.h>
29 #include <ripple/nodestore/DatabaseShard.h>
30 #include <ripple/overlay/Overlay.h>
31 #include <ripple/protocol/HashPrefix.h>
32 #include <ripple/protocol/jss.h>
33 #include <ripple/resource/Fees.h>
34 #include <ripple/shamap/SHAMapNodeID.h>
40 using namespace std::chrono_literals;
84 , mHaveTransactions(false)
89 , mReceiveDispatched(false)
113 <<
"Acquiring shard with no shard store available";
127 else if (shardStore &&
mSeq >= shardStore->earliestLedgerSeq())
129 if (
auto l = shardStore->fetchLedger(
mHash,
mSeq))
147 <<
" local store. " <<
mHash;
164 return app_.overlay().findPeerByShortID(id) != nullptr;
173 JLOG(
m_journal.
debug()) <<
"Deferring InboundLedger timer due to load";
180 ptr->invokeOnTimer();
190 if ((seq != 0) && (
mSeq == 0))
224 if (entry.second->type() == protocol::liAS_NODE)
230 <<
"Acquire " <<
mHash <<
" abort "
243 if (
mLedger->info().txHash.isNonZero())
245 if (
mLedger->txMap().getHash().isZero())
248 ret =
mLedger->txMap().getNeededHashes(max, filter);
259 if (
mLedger->info().accountHash.isNonZero())
261 if (
mLedger->stateMap().getHash().isZero())
264 ret =
mLedger->stateMap().getNeededHashes(max, filter);
304 auto makeLedger = [&,
this](
Blob const& data) {
306 mLedger = std::make_shared<Ledger>(
317 <<
" cannot be a ledger";
328 makeLedger(node->getData());
333 auto& dstDB{
mLedger->stateMap().family().db()};
336 Blob blob{node->getData()};
355 mLedger->stateMap().family().db().store(
368 if (
mLedger->info().txHash.isZero())
377 if (
mLedger->txMap().fetchRoot(
391 if (
mLedger->info().accountHash.isZero())
394 <<
"We are acquiring a ledger with a zero account hash";
400 if (
mLedger->stateMap().fetchRoot(
401 SHAMapHash{mLedger->info().accountHash}, &filter))
457 <<
"No progress(" << pc <<
") for ledger " <<
mHash;
477 [
this](
auto peer) {
return peer->hasLedger(
mHash,
mSeq); });
524 if (self->mComplete && !self->mFailed)
526 self->app_.getLedgerMaster().checkAccept(self->getLedger());
527 self->app_.getLedgerMaster().tryAdvance();
530 self->app_.getInboundLedgers().logFailure(
531 self->mHash, self->mSeq);
545 <<
"Trigger on ledger: " <<
mHash << (
mComplete ?
" completed" :
"")
553 stream <<
"Trigger acquiring ledger " <<
mHash <<
" from " << peer;
555 stream <<
"Trigger acquiring ledger " <<
mHash;
576 protocol::TMGetLedger tmGL;
582 tmGL.set_querytype(protocol::qtINDIRECT);
591 protocol::TMGetObjectByHash tmBH;
592 bool typeSet =
false;
593 tmBH.set_query(
true);
595 for (
auto const& p : need)
601 tmBH.set_type(p.first);
605 if (p.first == tmBH.type())
607 protocol::TMIndexedObject* io = tmBH.add_objects();
608 io->set_hash(p.second.begin(), p.second.size());
610 io->set_ledgerseq(
mSeq);
615 std::make_shared<Message>(tmBH, protocol::mtGET_OBJECTS);
629 <<
"getNeededHashes says acquire is complete";
642 tmGL.set_itype(protocol::liBASE);
644 tmGL.set_ledgerseq(
mSeq);
646 << (peer ?
"selected peer" :
"all peers");
652 tmGL.set_ledgerseq(
mLedger->info().seq);
657 tmGL.set_querydepth(0);
659 else if (peer && peer->isHighLatency())
662 tmGL.set_querydepth(2);
665 tmGL.set_querydepth(1);
673 if (!
mLedger->stateMap().isValid())
677 else if (
mLedger->stateMap().getHash().isZero())
680 tmGL.set_itype(protocol::liAS_NODE);
683 << (peer ?
"selected peer" :
"all peers");
703 if (!
mLedger->stateMap().isValid())
719 tmGL.set_itype(protocol::liAS_NODE);
720 for (
auto const&
id : nodes)
722 *(tmGL.add_nodeids()) =
id.first.getRawString();
726 <<
"Sending AS node request (" << nodes.size()
728 << (peer ?
"selected peer" :
"all peers");
745 if (!
mLedger->txMap().isValid())
749 else if (
mLedger->txMap().getHash().isZero())
752 tmGL.set_itype(protocol::liTX_NODE);
755 << (peer ?
"selected peer" :
"all peers");
769 if (!
mLedger->txMap().isValid())
785 tmGL.set_itype(protocol::liTX_NODE);
786 for (
auto const& n : nodes)
788 *(tmGL.add_nodeids()) = n.first.getRawString();
791 <<
"Sending TX node request (" << nodes.size()
792 <<
") to " << (peer ?
"selected peer" :
"all peers");
807 <<
"Done:" << (
mComplete ?
" complete" :
"")
822 nodes.begin(), nodes.end(), [
this](
auto const& item) {
823 return mRecentNodes.count(item.second) == 0;
829 if (dup == nodes.begin())
843 nodes.erase(dup, nodes.end());
849 if (nodes.size() > limit)
852 for (
auto const& n : nodes)
871 mLedger = std::make_shared<Ledger>(
877 <<
"Acquire hash mismatch: " <<
mLedger->info().hash
890 s.
addRaw(data.data(), data.size());
893 if (
mLedger->info().txHash.isZero())
896 if (
mLedger->info().accountHash.isZero())
899 mLedger->txMap().setSynching();
900 mLedger->stateMap().setSynching();
917 if (packet.type() == protocol::liTX_NODE)
931 auto [map, rootHash, filter] = [&]()
933 if (packet.type() == protocol::liTX_NODE)
937 std::make_unique<TransactionStateSF>(
942 std::make_unique<AccountStateSF>(
948 for (
auto const& node : packet.nodes())
951 node.nodeid().data(), node.nodeid().size());
953 san += map.addRootNode(
954 rootHash,
makeSlice(node.nodedata()), filter.get());
956 san += map.addKnownNode(
957 nodeID,
makeSlice(node.nodedata()), filter.get());
973 if (!map.isSynching())
975 if (packet.type() == protocol::liTX_NODE)
1008 san +=
mLedger->stateMap().addRootNode(
1033 san +=
mLedger->txMap().addRootNode(
1068 protocol::TMGetObjectByHash::otTRANSACTION_NODE, h));
1108 protocol::TMLedgerData& packet)
1112 if (packet.type() == protocol::liBASE)
1114 if (packet.nodes_size() < 1)
1137 if (!
mHaveState && (packet.nodes().size() > 1) &&
1152 <<
"Included AS/TX root invalid: " << ex.
what();
1164 if ((packet.type() == protocol::liTX_NODE) ||
1165 (packet.type() == protocol::liAS_NODE))
1167 if (packet.nodes().size() == 0)
1175 for (
auto const& node : packet.nodes())
1177 if (!node.has_nodeid() || !node.has_nodedata())
1188 if (packet.type() == protocol::liTX_NODE)
1214 int chosenPeerCount = -1;
1235 for (
auto& entry : data)
1237 if (
auto peer = entry.first.lock())
1240 if (count > chosenPeerCount)
1242 chosenPeerCount = count;
1243 chosenPeer = std::move(peer);
1263 ret[jss::complete] =
true;
1266 ret[jss::failed] =
true;
1269 ret[jss::peers] =
static_cast<int>(
mPeers.size());
1288 ret[jss::needed_state_hashes] = hv;
1298 ret[jss::needed_transaction_hashes] = hv;