Sponsored Content
Skip to content

refactor: Use uint256 directly as key instead of void pointer - #6313

Merged
bthomee merged 28 commits into
developfrom
bthomee/key
Feb 25, 2026
Merged

refactor: Use uint256 directly as key instead of void pointer#6313
bthomee merged 28 commits into
developfrom
bthomee/key

Conversation

@bthomee

@bthomee bthomee commented Feb 2, 2026

Copy link
Copy Markdown
Collaborator

High Level Overview of Change

This change replaces void const* by uint256 const& for database fetches.

Context of Change

Object hashes are expressed using the uint256 data type, and are converted to void * when calling the fetch or fetchBatch functions. However, in these fetch functions they are converted back to uint256, making the conversion process unnecessary. In a few cases the underlying pointer is needed, but that can then be easy obtained via [hash variable].data().

I tested this change with both NuDB and RocksDB using an existing database, and the binary was able to use those databases and proceed to sync with the network.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Performance (increase or change in throughput and/or latency)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)
  • Documentation update
  • Chore (no impact to binary, e.g. .gitignore, formatting, dropping support for older tooling)
  • Release

Copilot AI review requested due to automatic review settings February 2, 2026 16:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the nodestore backend API to use uint256 const& directly instead of void const* for database fetch operations, eliminating unnecessary pointer conversions.

Changes:

  • Updated the Backend interface to accept uint256 const& instead of void const* for fetch() and fetchBatch() methods
  • Modified all backend implementations (RocksDB, NuDB, Memory, Null) to use the new signature
  • Updated all callers to pass hash objects directly instead of using .data() or .begin()
  • Removed unnecessary pointer vector conversion code in DatabaseNodeImp::fetchBatch()
  • Improved variable naming from "key" to "hash" in test files for better semantic clarity

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
include/xrpl/nodestore/Backend.h Updated virtual method signatures and documentation for fetch() and fetchBatch() to use uint256 const&
src/libxrpl/nodestore/backend/RocksDBFactory.cpp Updated implementation to accept uint256 const&, using hash.data() for RocksDB Slice and DecodedBlob
src/libxrpl/nodestore/backend/NullFactory.cpp Updated null backend stub implementation signatures
src/libxrpl/nodestore/backend/NuDBFactory.cpp Updated implementation to accept uint256 const&, using hash.data() for NuDB API and DecodedBlob
src/libxrpl/nodestore/backend/MemoryFactory.cpp Removed unnecessary fromVoid() conversion and updated signatures
src/libxrpl/nodestore/DatabaseRotatingImp.cpp Updated caller to pass hash directly instead of hash.data()
src/libxrpl/nodestore/DatabaseNodeImp.cpp Updated caller and removed redundant pointer vector creation in fetchBatch()
src/test/nodestore/TestBase.h Updated test helper to pass hash directly and removed .cbegin() calls
src/test/nodestore/Timing_test.cpp Updated test code to use "hash" variable naming and pass hash directly, removing .data() calls

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bthomee
bthomee requested a review from vlntb February 2, 2026 16:51
@codecov

codecov Bot commented Feb 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.14286% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.8%. Comparing base (65e63eb) to head (a70f546).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
src/libxrpl/nodestore/backend/MemoryFactory.cpp 33.3% 2 Missing ⚠️
src/libxrpl/nodestore/backend/NuDBFactory.cpp 66.7% 2 Missing ⚠️
src/libxrpl/nodestore/backend/NullFactory.cpp 0.0% 2 Missing ⚠️
src/libxrpl/nodestore/backend/RocksDBFactory.cpp 71.4% 2 Missing ⚠️
src/libxrpl/nodestore/DatabaseNodeImp.cpp 50.0% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #6313   +/-   ##
=======================================
  Coverage     79.8%   79.8%           
=======================================
  Files          848     848           
  Lines        67763   67757    -6     
  Branches      7578    7553   -25     
=======================================
- Hits         54077   54074    -3     
+ Misses       13686   13683    -3     
Files with missing lines Coverage Δ
include/xrpl/nodestore/Backend.h 14.3% <ø> (ø)
src/libxrpl/nodestore/DatabaseRotatingImp.cpp 63.9% <100.0%> (ø)
src/libxrpl/nodestore/DatabaseNodeImp.cpp 39.5% <50.0%> (+4.6%) ⬆️
src/libxrpl/nodestore/backend/MemoryFactory.cpp 67.6% <33.3%> (-0.5%) ⬇️
src/libxrpl/nodestore/backend/NuDBFactory.cpp 64.3% <66.7%> (+0.2%) ⬆️
src/libxrpl/nodestore/backend/NullFactory.cpp 20.7% <0.0%> (ø)
src/libxrpl/nodestore/backend/RocksDBFactory.cpp 50.0% <71.4%> (+0.3%) ⬆️

