1#include <xrpld/app/ledger/LedgerMaster.h>
2#include <xrpld/app/ledger/LedgerReplayer.h>
3#include <xrpld/app/ledger/detail/LedgerReplayMsgHandler.h>
4#include <xrpld/app/main/Application.h>
6#include <xrpl/protocol/LedgerHeader.h>
12 : app_(app), replayer_(replayer), journal_(app.journal(
"LedgerReplayMsgHandler"))
16protocol::TMProofPathResponse
19 protocol::TMProofPathRequest& packet = *msg;
20 protocol::TMProofPathResponse reply;
22 if (!packet.has_key() || !packet.has_ledgerhash() || !packet.has_type() ||
24 !protocol::TMLedgerMapType_IsValid(packet.type()))
27 reply.set_error(protocol::TMReplyError::reBAD_REQUEST);
30 reply.set_key(packet.key());
31 reply.set_ledgerhash(packet.ledgerhash());
32 reply.set_type(packet.type());
34 uint256 const key(packet.key());
35 uint256 const ledgerHash(packet.ledgerhash());
39 JLOG(
journal_.
debug()) <<
"getProofPath: Don't have ledger " << ledgerHash;
40 reply.set_error(protocol::TMReplyError::reNO_LEDGER);
45 switch (packet.type())
47 case protocol::lmACCOUNT_STATE:
48 return ledger->stateMap().getProofPath(key);
49 case protocol::lmTRANSACTION:
50 return ledger->txMap().getProofPath(key);
60 JLOG(
journal_.
debug()) <<
"getProofPath: Don't have the node " << key <<
" of ledger " << ledgerHash;
61 reply.set_error(protocol::TMReplyError::reNO_NODE);
67 addRaw(ledger->header(), nData);
70 for (
auto const& b : *path)
71 reply.add_path(b.data(), b.size());
73 JLOG(
journal_.
debug()) <<
"getProofPath for the node " << key <<
" of ledger " << ledgerHash <<
" path length "
81 protocol::TMProofPathResponse& reply = *msg;
82 if (reply.has_error() || !reply.has_key() || !reply.has_ledgerhash() || !reply.has_type() ||
83 !reply.has_ledgerheader() || reply.path_size() == 0)
89 if (reply.type() != protocol::lmACCOUNT_STATE)
91 JLOG(
journal_.
debug()) <<
"Bad message: we only support the state ShaMap for now";
96 auto info =
deserializeHeader({reply.ledgerheader().data(), reply.ledgerheader().size()});
97 uint256 replyHash(reply.ledgerhash());
103 info.hash = replyHash;
108 JLOG(
journal_.
debug()) <<
"Bad message: we only support the short skip list for now. "
116 path.
reserve(reply.path_size());
117 for (
int i = 0; i < reply.path_size(); ++i)
119 path.
emplace_back(reply.path(i).begin(), reply.path(i).end());
124 JLOG(
journal_.
debug()) <<
"Bad message: Proof path verify failed";
130 if (!node || !node->isLeaf())
142 JLOG(
journal_.
debug()) <<
"Bad message: Cannot get ShaMapItem";
146protocol::TMReplayDeltaResponse
149 protocol::TMReplayDeltaRequest& packet = *msg;
150 protocol::TMReplayDeltaResponse reply;
152 if (!packet.has_ledgerhash() || packet.ledgerhash().size() !=
uint256::size())
155 reply.set_error(protocol::TMReplyError::reBAD_REQUEST);
158 reply.set_ledgerhash(packet.ledgerhash());
160 uint256 const ledgerHash{packet.ledgerhash()};
162 if (!ledger || !ledger->isImmutable())
164 JLOG(
journal_.
debug()) <<
"getReplayDelta: Don't have ledger " << ledgerHash;
165 reply.set_error(protocol::TMReplyError::reNO_LEDGER);
171 addRaw(ledger->header(), nData);
174 auto const& txMap = ledger->txMap();
175 txMap.visitLeaves([&](boost::intrusive_ptr<SHAMapItem const>
const&
txNode) {
179 JLOG(
journal_.
debug()) <<
"getReplayDelta for ledger " << ledgerHash <<
" txMap hash "
180 << txMap.getHash().as_uint256();
187 protocol::TMReplayDeltaResponse& reply = *msg;
188 if (reply.has_error() || !reply.has_ledgerheader())
194 auto info =
deserializeHeader({reply.ledgerheader().data(), reply.ledgerheader().size()});
195 uint256 replyHash(reply.ledgerhash());
201 info.hash = replyHash;
203 auto numTxns = reply.transaction_size();
208 for (
int i = 0; i < numTxns; ++i)
214 Serializer shaMapItemData(reply.transaction(i).data(), reply.transaction(i).size());
226 auto tid = tx->getTransactionID();
228 orderedTxns.
emplace(meta[sfTransactionIndex], std::move(tx));
245 JLOG(
journal_.
debug()) <<
"Bad message: Transactions verify failed";
virtual LedgerMaster & getLedgerMaster()=0
virtual Family & getNodeFamily()=0
std::shared_ptr< Ledger const > getLedgerByHash(uint256 const &hash)
bool processProofPathResponse(std::shared_ptr< protocol::TMProofPathResponse > const &msg)
Process TMProofPathResponse.
protocol::TMProofPathResponse processProofPathRequest(std::shared_ptr< protocol::TMProofPathRequest > const &msg)
Process TMProofPathRequest and return TMProofPathResponse.
LedgerReplayMsgHandler(Application &app, LedgerReplayer &replayer)
LedgerReplayer & replayer_
bool processReplayDeltaResponse(std::shared_ptr< protocol::TMReplayDeltaResponse > const &msg)
Process TMReplayDeltaResponse.
protocol::TMReplayDeltaResponse processReplayDeltaRequest(std::shared_ptr< protocol::TMReplayDeltaRequest > const &msg)
Process TMReplayDeltaRequest and return TMReplayDeltaResponse.
Manages the lifetime of ledger replay tasks.
void gotReplayDelta(LedgerHeader const &info, std::map< std::uint32_t, std::shared_ptr< STTx const > > &&txns)
Process a ledger delta (extracted from a TMReplayDeltaResponse message)
void gotSkipList(LedgerHeader 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.
static bool verifyProofPath(uint256 const &rootHash, uint256 const &key, std::vector< Blob > const &path)
Verify the proof path.
bool addGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
SHAMapHash getHash() const
Slice getSlice(std::size_t bytes)
void const * getDataPtr() const
Slice slice() const noexcept
static constexpr std::size_t size()
T emplace_back(T... args)
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.
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
LedgerHeader deserializeHeader(Slice data, bool hasHash=false)
Deserialize a ledger header from a byte array.
uint256 calculateLedgerHash(LedgerHeader const &info)
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)
@ txNode
transaction plus metadata
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)