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>
24#include <xrpl/protocol/LedgerHeader.h>
34 , journal_(app.journal(
"LedgerReplayMsgHandler"))
38protocol::TMProofPathResponse
42 protocol::TMProofPathRequest& packet = *msg;
43 protocol::TMProofPathResponse reply;
45 if (!packet.has_key() || !packet.has_ledgerhash() || !packet.has_type() ||
48 !protocol::TMLedgerMapType_IsValid(packet.type()))
51 reply.set_error(protocol::TMReplyError::reBAD_REQUEST);
54 reply.set_key(packet.key());
55 reply.set_ledgerhash(packet.ledgerhash());
56 reply.set_type(packet.type());
58 uint256 const key(packet.key());
59 uint256 const ledgerHash(packet.ledgerhash());
64 <<
"getProofPath: Don't have ledger " << ledgerHash;
65 reply.set_error(protocol::TMReplyError::reNO_LEDGER);
70 switch (packet.type())
72 case protocol::lmACCOUNT_STATE:
73 return ledger->stateMap().getProofPath(key);
74 case protocol::lmTRANASCTION:
75 return ledger->txMap().getProofPath(key);
85 JLOG(
journal_.
debug()) <<
"getProofPath: Don't have the node " << key
86 <<
" of ledger " << ledgerHash;
87 reply.set_error(protocol::TMReplyError::reNO_NODE);
93 addRaw(ledger->info(), nData);
96 for (
auto const& b : *path)
97 reply.add_path(b.data(), b.size());
100 <<
" of ledger " << ledgerHash <<
" path length "
109 protocol::TMProofPathResponse& reply = *msg;
110 if (reply.has_error() || !reply.has_key() || !reply.has_ledgerhash() ||
111 !reply.has_type() || !reply.has_ledgerheader() ||
112 reply.path_size() == 0)
118 if (reply.type() != protocol::lmACCOUNT_STATE)
121 <<
"Bad message: we only support the state ShaMap for now";
127 {reply.ledgerheader().data(), reply.ledgerheader().size()});
128 uint256 replyHash(reply.ledgerhash());
134 info.hash = replyHash;
140 <<
"Bad message: we only support the short skip list for now. "
148 path.reserve(reply.path_size());
149 for (
int i = 0; i < reply.path_size(); ++i)
151 path.emplace_back(reply.path(i).begin(), reply.path(i).end());
156 JLOG(
journal_.
debug()) <<
"Bad message: Proof path verify failed";
162 if (!node || !node->isLeaf())
174 JLOG(
journal_.
debug()) <<
"Bad message: Cannot get ShaMapItem";
178protocol::TMReplayDeltaResponse
182 protocol::TMReplayDeltaRequest& packet = *msg;
183 protocol::TMReplayDeltaResponse reply;
185 if (!packet.has_ledgerhash() ||
189 reply.set_error(protocol::TMReplyError::reBAD_REQUEST);
192 reply.set_ledgerhash(packet.ledgerhash());
194 uint256 const ledgerHash{packet.ledgerhash()};
196 if (!ledger || !ledger->isImmutable())
199 <<
"getReplayDelta: Don't have ledger " << ledgerHash;
200 reply.set_error(protocol::TMReplyError::reNO_LEDGER);
206 addRaw(ledger->info(), nData);
209 auto const& txMap = ledger->txMap();
211 [&](boost::intrusive_ptr<SHAMapItem const>
const&
txNode) {
215 JLOG(
journal_.
debug()) <<
"getReplayDelta for ledger " << ledgerHash
216 <<
" txMap hash " << txMap.getHash().as_uint256();
224 protocol::TMReplayDeltaResponse& reply = *msg;
225 if (reply.has_error() || !reply.has_ledgerheader())
232 {reply.ledgerheader().data(), reply.ledgerheader().size()});
233 uint256 replyHash(reply.ledgerhash());
239 info.hash = replyHash;
241 auto numTxns = reply.transaction_size();
246 for (
int i = 0; i < numTxns; ++i)
253 reply.transaction(i).data(), reply.transaction(i).size());
259 auto tx = std::make_shared<STTx const>(txSit);
265 auto tid = tx->getTransactionID();
267 orderedTxns.
emplace(meta[sfTransactionIndex], std::move(tx));
286 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 std::shared_ptr< 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
const void * 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.