... and 4 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bthomee
bthomee requested a review from godexsoft February 2, 2026 18:38

@vlntb vlntb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The change improves type safety by replacing void const* with uint256 const&, follows East const notation, and eliminates unnecessary temporary vectors.

Base automatically changed from bthomee/disable-cache to develop February 6, 2026 14:42
@bthomee
bthomee requested a review from a team February 6, 2026 14:42
Copilot AI review requested due to automatic review settings February 11, 2026 14:16
@bthomee
bthomee requested a review from a1q123456 February 11, 2026 14:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread include/xrpl/nodestore/Backend.h
Comment thread src/test/nodestore/Timing_test.cpp Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 11, 2026 15:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@godexsoft godexsoft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks like a good idea. If you want to allow the old API then we could add overloads for each function to take the old void* and pass them to the new functions.
Definitely try to get rid of reinterpret_cast 👍


rocksdb::ReadOptions const options;
rocksdb::Slice const slice(static_cast<char const*>(key), m_keyBytes);
rocksdb::Slice const slice(reinterpret_cast<char const*>(hash.data()), m_keyBytes);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to avoid reinterpret_cast. It's only good as last resort.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to std::bit_cast, as the to and from types are trivially copyable and have the same size.

  • hash: is our custom uint256, which is aliased to our base_uint<256> and wraps a std::array<std::uint32_t, WIDTH> data_; with WIDTH = 256/32 = 8.
  • hash.data(): calls reinterpret_cast<const_pointer>(data_.data()), whereby it takes the uint32_t const* and casts it to unsigned char const*.
  • The std::bit_cast<char const*> then converts unsigned char const* to a char const*, as needed by RocksDB.

I built and tested the binary locally and was able to sync up with testnet using RocksDB. While this is not the ultimate test, it's a good sanity check.

@bthomee
bthomee requested a review from godexsoft February 12, 2026 20:28

@a1q123456 a1q123456 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copilot AI review requested due to automatic review settings February 25, 2026 21:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


rocksdb::ReadOptions const options;
rocksdb::Slice const slice(static_cast<char const*>(key), m_keyBytes);
rocksdb::Slice const slice(std::bit_cast<char const*>(hash.data()), m_keyBytes);

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of std::bit_cast here is inconsistent with the existing code in this file. Lines 335 and 337 use reinterpret_cast for similar pointer casts when creating rocksdb::Slice objects. For consistency with the established pattern in this codebase, consider using reinterpret_cast instead of std::bit_cast here.

Suggested change
rocksdb::Slice const slice(std::bit_cast<char const*>(hash.data()), m_keyBytes);
rocksdb::Slice const slice(reinterpret_cast<char const*>(hash.data()), m_keyBytes);

Copilot uses AI. Check for mistakes.
key,
[key, pno, &status](void const* data, std::size_t size) {
hash.data(),
[hash, pno, &status](void const* data, std::size_t size) {

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lambda now captures hash by value, which copies 32 bytes of data. Since the lambda is invoked synchronously within the db_.fetch call (as evidenced by the use of the status variable after the call returns), capturing hash by reference (&hash) would be more efficient and equally safe. Consider changing the capture to [&hash, pno, &status] to avoid the unnecessary copy.

Suggested change
[hash, pno, &status](void const* data, std::size_t size) {
[&hash, pno, &status](void const* data, std::size_t size) {

Copilot uses AI. Check for mistakes.

@godexsoft godexsoft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:rage1:

@ximinez ximinez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks safe

@bthomee
bthomee merged commit 3a8a18c into develop Feb 25, 2026
2 of 3 checks passed
@bthomee
bthomee deleted the bthomee/key branch February 25, 2026 23:23
@mvadari mvadari added this to the 3.2.0 milestone May 20, 2026
beartec-jpg pushed a commit to beartec-jpg/FalconLedger that referenced this pull request Jun 1, 2026
…6313)

This change replaces `void const*` by `uint256 const&` for database fetches.

Object hashes are expressed using the `uint256` data type, and are converted to `void *` when calling the `fetch` or `fetchBatch` functions. However, in these fetch functions they are converted back to `uint256`, making the conversion process unnecessary. In a few cases the underlying pointer is needed, but that can then be easy obtained via `[hash variable].data()`.
@bthomee bthomee mentioned this pull request Jun 26, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants