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.
This commit is contained in:
Nicholas Dudfield
2026-09-18 11:44:49 +07:00
parent 8e2907f231
commit 4bea07f662
5 changed files with 23 additions and 3 deletions

View File

@@ -24,6 +24,7 @@
#include <xrpld/nodestore/Manager.h>
#include <xrpld/shamap/Family.h>
#include <xrpl/basics/chrono.h>
#include <xrpl/basics/random.h>
namespace ripple {
namespace tests {
@@ -80,6 +81,12 @@ public:
return j_;
}
beast::xor_shift_engine&
prng() override
{
return default_prng();
}
std::shared_ptr<FullBelowCache>
getFullBelowCache() override
{

View File

@@ -25,6 +25,7 @@
#include <xrpld/shamap/TreeNodeCache.h>
#include <xrpl/basics/Log.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/beast/xor_shift_engine.h>
#include <cstdint>
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<FullBelowCache>
getFullBelowCache() = 0;

View File

@@ -60,6 +60,9 @@ public:
return j_;
}
beast::xor_shift_engine&
prng() override;
std::shared_ptr<FullBelowCache>
getFullBelowCache() override
{

View File

@@ -46,6 +46,12 @@ NodeFamily::NodeFamily(Application& app, CollectorManager& cm)
{
}
beast::xor_shift_engine&
NodeFamily::prng()
{
return app_.getPrng();
}
void
NodeFamily::sweep()
{

View File

@@ -235,7 +235,7 @@ SHAMap::gmn_ProcessNodes(MissingNodes& mn, MissingNodes::StackEntry& se)
// Switch to processing the child node
node = static_cast<SHAMapInnerNode*>(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<SHAMapInnerNode*>(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();
}