From 4bea07f66263bd9914d02fd7cbfba233d5571141 Mon Sep 17 00:00:00 2001 From: Nicholas Dudfield Date: Fri, 18 Sep 2026 11:44:49 +0700 Subject: [PATCH] feat(shamap): inject Family PRNG into missing-node walks NodeFamily forwards Application::getPrng. SHAMapSync draws first-child offsets from that engine. TestNodeFamily keeps default_prng. --- src/test/shamap/common.h | 7 +++++++ src/xrpld/shamap/Family.h | 4 ++++ src/xrpld/shamap/NodeFamily.h | 3 +++ src/xrpld/shamap/detail/NodeFamily.cpp | 6 ++++++ src/xrpld/shamap/detail/SHAMapSync.cpp | 6 +++--- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/test/shamap/common.h b/src/test/shamap/common.h index 86acc8e2b0..1c2d21b928 100644 --- a/src/test/shamap/common.h +++ b/src/test/shamap/common.h @@ -24,6 +24,7 @@ #include #include #include +#include namespace ripple { namespace tests { @@ -80,6 +81,12 @@ public: return j_; } + beast::xor_shift_engine& + prng() override + { + return default_prng(); + } + std::shared_ptr getFullBelowCache() override { diff --git a/src/xrpld/shamap/Family.h b/src/xrpld/shamap/Family.h index bbb22c273d..ca76b9d95b 100644 --- a/src/xrpld/shamap/Family.h +++ b/src/xrpld/shamap/Family.h @@ -25,6 +25,7 @@ #include #include #include +#include #include namespace ripple { @@ -53,6 +54,9 @@ public: virtual beast::Journal const& journal() = 0; + virtual beast::xor_shift_engine& + prng() = 0; + /** Return a pointer to the Family Full Below Cache */ virtual std::shared_ptr getFullBelowCache() = 0; diff --git a/src/xrpld/shamap/NodeFamily.h b/src/xrpld/shamap/NodeFamily.h index 4062ea2389..68b51e732f 100644 --- a/src/xrpld/shamap/NodeFamily.h +++ b/src/xrpld/shamap/NodeFamily.h @@ -60,6 +60,9 @@ public: return j_; } + beast::xor_shift_engine& + prng() override; + std::shared_ptr getFullBelowCache() override { diff --git a/src/xrpld/shamap/detail/NodeFamily.cpp b/src/xrpld/shamap/detail/NodeFamily.cpp index faa5c2e360..6ccc7eb873 100644 --- a/src/xrpld/shamap/detail/NodeFamily.cpp +++ b/src/xrpld/shamap/detail/NodeFamily.cpp @@ -46,6 +46,12 @@ NodeFamily::NodeFamily(Application& app, CollectorManager& cm) { } +beast::xor_shift_engine& +NodeFamily::prng() +{ + return app_.getPrng(); +} + void NodeFamily::sweep() { diff --git a/src/xrpld/shamap/detail/SHAMapSync.cpp b/src/xrpld/shamap/detail/SHAMapSync.cpp index 4f93825751..223125c55f 100644 --- a/src/xrpld/shamap/detail/SHAMapSync.cpp +++ b/src/xrpld/shamap/detail/SHAMapSync.cpp @@ -235,7 +235,7 @@ SHAMap::gmn_ProcessNodes(MissingNodes& mn, MissingNodes::StackEntry& se) // Switch to processing the child node node = static_cast(d); nodeID = nodeID.getChildNodeID(branch); - firstChild = rand_int(255); + firstChild = rand_int(f_.prng(), 255); currentChild = 0; fullBelow = true; } @@ -342,7 +342,7 @@ SHAMap::getMissingNodes(int max, SHAMapSyncFilter* filter) MissingNodes::StackEntry pos{ static_cast(root_.get()), SHAMapNodeID(), - rand_int(255), + rand_int(f_.prng(), 255), 0, true}; auto& node = std::get<0>(pos); @@ -399,7 +399,7 @@ SHAMap::getMissingNodes(int max, SHAMapSyncFilter* filter) for (auto const& [innerNode, nodeId] : mn.resumes_) if (!innerNode->isFullBelow(mn.generation_)) mn.stack_.push(std::make_tuple( - innerNode, nodeId, rand_int(255), 0, true)); + innerNode, nodeId, rand_int(f_.prng(), 255), 0, true)); mn.resumes_.clear(); }