20#include <xrpld/app/ledger/LedgerMaster.h>
21#include <xrpld/app/ledger/LedgerReplayer.h>
22#include <xrpld/app/ledger/detail/LedgerReplayMsgHandler.h>
23#include <xrpld/app/main/Application.h>
25#include <xrpl/protocol/LedgerHeader.h>
35 , journal_(app.journal(
"LedgerReplayMsgHandler"))
39protocol::TMProofPathResponse
43 protocol::TMProofPathRequest& packet = *msg;
44 protocol::TMProofPathResponse reply;
46 if (!packet.has_key() || !packet.has_ledgerhash() || !packet.has_type() ||
49 !protocol::TMLedgerMapType_IsValid(packet.type()))
52 reply.set_error(protocol::TMReplyError::reBAD_REQUEST);
55 reply.set_key(packet.key());
56 reply.set_ledgerhash(packet.ledgerhash());
57 reply.set_type(packet.type());
59 uint256 const key(packet.key());
60 uint256 const ledgerHash(packet.ledgerhash());
65 <<
"getProofPath: Don't have ledger " << ledgerHash;
66 reply.set_error(protocol::TMReplyError::reNO_LEDGER);
71 switch (packet.type())
73 case protocol::lmACCOUNT_STATE:
74 return ledger->stateMap().getProofPath(key);
75 case protocol::lmTRANASCTION:
76 return ledger->txMap().getProofPath(key);
86 JLOG(
journal_.
debug()) <<
"getProofPath: Don't have the node " << key
87 <<
" of ledger " << ledgerHash;
88 reply.set_error(protocol::TMReplyError::reNO_NODE);
94 addRaw(ledger->info(), nData);
97 for (
auto const& b : *path)
98 reply.add_path(b.data(), b.size());
100 JLOG(
journal_.
debug()) <<
"getProofPath for the node " << key
101 <<
" of ledger " << ledgerHash <<
" path length "
110 protocol::TMProofPathResponse& reply = *msg;
111 if (reply.has_error() || !reply.has_key() || !reply.has_ledgerhash() ||
112 !reply.has_type() || !reply.has_ledgerheader() ||
113 reply.path_size() == 0)
119 if (reply.type() != protocol::lmACCOUNT_STATE)
122 <<
"Bad message: we only support the state ShaMap for now";
128 {reply.ledgerheader().data(), reply.ledgerheader().size()});
129 uint256 replyHash(reply.ledgerhash());
135 info.hash = replyHash;
141 <<
"Bad message: we only support the short skip list for now. "
149 path.reserve(reply.path_size());
150 for (
int i = 0; i < reply.path_size(); ++i)
152 path.emplace_back(reply.path(i).begin(), reply.path(i).end());
157 JLOG(
journal_.
debug()) <<
"Bad message: Proof path verify failed";
163 if (!node || !node->isLeaf())
175 JLOG(
journal_.
debug()) <<
"Bad message: Cannot get ShaMapItem";
179protocol::TMReplayDeltaResponse
183 protocol::TMReplayDeltaRequest& packet = *msg;
184 protocol::TMReplayDeltaResponse reply;
186 if (!packet.has_ledgerhash() ||
190 reply.set_error(protocol::TMReplyError::reBAD_REQUEST);
193 reply.set_ledgerhash(packet.ledgerhash());
195 uint256 const ledgerHash{packet.ledgerhash()};
197 if (!ledger || !ledger->isImmutable())
200 <<
"getReplayDelta: Don't have ledger " << ledgerHash;
201 reply.set_error(protocol::TMReplyError::reNO_LEDGER);
207 addRaw(ledger->info(), nData);
210 auto const& txMap = ledger->txMap();
212 [&](boost::intrusive_ptr<SHAMapItem const>
const&
txNode) {
216 JLOG(
journal_.
debug()) <<
"getReplayDelta for ledger " << ledgerHash
217 <<
" txMap hash " << txMap.getHash().as_uint256();
225 protocol::TMReplayDeltaResponse& reply = *msg;
226 if (reply.has_error() || !reply.has_ledgerheader())
233 {reply.ledgerheader().data(), reply.ledgerheader().size()});
234 uint256 replyHash(reply.ledgerhash());
240 info.hash = replyHash;
242 auto numTxns = reply.transaction_size();
247 for (
int i = 0; i < numTxns; ++i)
254 reply.transaction(i).data(), reply.transaction(i).size());
260 auto tx = std::make_shared<STTx const>(txSit);
266 auto tid = tx->getTransactionID();
268 orderedTxns.
emplace(meta[sfTransactionIndex], std::move(tx));
287 JLOG(
journal_.
debug()) <<
"Bad message: Transactions verify failed";
virtual Family & getNodeFamily()=0
virtual LedgerMaster & getLedgerMaster()=0
std::shared_ptr< Ledger const > getLedgerByHash(uint256 const &hash)
protocol::TMReplayDeltaResponse processReplayDeltaRequest(std::shared_ptr< protocol::TMReplayDeltaRequest > const &msg)
Process TMReplayDeltaRequest and return TMReplayDeltaResponse.
bool processProofPathResponse(std::shared_ptr< protocol::TMProofPathResponse > const &msg)
Process TMProofPathResponse.
LedgerReplayer & replayer_
bool processReplayDeltaResponse(std::shared_ptr< protocol::TMReplayDeltaResponse > const &msg)
Process TMReplayDeltaResponse.
protocol::TMProofPathResponse processProofPathRequest(std::shared_ptr< protocol::TMProofPathRequest > const &msg)
Process TMProofPathRequest and return TMProofPathResponse.
LedgerReplayMsgHandler(Application &app, LedgerReplayer &replayer)
Manages the lifetime of ledger replay tasks.
void gotReplayDelta(LedgerInfo const &info, std::map< std::uint32_t, std::shared_ptr< STTx const > > &&txns)
Process a ledger delta (extracted from a TMReplayDeltaResponse message)
void gotSkipList(LedgerInfo const &info, boost::intrusive_ptr< SHAMapItem const > const &data)
Process a skip list (extracted from a TMProofPathResponse message)
uint256 const & as_uint256() const
boost::intrusive_ptr< SHAMapItem const > const & peekItem() const
static intr_ptr::SharedPtr< SHAMapTreeNode > makeFromWire(Slice rawNode)
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
bool addGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
SHAMapHash getHash() const
static bool verifyProofPath(uint256 const &rootHash, uint256 const &key, std::vector< Blob > const &path)
Verify the proof path.
Slice getSlice(std::size_t bytes)
Slice slice() const noexcept
void const * getDataPtr() const
static constexpr std::size_t size()
Keylet const & skip() noexcept
The index of the "short" skip list.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
uint256 calculateLedgerHash(LedgerInfo const &info)
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
@ txNode
transaction plus metadata
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)
LedgerHeader deserializeHeader(Slice data, bool hasHash=false)
Deserialize a ledger header from a byte array.