From d0a813a19d253a01285197319cf4cc37e2cd86a5 Mon Sep 17 00:00:00 2001 From: natenichols Date: Thu, 12 May 2022 14:16:34 -0500 Subject: [PATCH 1/4] Adding missing include in beast/rngfill.h to fix rippled build --- src/ripple/basics/MathUtilities.h | 2 +- src/ripple/beast/utility/rngfill.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ripple/basics/MathUtilities.h b/src/ripple/basics/MathUtilities.h index f9dbcbbbc..4e8e3751c 100644 --- a/src/ripple/basics/MathUtilities.h +++ b/src/ripple/basics/MathUtilities.h @@ -21,7 +21,7 @@ #define RIPPLE_BASICS_MATHUTILITIES_H_INCLUDED #include -#include +#include #include namespace ripple { diff --git a/src/ripple/beast/utility/rngfill.h b/src/ripple/beast/utility/rngfill.h index cf8b7bbeb..71f434bda 100644 --- a/src/ripple/beast/utility/rngfill.h +++ b/src/ripple/beast/utility/rngfill.h @@ -21,6 +21,7 @@ #define BEAST_RANDOM_RNGFILL_H_INCLUDED #include +#include #include #include #include From 34786abd4ff06f80022024d177e0d7dbf97abda9 Mon Sep 17 00:00:00 2001 From: manojsdoshi Date: Wed, 18 May 2022 14:28:03 -0700 Subject: [PATCH 2/4] Set version to 1.9.1-rc2 --- src/ripple/protocol/impl/BuildInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ripple/protocol/impl/BuildInfo.cpp b/src/ripple/protocol/impl/BuildInfo.cpp index e3cda0ae1..2f3862279 100644 --- a/src/ripple/protocol/impl/BuildInfo.cpp +++ b/src/ripple/protocol/impl/BuildInfo.cpp @@ -33,7 +33,7 @@ namespace BuildInfo { // and follow the format described at http://semver.org/ //------------------------------------------------------------------------------ // clang-format off -char const* const versionString = "1.9.1-rc1" +char const* const versionString = "1.9.1-rc2" // clang-format on #if defined(DEBUG) || defined(SANITIZER) From e32bc674aa2a035ea0f05fe43d2f301b203f1827 Mon Sep 17 00:00:00 2001 From: manojsdoshi Date: Sun, 22 May 2022 13:18:09 -0700 Subject: [PATCH 3/4] Set version to 1.9.1 --- RELEASENOTES.md | 78 ++++++++++++++++++++++++++ src/ripple/protocol/impl/BuildInfo.cpp | 2 +- 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index d509f9d7e..9412e13ef 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -7,6 +7,84 @@ This document contains the release notes for `rippled`, the reference server imp Have new ideas? Need help with setting up your node? Come visit us [here](https://github.com/ripple/rippled/issues/new/choose) +# Introducing XRP Ledger version 1.9.1 + +Version 1.9.1 of `rippled`, the reference server implementation of the XRP Ledger protocol, is now available. This release includes several important fixes, including a fix for a syncing issue from 1.9.0, a new fix amendment to correct a bug in the new Non-Fungible Tokens (NFTs) code, and a new amendment to allow multi-signing by up to 32 signers. + + + + +## Action Required + +This release introduces two new amendments to the XRP Ledger protocol. These amendments are now open for voting according to the XRP Ledger's [amendment process](https://xrpl.org/amendments.html), which enables protocol changes following two weeks of >80% support from trusted validators. + +If you operate an XRP Ledger server, then you should upgrade to version 1.9.1 within two weeks, to ensure service continuity. The exact time that protocol changes take effect depends on the voting decisions of the decentralized network. + +The **fixNFTokenDirV1** amendment fixes a bug in code associated with the **NonFungibleTokensV1** amendment, so the fixNFTokenDirV1 amendment should be enabled first. All validator operators are encouraged to [configure amendment voting](https://xrpl.org/configure-amendment-voting.html) to oppose the NonFungibleTokensV1 amendment until _after_ the fixNFTokenDirV1 amendment has become enabled. For more information about NFTs on the XRP Ledger, see [NFT Conceptual Overview](https://xrpl.org/nft-conceptual-overview.html). + +The **ExpandedSignerList** amendment extends the ledger's built-in multi-signing functionality so that each list can contain up to 32 entries instead of the current limit of 8. Additionally, this amendment allows each signer to have an arbitrary 256-bit data field associated with it. This data can be used to identify the signer or provide other metadata that is useful for organizations, smart contracts, or other purposes. + +## Install / Upgrade + +On supported platforms, see the [instructions on installing or updating `rippled`](https://xrpl.org/install-rippled.html). + +## Changelog + +This release contains the following features and improvements. + +## New Features and Amendments + +- **Introduce fixNFTokenDirV1 Amendment** - This amendment fixes an off-by-one error that occurred in some corner cases when determining which `NFTokenPage` an `NFToken` object belongs on. It also adjusts the constraints of `NFTokenPage` invariant checks, so that certain error cases fail with a suitable error code such as `tecNO_SUITABLE_TOKEN_PAGE` instead of failing with a `tecINVARIANT_FAILED` error code. ([#4155](https://github.com/ripple/rippled/pull/4155)) + +- **Introduce ExpandedSignerList Amendment** - This amendment expands the maximum signer list size to 32 entries and allows each signer to have an optional 256-bit `WalletLocator` field containing arbitrary data. ([#4097](https://github.com/ripple/rippled/pull/4097)) + +- **Pause online deletion rather than canceling it if the server fails health check** - The server stops performing online deletion of old ledger history if the server fails its internal health check during this time. Online deletion can now resume after the server recovers, rather than having to start over. ([#4139](https://github.com/ripple/rippled/pull/4139)) + + +## Bug Fixes and Performance Improvements + +- **Fix performance issues introduced in 1.9.0** - Readjusts some parameters of the ledger acquisition engine to revert some changes introduced in 1.9.0 that had adverse effects on some systems, including causing some systems to fail to sync to the network. ([#4152](https://github.com/ripple/rippled/pull/4152)) + +- **Improve Memory Efficiency of Path Finding** - Finding paths for cross-currency payments is a resource-intensive operation. While that remains true, this fix improves memory usage of pathfinding by discarding trust line results that cannot be used before those results are fully loaded or cached. ([#4111](https://github.com/ripple/rippled/pull/4111)) + +- **Fix incorrect CMake behavior on Windows when platform is unspecified or x64** - Fixes handling of platform selection when using the cmake-gui tool to build on Windows. The generator expects `Win64` but the GUI only provides `x64` as an option, which raises an error. This fix only raises an error if the platform is `Win32` instead, allowing the generation of solution files to succeed. ([#4150](https://github.com/ripple/rippled/pull/4150)) + +- **Fix test failures with newer MSVC compilers on Windows** - Fixes some cases where the API handler code used string pointer comparisons, which may not work correctly with some versions of the MSVC compiler. ([#4149](https://github.com/ripple/rippled/pull/4149)) + +- **Update minimum Boost version to 1.71.0** - This release is compatible with Boost library versions 1.71.0 through 1.77.0. The build configuration and documentation have been updated to reflect this. ([#4134](https://github.com/ripple/rippled/pull/4134)) + +- **Fix unit test failures for DatabaseDownloader** - Increases a timeout in the `DatabaseDownloader` code and adjusts unit tests so that the code does not return spurious failures, and more data is logged if it does fail. ([#4021](https://github.com/ripple/rippled/pull/4021)) + +- **Refactor relational database interface** - Improves code comments, naming, and organization of the module that interfaces with relational databases (such as the SQLite database used for tracking transaction history). ([#3965](https://github.com/ripple/rippled/pull/3965)) + + +## Contributions + +### GitHub + +The public source code repository for `rippled` is hosted on GitHub at . + +We welcome contributions, big and small, and invite everyone to join the community of XRP Ledger developers and help us build the Internet of Value. + + +### Credits + +The following people contributed directly to this release: + +- Devon White +- Ed Hennis +- Gregory Popovitch +- Mark Travis +- Manoj Doshi +- Nik Bougalis +- Richard Holland +- Scott Schurr + +For a real-time view of all lifetime contributors, including links to the commits made by each, please visit the "Contributors" section of the GitHub repository: . + +We welcome external contributions and are excited to see the broader XRP Ledger community continue to grow and thrive. + + # Change log - API version 2 will now return `signer_lists` in the root of the `account_info` response, no longer nested under `account_data`. diff --git a/src/ripple/protocol/impl/BuildInfo.cpp b/src/ripple/protocol/impl/BuildInfo.cpp index 2f3862279..5fd822203 100644 --- a/src/ripple/protocol/impl/BuildInfo.cpp +++ b/src/ripple/protocol/impl/BuildInfo.cpp @@ -33,7 +33,7 @@ namespace BuildInfo { // and follow the format described at http://semver.org/ //------------------------------------------------------------------------------ // clang-format off -char const* const versionString = "1.9.1-rc2" +char const* const versionString = "1.9.1" // clang-format on #if defined(DEBUG) || defined(SANITIZER) From 27846df19c71bd99726172d4d6beab802838fac7 Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Mon, 11 Apr 2022 22:55:24 +0000 Subject: [PATCH 4/4] Add book_changes rpc --- src/ripple/app/main/Main.cpp | 1 + src/ripple/app/misc/NetworkOPs.cpp | 47 ++++- src/ripple/net/InfoSub.h | 5 + src/ripple/net/impl/RPCCall.cpp | 1 + src/ripple/protocol/jss.h | 8 + src/ripple/rpc/BookChanges.h | 213 ++++++++++++++++++++++ src/ripple/rpc/handlers/BookOffers.cpp | 13 ++ src/ripple/rpc/handlers/Handlers.h | 2 + src/ripple/rpc/handlers/LedgerRequest.cpp | 123 +------------ src/ripple/rpc/handlers/Subscribe.cpp | 4 + src/ripple/rpc/impl/Handler.cpp | 1 + src/ripple/rpc/impl/RPCHandler.cpp | 5 + src/ripple/rpc/impl/RPCHelpers.cpp | 116 ++++++++++++ src/ripple/rpc/impl/RPCHelpers.h | 6 + 14 files changed, 430 insertions(+), 115 deletions(-) create mode 100644 src/ripple/rpc/BookChanges.h diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index c08836e79..64b6464a4 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -135,6 +135,7 @@ printHelp(const po::options_description& desc) "[strict]\n" " account_tx accountID [ledger_min [ledger_max [limit " "[offset]]]] [binary] [count] [descending]\n" + " book_changes []\n" " book_offers [ " "[ [ []]]]]\n" " can_delete [||now|always|never]\n" diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index 9203a83ad..6ff644ba8 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -62,6 +62,7 @@ #include #include #include +#include #include #include #include @@ -502,6 +503,11 @@ public: bool unsubLedger(std::uint64_t uListener) override; + bool + subBookChanges(InfoSub::ref ispListener) override; + bool + unsubBookChanges(std::uint64_t uListener) override; + bool subServer(InfoSub::ref ispListener, Json::Value& jvResult, bool admin) override; @@ -743,9 +749,10 @@ private: sValidations, // Received validations. sPeerStatus, // Peer status changes. sConsensusPhase, // Consensus phase + sBookChanges, // Per-ledger order book changes - sLastEntry = sConsensusPhase // as this name implies, any new entry - // must be ADDED ABOVE this one + sLastEntry = sBookChanges // as this name implies, any new entry + // must be ADDED ABOVE this one }; std::array mStreamMaps; @@ -2898,6 +2905,24 @@ NetworkOPsImp::pubLedger(std::shared_ptr const& lpAccepted) } } + if (!mStreamMaps[sBookChanges].empty()) + { + Json::Value jvObj = ripple::RPC::computeBookChanges(lpAccepted); + + auto it = mStreamMaps[sBookChanges].begin(); + while (it != mStreamMaps[sBookChanges].end()) + { + InfoSub::pointer p = it->second.lock(); + if (p) + { + p->send(jvObj, true); + ++it; + } + else + it = mStreamMaps[sBookChanges].erase(it); + } + } + { static bool firstTime = true; if (firstTime) @@ -3876,6 +3901,16 @@ NetworkOPsImp::subLedger(InfoSub::ref isrListener, Json::Value& jvResult) .second; } +// <-- bool: true=added, false=already there +bool +NetworkOPsImp::subBookChanges(InfoSub::ref isrListener) +{ + std::lock_guard sl(mSubLock); + return mStreamMaps[sBookChanges] + .emplace(isrListener->getSeq(), isrListener) + .second; +} + // <-- bool: true=erased, false=was not there bool NetworkOPsImp::unsubLedger(std::uint64_t uSeq) @@ -3884,6 +3919,14 @@ NetworkOPsImp::unsubLedger(std::uint64_t uSeq) return mStreamMaps[sLedger].erase(uSeq); } +// <-- bool: true=erased, false=was not there +bool +NetworkOPsImp::unsubBookChanges(std::uint64_t uSeq) +{ + std::lock_guard sl(mSubLock); + return mStreamMaps[sBookChanges].erase(uSeq); +} + // <-- bool: true=added, false=already there bool NetworkOPsImp::subManifests(InfoSub::ref isrListener) diff --git a/src/ripple/net/InfoSub.h b/src/ripple/net/InfoSub.h index 3c170669b..fb44e23b7 100644 --- a/src/ripple/net/InfoSub.h +++ b/src/ripple/net/InfoSub.h @@ -128,6 +128,11 @@ public: virtual bool unsubLedger(std::uint64_t uListener) = 0; + virtual bool + subBookChanges(ref ispListener) = 0; + virtual bool + unsubBookChanges(std::uint64_t uListener) = 0; + virtual bool subManifests(ref ispListener) = 0; virtual bool diff --git a/src/ripple/net/impl/RPCCall.cpp b/src/ripple/net/impl/RPCCall.cpp index 820f25ddf..334ca8693 100644 --- a/src/ripple/net/impl/RPCCall.cpp +++ b/src/ripple/net/impl/RPCCall.cpp @@ -1242,6 +1242,7 @@ public: {"account_objects", &RPCParser::parseAccountItems, 1, 5}, {"account_offers", &RPCParser::parseAccountItems, 1, 4}, {"account_tx", &RPCParser::parseAccountTransactions, 1, 8}, + {"book_changes", &RPCParser::parseLedgerId, 1, 1}, {"book_offers", &RPCParser::parseBookOffers, 2, 7}, {"can_delete", &RPCParser::parseCanDelete, 0, 1}, {"channel_authorize", &RPCParser::parseChannelAuthorize, 3, 4}, diff --git a/src/ripple/protocol/jss.h b/src/ripple/protocol/jss.h index 0dc413e6d..a87d77e0f 100644 --- a/src/ripple/protocol/jss.h +++ b/src/ripple/protocol/jss.h @@ -166,11 +166,13 @@ JSS(build_path); // in: TransactionSign JSS(build_version); // out: NetworkOPs JSS(cancel_after); // out: AccountChannels JSS(can_delete); // out: CanDelete +JSS(changes); // out: BookChanges JSS(channel_id); // out: AccountChannels JSS(channels); // out: AccountChannels JSS(check); // in: AccountObjects JSS(check_nodes); // in: LedgerCleaner JSS(clear); // in/out: FetchInfo +JSS(close); // out: BookChanges JSS(close_flags); // out: LedgerToJson JSS(close_time); // in: Application, out: NetworkOPs, // RCLCxPeerPos, LedgerToJson @@ -193,6 +195,8 @@ JSS(converge_time_s); // out: NetworkOPs JSS(cookie); // out: NetworkOPs JSS(count); // in: AccountTx*, ValidatorList JSS(counters); // in/out: retrieve counters +JSS(cur_a); // out: BookChanges +JSS(cur_b); // out: BookChanges JSS(currentShard); // out: NodeToShardStatus JSS(currentShardIndex); // out: NodeToShardStatus JSS(currency); // in: paths/PathRequest, STAmount @@ -282,6 +286,7 @@ JSS(hashes); // in: AccountObjects JSS(have_header); // out: InboundLedger JSS(have_state); // out: InboundLedger JSS(have_transactions); // out: InboundLedger +JSS(high); // out: BookChanges JSS(highest_sequence); // out: AccountInfo JSS(highest_ticket); // out: AccountInfo JSS(historical_perminute); // historical_perminute. @@ -363,6 +368,7 @@ JSS(load_fee); // out: LoadFeeTrackImp, NetworkOPs JSS(local); // out: resource/Logic.h JSS(local_txs); // out: GetCounts JSS(local_static_keys); // out: ValidatorList +JSS(low); // out: BookChanges JSS(lowest_sequence); // out: AccountInfo JSS(lowest_ticket); // out: AccountInfo JSS(majority); // out: RPC feature @@ -639,6 +645,8 @@ JSS(validator_sites); // out: ValidatorSites JSS(value); // out: STAmount JSS(version); // out: RPCVersion JSS(vetoed); // out: AmendmentTableImpl +JSS(vol_a); // out: BookChanges +JSS(vol_b); // out: BookChanges JSS(vote); // in: Feature JSS(warning); // rpc: JSS(warnings); // out: server_info, server_state diff --git a/src/ripple/rpc/BookChanges.h b/src/ripple/rpc/BookChanges.h new file mode 100644 index 000000000..c754cbde7 --- /dev/null +++ b/src/ripple/rpc/BookChanges.h @@ -0,0 +1,213 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2019 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef RIPPLE_RPC_BOOKCHANGES_H_INCLUDED +#define RIPPLE_RPC_BOOKCAHNGES_H_INCLUDED + +namespace Json { +class Value; +} + +namespace ripple { + +class ReadView; +class Transaction; +class TxMeta; +class STTx; + +namespace RPC { + +template +Json::Value +computeBookChanges(std::shared_ptr const& lpAccepted) +{ + std::map< + std::string, + std::tuple< + STAmount, // side A volume + STAmount, // side B volume + STAmount, // high rate + STAmount, // low rate + STAmount, // open rate + STAmount // close rate + >> + tally; + + for (auto& tx : lpAccepted->txs) + { + if (!tx.first || !tx.second || + !tx.first->isFieldPresent(sfTransactionType)) + continue; + + std::optional offerCancel; + uint16_t tt = tx.first->getFieldU16(sfTransactionType); + switch (tt) + { + case ttOFFER_CANCEL: + case ttOFFER_CREATE: { + if (tx.first->isFieldPresent(sfOfferSequence)) + offerCancel = tx.first->getFieldU32(sfOfferSequence); + break; + } + // in future if any other ways emerge to cancel an offer + // this switch makes them easy to add + default: + break; + } + + for (auto const& node : tx.second->getFieldArray(sfAffectedNodes)) + { + SField const& metaType = node.getFName(); + uint16_t nodeType = node.getFieldU16(sfLedgerEntryType); + + // we only care about ltOFFER objects being modified or + // deleted + if (nodeType != ltOFFER || metaType == sfCreatedNode) + continue; + + // if either FF or PF are missing we can't compute + // but generally these are cancelled rather than crossed + // so skipping them is consistent + if (!node.isFieldPresent(sfFinalFields) || + !node.isFieldPresent(sfPreviousFields)) + continue; + + STObject& finalFields = (const_cast(node)) + .getField(sfFinalFields) + .downcast(); + + STObject& previousFields = (const_cast(node)) + .getField(sfPreviousFields) + .downcast(); + + // defensive case that should never be hit + if (!finalFields.isFieldPresent(sfTakerGets) || + !finalFields.isFieldPresent(sfTakerPays) || + !previousFields.isFieldPresent(sfTakerGets) || + !previousFields.isFieldPresent(sfTakerPays)) + continue; + + // filter out any offers deleted by explicit offer cancels + if (metaType == sfDeletedNode && offerCancel && + finalFields.getFieldU32(sfSequence) == *offerCancel) + continue; + + // compute the difference in gets and pays actually + // affected onto the offer + STAmount deltaGets = finalFields.getFieldAmount(sfTakerGets) - + previousFields.getFieldAmount(sfTakerGets); + STAmount deltaPays = finalFields.getFieldAmount(sfTakerPays) - + previousFields.getFieldAmount(sfTakerPays); + + std::string g{to_string(deltaGets.issue())}; + std::string p{to_string(deltaPays.issue())}; + + bool const noswap = + isXRP(deltaGets) ? true : (isXRP(deltaPays) ? false : (g < p)); + + STAmount first = noswap ? deltaGets : deltaPays; + STAmount second = noswap ? deltaPays : deltaGets; + + // defensively programmed, should (probably) never happen + if (second == beast::zero) + continue; + + STAmount rate = divide(first, second, noIssue()); + + if (first < beast::zero) + first = -first; + + if (second < beast::zero) + second = -second; + + std::stringstream ss; + if (noswap) + ss << g << "|" << p; + else + ss << p << "|" << g; + + std::string key{ss.str()}; + + if (tally.find(key) == tally.end()) + tally[key] = { + first, // side A vol + second, // side B vol + rate, // high + rate, // low + rate, // open + rate // close + }; + else + { + // increment volume + auto& entry = tally[key]; + + std::get<0>(entry) += first; // side A vol + std::get<1>(entry) += second; // side B vol + + if (std::get<2>(entry) < rate) // high + std::get<2>(entry) = rate; + + if (std::get<3>(entry) > rate) // low + std::get<3>(entry) = rate; + + std::get<5>(entry) = rate; // close + } + } + } + + Json::Value jvObj(Json::objectValue); + jvObj[jss::type] = "bookChanges"; + jvObj[jss::ledger_index] = lpAccepted->info().seq; + jvObj[jss::ledger_hash] = to_string(lpAccepted->info().hash); + jvObj[jss::ledger_time] = Json::Value::UInt( + lpAccepted->info().closeTime.time_since_epoch().count()); + + jvObj[jss::changes] = Json::arrayValue; + + for (auto const& entry : tally) + { + Json::Value& inner = jvObj[jss::changes].append(Json::objectValue); + + STAmount volA = std::get<0>(entry.second); + STAmount volB = std::get<1>(entry.second); + + inner[jss::cur_a] = + (isXRP(volA) ? "XRP_drops" : to_string(volA.issue())); + inner[jss::cur_b] = + (isXRP(volB) ? "XRP_drops" : to_string(volB.issue())); + + inner[jss::vol_a] = + (isXRP(volA) ? to_string(volA.xrp()) : to_string(volA.iou())); + inner[jss::vol_b] = + (isXRP(volB) ? to_string(volB.xrp()) : to_string(volB.iou())); + + inner[jss::high] = to_string(std::get<2>(entry.second).iou()); + inner[jss::low] = to_string(std::get<3>(entry.second).iou()); + inner[jss::open] = to_string(std::get<4>(entry.second).iou()); + inner[jss::close] = to_string(std::get<5>(entry.second).iou()); + } + + return jvObj; +} + +} // namespace RPC +} // namespace ripple + +#endif diff --git a/src/ripple/rpc/handlers/BookOffers.cpp b/src/ripple/rpc/handlers/BookOffers.cpp index a42a0de99..e85b6029b 100644 --- a/src/ripple/rpc/handlers/BookOffers.cpp +++ b/src/ripple/rpc/handlers/BookOffers.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -200,4 +201,16 @@ doBookOffers(RPC::JsonContext& context) return jvResult; } +Json::Value +doBookChanges(RPC::JsonContext& context) +{ + auto res = RPC::getLedgerByContext(context); + + if (std::holds_alternative(res)) + return std::get(res); + + return RPC::computeBookChanges( + std::get>(res)); +} + } // namespace ripple diff --git a/src/ripple/rpc/handlers/Handlers.h b/src/ripple/rpc/handlers/Handlers.h index 1bb3be056..3c00899d7 100644 --- a/src/ripple/rpc/handlers/Handlers.h +++ b/src/ripple/rpc/handlers/Handlers.h @@ -43,6 +43,8 @@ doAccountTxJson(RPC::JsonContext&); Json::Value doBookOffers(RPC::JsonContext&); Json::Value +doBookChanges(RPC::JsonContext&); +Json::Value doBlackList(RPC::JsonContext&); Json::Value doCanDelete(RPC::JsonContext&); diff --git a/src/ripple/rpc/handlers/LedgerRequest.cpp b/src/ripple/rpc/handlers/LedgerRequest.cpp index 3fe238e92..88d26176d 100644 --- a/src/ripple/rpc/handlers/LedgerRequest.cpp +++ b/src/ripple/rpc/handlers/LedgerRequest.cpp @@ -26,7 +26,9 @@ #include #include #include +#include #include +#include namespace ripple { @@ -37,122 +39,17 @@ namespace ripple { Json::Value doLedgerRequest(RPC::JsonContext& context) { - if (context.app.config().reporting()) - return rpcError(rpcREPORTING_UNSUPPORTED); + auto res = getLedgerByContext(context); - auto const hasHash = context.params.isMember(jss::ledger_hash); - auto const hasIndex = context.params.isMember(jss::ledger_index); - std::uint32_t ledgerIndex = 0; + if (std::holds_alternative(res)) + return std::get(res); - auto& ledgerMaster = context.app.getLedgerMaster(); - LedgerHash ledgerHash; + auto const& ledger = std::get>(res); - if ((hasHash && hasIndex) || !(hasHash || hasIndex)) - { - return RPC::make_param_error( - "Exactly one of ledger_hash and ledger_index can be set."); - } - - context.loadType = Resource::feeHighBurdenRPC; - - if (hasHash) - { - auto const& jsonHash = context.params[jss::ledger_hash]; - if (!jsonHash.isString() || !ledgerHash.parseHex(jsonHash.asString())) - return RPC::invalid_field_error(jss::ledger_hash); - } - else - { - auto const& jsonIndex = context.params[jss::ledger_index]; - if (!jsonIndex.isInt()) - return RPC::invalid_field_error(jss::ledger_index); - - // We need a validated ledger to get the hash from the sequence - if (ledgerMaster.getValidatedLedgerAge() > - RPC::Tuning::maxValidatedLedgerAge) - { - if (context.apiVersion == 1) - return rpcError(rpcNO_CURRENT); - return rpcError(rpcNOT_SYNCED); - } - - ledgerIndex = jsonIndex.asInt(); - auto ledger = ledgerMaster.getValidatedLedger(); - - if (ledgerIndex >= ledger->info().seq) - return RPC::make_param_error("Ledger index too large"); - if (ledgerIndex <= 0) - return RPC::make_param_error("Ledger index too small"); - - auto const j = context.app.journal("RPCHandler"); - // Try to get the hash of the desired ledger from the validated ledger - auto neededHash = hashOfSeq(*ledger, ledgerIndex, j); - if (!neededHash) - { - // Find a ledger more likely to have the hash of the desired ledger - auto const refIndex = getCandidateLedger(ledgerIndex); - auto refHash = hashOfSeq(*ledger, refIndex, j); - assert(refHash); - - ledger = ledgerMaster.getLedgerByHash(*refHash); - if (!ledger) - { - // We don't have the ledger we need to figure out which ledger - // they want. Try to get it. - - if (auto il = context.app.getInboundLedgers().acquire( - *refHash, refIndex, InboundLedger::Reason::GENERIC)) - { - Json::Value jvResult = RPC::make_error( - rpcLGR_NOT_FOUND, - "acquiring ledger containing requested index"); - jvResult[jss::acquiring] = - getJson(LedgerFill(*il, &context)); - return jvResult; - } - - if (auto il = context.app.getInboundLedgers().find(*refHash)) - { - Json::Value jvResult = RPC::make_error( - rpcLGR_NOT_FOUND, - "acquiring ledger containing requested index"); - jvResult[jss::acquiring] = il->getJson(0); - return jvResult; - } - - // Likely the app is shutting down - return Json::Value(); - } - - neededHash = hashOfSeq(*ledger, ledgerIndex, j); - } - assert(neededHash); - ledgerHash = neededHash ? *neededHash : beast::zero; // kludge - } - - // Try to get the desired ledger - // Verify all nodes even if we think we have it - auto ledger = context.app.getInboundLedgers().acquire( - ledgerHash, ledgerIndex, InboundLedger::Reason::GENERIC); - - // In standalone mode, accept the ledger from the ledger cache - if (!ledger && context.app.config().standalone()) - ledger = ledgerMaster.getLedgerByHash(ledgerHash); - - if (ledger) - { - // We already had the entire ledger verified/acquired - Json::Value jvResult; - jvResult[jss::ledger_index] = ledger->info().seq; - addJson(jvResult, {*ledger, &context, 0}); - return jvResult; - } - - if (auto il = context.app.getInboundLedgers().find(ledgerHash)) - return il->getJson(0); - - return RPC::make_error( - rpcNOT_READY, "findCreate failed to return an inbound ledger"); + Json::Value jvResult; + jvResult[jss::ledger_index] = ledger->info().seq; + addJson(jvResult, {*ledger, &context, 0}); + return jvResult; } } // namespace ripple diff --git a/src/ripple/rpc/handlers/Subscribe.cpp b/src/ripple/rpc/handlers/Subscribe.cpp index a3c1d1e1c..f17aa62b6 100644 --- a/src/ripple/rpc/handlers/Subscribe.cpp +++ b/src/ripple/rpc/handlers/Subscribe.cpp @@ -136,6 +136,10 @@ doSubscribe(RPC::JsonContext& context) { context.netOps.subLedger(ispSub, jvResult); } + else if (streamName == "book_changes") + { + context.netOps.subBookChanges(ispSub); + } else if (streamName == "manifests") { context.netOps.subManifests(ispSub); diff --git a/src/ripple/rpc/impl/Handler.cpp b/src/ripple/rpc/impl/Handler.cpp index 15f2ea8f8..17a15eed3 100644 --- a/src/ripple/rpc/impl/Handler.cpp +++ b/src/ripple/rpc/impl/Handler.cpp @@ -72,6 +72,7 @@ Handler const handlerArray[]{ {"account_offers", byRef(&doAccountOffers), Role::USER, NO_CONDITION}, {"account_tx", byRef(&doAccountTxJson), Role::USER, NO_CONDITION}, {"blacklist", byRef(&doBlackList), Role::ADMIN, NO_CONDITION}, + {"book_changes", byRef(&doBookChanges), Role::USER, NO_CONDITION}, {"book_offers", byRef(&doBookOffers), Role::USER, NO_CONDITION}, {"can_delete", byRef(&doCanDelete), Role::ADMIN, NO_CONDITION}, {"channel_authorize", byRef(&doChannelAuthorize), Role::USER, NO_CONDITION}, diff --git a/src/ripple/rpc/impl/RPCHandler.cpp b/src/ripple/rpc/impl/RPCHandler.cpp index b04a6f0ed..c7984f830 100644 --- a/src/ripple/rpc/impl/RPCHandler.cpp +++ b/src/ripple/rpc/impl/RPCHandler.cpp @@ -17,7 +17,9 @@ */ //============================================================================== +#include #include +#include #include #include #include @@ -30,14 +32,17 @@ #include #include #include +#include #include #include +#include #include #include #include #include #include #include +#include namespace ripple { namespace RPC { diff --git a/src/ripple/rpc/impl/RPCHelpers.cpp b/src/ripple/rpc/impl/RPCHelpers.cpp index 6958ce9d9..77255a5e6 100644 --- a/src/ripple/rpc/impl/RPCHelpers.cpp +++ b/src/ripple/rpc/impl/RPCHelpers.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include +#include #include namespace ripple { @@ -956,5 +958,119 @@ getAPIVersionNumber(Json::Value const& jv, bool betaEnabled) return requestedVersion.asUInt(); } +std::variant, Json::Value> +getLedgerByContext(RPC::JsonContext& context) +{ + if (context.app.config().reporting()) + return rpcError(rpcREPORTING_UNSUPPORTED); + + auto const hasHash = context.params.isMember(jss::ledger_hash); + auto const hasIndex = context.params.isMember(jss::ledger_index); + std::uint32_t ledgerIndex = 0; + + auto& ledgerMaster = context.app.getLedgerMaster(); + LedgerHash ledgerHash; + + if ((hasHash && hasIndex) || !(hasHash || hasIndex)) + { + return RPC::make_param_error( + "Exactly one of ledger_hash and ledger_index can be set."); + } + + context.loadType = Resource::feeHighBurdenRPC; + + if (hasHash) + { + auto const& jsonHash = context.params[jss::ledger_hash]; + if (!jsonHash.isString() || !ledgerHash.parseHex(jsonHash.asString())) + return RPC::invalid_field_error(jss::ledger_hash); + } + else + { + auto const& jsonIndex = context.params[jss::ledger_index]; + if (!jsonIndex.isInt()) + return RPC::invalid_field_error(jss::ledger_index); + + // We need a validated ledger to get the hash from the sequence + if (ledgerMaster.getValidatedLedgerAge() > + RPC::Tuning::maxValidatedLedgerAge) + { + if (context.apiVersion == 1) + return rpcError(rpcNO_CURRENT); + return rpcError(rpcNOT_SYNCED); + } + + ledgerIndex = jsonIndex.asInt(); + auto ledger = ledgerMaster.getValidatedLedger(); + + if (ledgerIndex >= ledger->info().seq) + return RPC::make_param_error("Ledger index too large"); + if (ledgerIndex <= 0) + return RPC::make_param_error("Ledger index too small"); + + auto const j = context.app.journal("RPCHandler"); + // Try to get the hash of the desired ledger from the validated ledger + auto neededHash = hashOfSeq(*ledger, ledgerIndex, j); + if (!neededHash) + { + // Find a ledger more likely to have the hash of the desired ledger + auto const refIndex = getCandidateLedger(ledgerIndex); + auto refHash = hashOfSeq(*ledger, refIndex, j); + assert(refHash); + + ledger = ledgerMaster.getLedgerByHash(*refHash); + if (!ledger) + { + // We don't have the ledger we need to figure out which ledger + // they want. Try to get it. + + if (auto il = context.app.getInboundLedgers().acquire( + *refHash, refIndex, InboundLedger::Reason::GENERIC)) + { + Json::Value jvResult = RPC::make_error( + rpcLGR_NOT_FOUND, + "acquiring ledger containing requested index"); + jvResult[jss::acquiring] = + getJson(LedgerFill(*il, &context)); + return jvResult; + } + + if (auto il = context.app.getInboundLedgers().find(*refHash)) + { + Json::Value jvResult = RPC::make_error( + rpcLGR_NOT_FOUND, + "acquiring ledger containing requested index"); + jvResult[jss::acquiring] = il->getJson(0); + return jvResult; + } + + // Likely the app is shutting down + return Json::Value(); + } + + neededHash = hashOfSeq(*ledger, ledgerIndex, j); + } + assert(neededHash); + ledgerHash = neededHash ? *neededHash : beast::zero; // kludge + } + + // Try to get the desired ledger + // Verify all nodes even if we think we have it + auto ledger = context.app.getInboundLedgers().acquire( + ledgerHash, ledgerIndex, InboundLedger::Reason::GENERIC); + + // In standalone mode, accept the ledger from the ledger cache + if (!ledger && context.app.config().standalone()) + ledger = ledgerMaster.getLedgerByHash(ledgerHash); + + if (ledger) + return ledger; + + if (auto il = context.app.getInboundLedgers().find(ledgerHash)) + return il->getJson(0); + + return RPC::make_error( + rpcNOT_READY, "findCreate failed to return an inbound ledger"); +} } // namespace RPC } // namespace ripple diff --git a/src/ripple/rpc/impl/RPCHelpers.h b/src/ripple/rpc/impl/RPCHelpers.h index e3d44c2e7..2aa62f347 100644 --- a/src/ripple/rpc/impl/RPCHelpers.h +++ b/src/ripple/rpc/impl/RPCHelpers.h @@ -31,6 +31,7 @@ #include #include #include +#include namespace Json { class Value; @@ -287,6 +288,11 @@ chooseLedgerEntryType(Json::Value const& params); unsigned int getAPIVersionNumber(const Json::Value& value, bool betaEnabled); +/** Return a ledger based on ledger_hash or ledger_index, + or an RPC error */ +std::variant, Json::Value> +getLedgerByContext(RPC::JsonContext& context); + } // namespace RPC } // namespace ripple