From 05f961c77cc5fb5637207754f5d3e005a8d75605 Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Mon, 19 Dec 2022 16:45:13 +0000 Subject: [PATCH] first half of XPOP_HISTORY --- src/ripple/app/misc/NetworkOPs.cpp | 34 ++++++++++++++++++++++++++ src/ripple/core/Config.h | 4 +++ src/ripple/core/ConfigSections.h | 1 + src/ripple/core/impl/Config.cpp | 3 +++ src/ripple/protocol/SystemParameters.h | 2 +- 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index 2c9819f0b..587746392 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -79,6 +79,9 @@ namespace ripple { class NetworkOPsImp final : public NetworkOPs { + // ledger_seq -> validator key -> validation message + std::map> xpop_history; + /** * Transaction with input flags and results to be applied in batches. */ @@ -2325,6 +2328,37 @@ NetworkOPsImp::recvValidation( handleNewValidation(app_, val, source); + // manage xpop validation history + if (app_.config().XPOP_HISTORY) + { + if (val->isTrusted()) + { + uint32_t seq = val->getFieldU32(sfLedgerSequence); + + if (xpop_history.find(seq) == xpop_history.end()) + xpop_history.emplace(seq, std::map{}); + + xpop_history[seq].emplace(val->getSignerPublic(), *val); + } + + uint32_t delete_threshold = + app_.getLedgerMaster().getValidLedgerIndex() + 1 - *(app_.config().XPOP_HISTORY); + + if (xpop_history.find(delete_threshold) != xpop_history.end()) + xpop_history.erase(delete_threshold); + + if (xpop_history.size() > *(app_.config().XPOP_HISTORY)) + { + std::unordered_set to_delete; + for (auto const& kp : xpop_history) + if (kp.first < delete_threshold) + to_delete.emplace(kp.first); + + for (uint32_t td: to_delete) + xpop_history.erase(td); + } + } + pubValidation(val); // We will always relay trusted validations; if configured, we will diff --git a/src/ripple/core/Config.h b/src/ripple/core/Config.h index 2d440a1af..c7ec6f631 100644 --- a/src/ripple/core/Config.h +++ b/src/ripple/core/Config.h @@ -152,6 +152,10 @@ public: int RELAY_UNTRUSTED_VALIDATIONS = 1; int RELAY_UNTRUSTED_PROPOSALS = 0; + // The number of ledgers worth of valdiations to keep for the purpose + // of servicing xpop requests these are lost on restart + std::optional XPOP_HISTORY; + // True to ask peers not to relay current IP. bool PEER_PRIVATE = false; // peers_max is a legacy configuration, which is going to be replaced diff --git a/src/ripple/core/ConfigSections.h b/src/ripple/core/ConfigSections.h index ba0f209c0..41bee720c 100644 --- a/src/ripple/core/ConfigSections.h +++ b/src/ripple/core/ConfigSections.h @@ -101,6 +101,7 @@ struct ConfigSection #define SECTION_LEDGER_REPLAY "ledger_replay" #define SECTION_BETA_RPC_API "beta_rpc_api" #define SECTION_SWEEP_INTERVAL "sweep_interval" +#define SECTION_XPOP_HISTORY "xpop_history" } // namespace ripple diff --git a/src/ripple/core/impl/Config.cpp b/src/ripple/core/impl/Config.cpp index 9cdb17d4e..7024bb8e3 100644 --- a/src/ripple/core/impl/Config.cpp +++ b/src/ripple/core/impl/Config.cpp @@ -481,6 +481,9 @@ Config::loadFromString(std::string const& fileContents) std::string strTemp; + if (getSingleSection(secConfig, SECTION_XPOP_HISTORY, strTemp, j_)) + XPOP_HISTORY = beast::lexicalCastThrow(strTemp); + if (getSingleSection(secConfig, SECTION_PEER_PRIVATE, strTemp, j_)) PEER_PRIVATE = beast::lexicalCastThrow(strTemp); diff --git a/src/ripple/protocol/SystemParameters.h b/src/ripple/protocol/SystemParameters.h index cd76970e9..91121022c 100644 --- a/src/ripple/protocol/SystemParameters.h +++ b/src/ripple/protocol/SystemParameters.h @@ -73,7 +73,7 @@ constexpr std::ratio<204, 256> preFixAmendmentMajorityCalcThreshold; constexpr std::ratio<80, 100> postFixAmendmentMajorityCalcThreshold; /** The minimum amount of time an amendment must hold a majority */ -constexpr std::chrono::seconds const defaultAmendmentMajorityTime = weeks{2}; +constexpr std::chrono::seconds const defaultAmendmentMajorityTime = days{5}; } // namespace ripple