feat: allow for accountsdb checksum computation#990
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds AccountsDb::checksum() returning a deterministic u64 by acquiring the write lock, iterating all active accounts in LMDB key-sorted order, and hashing pubkey bytes plus serialized account data using xxHash3 (twox-hash). Adds twox-hash dependency and unit tests verifying determinism and detection of state changes. Changes storage.size_bytes() to return the active data segment length rather than allocated capacity. Updates solana-account revision in workspace and test-integration Cargo.toml files. Assessment against linked issues
Out-of-scope changes
Suggested reviewers
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@magicblock-accounts-db/src/lib.rs`:
- Around line 386-397: Change checksum() to return AccountsDbResult<u64> (not
u64), propagate any LMDB/index errors instead of swallowing them, and surface
failures from iter_all() rather than treating an empty iterator as success;
specifically update checksum() to call the underlying index/get_all_accounts
path in a fallible way and return Err(...) on any index/LMDB error. While
iterating accounts inside checksum(), do not silently skip Owned accounts: when
acc.as_borrowed() is None, emit a tracing::error! (including the pubkey) and
return an Err variant indicating an unexpected Owned account (so callers see the
failure). Keep the existing hashing logic (xxhash3_64::Hasher) for Borrowed
accounts only, but ensure all error paths map to AccountsDbResult and are
returned to the caller.
In `@magicblock-accounts-db/src/storage.rs`:
- Around line 374-377: The current size_bytes() change breaks reload() because
it uses active_segment().len() (used bytes) to grow the snapshot file, shrinking
capacity after rollback; update reload() to ensure the file is grown to the full
mmap extent instead of calling size_bytes(): call ensure_file_size(...) with the
full configured size (compute from the configured capacity_blocks × block_size +
METADATA_STORAGE_SIZE or use the stored mmap extent/initial file size) so
map_file recomputes capacity_blocks from the original full allocation; keep
size_bytes() semantics if it must represent used bytes, but do not use it in
reload(); also adjust or add a test (e.g. test_db_size_after_rollback) to
exercise an actual rollback (target_slot < current slot) to verify capacity is
preserved.
In `@magicblock-accounts-db/src/tests.rs`:
- Around line 513-521: The second assertion is comparing env.checksum() to
original_checksum even though accounts[5] was already mutated, so save the
intermediate checksum immediately after inserting accounts[5] (e.g., let
intermediate_checksum = env.checksum()) and then modify
accounts[10].1.set_lamports(...) and env.insert_account(&accounts[10].0,
&accounts[10].1).unwrap(); finally assert_ne!(env.checksum(),
intermediate_checksum, "checksum must detect lamport change") to ensure the
lamport mutation on accounts[10] is the change being tested.
180ce94 to
3ed3c71
Compare
There was a problem hiding this comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@magicblock-accounts-db/src/lib.rs`:
- Around line 386-397: Change checksum() to return AccountsDbResult<u64> and
propagate LMDB/iteration errors instead of silently returning an empty checksum:
call iter_all() and if it returns Err (originating from
self.index.get_all_accounts()) return that error wrapped with context; when
iterating, treat acc.as_borrowed() returning None as an error (do not continue
silently) and return a descriptive AccountsDbError indicating a failed account
borrow/unsupported Owned variant (include pubkey info). Keep using
xxhash3_64::Hasher but only finish and Ok(hasher.finish()) on success; update
callers to handle the AccountsDbResult<u64>.
In `@magicblock-accounts-db/src/storage.rs`:
- Around line 374-377: size_bytes() now returns only the active-used portion
(cursor*block_size + METADATA_STORAGE_SIZE) which causes reload() (which calls
ensure_file_size and then map_file that computes capacity_blocks = (file_size -
METADATA_STORAGE_SIZE) / block_size) to see a reduced file_size after rollbacks
and incorrectly shrink capacity; fix reload() so it uses the actual on-disk file
length (e.g., via file metadata or the raw segment file length) when calling
ensure_file_size/map_file instead of self.size_bytes(), leaving size_bytes()
semantics unchanged; update references in reload(), ensure_file_size/map_file
invocation, and any logic around capacity_blocks/METADATA_STORAGE_SIZE to read
the real file size rather than active_segment()/size_bytes().
In `@magicblock-accounts-db/src/tests.rs`:
- Around line 518-527: The test's second assertion doesn't isolate the lamport
change because env.checksum() already diverged after mutating and committing
accounts[5]; capture the checksum immediately after the accounts[5] commit
(e.g., let checksum_after_commit = env.checksum()) and then mutate accounts[10]
via accounts[10].1.set_lamports(...) and env.insert_account(...), then
assert_ne!(env.checksum(), checksum_after_commit) to ensure the assertion
specifically tests the lamports change; reference env.checksum,
accounts[10].1.set_lamports, env.insert_account and
original_checksum/accounts[5] to locate the relevant lines.
bd19a3e to
fb9bd0b
Compare
25651e8 to
5f00021
Compare
e81ba66 to
ac34a0f
Compare
5f00021 to
1d4ffb8
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@magicblock-accounts-db/src/storage.rs`:
- Around line 374-376: The method size_bytes() currently returns
active_segment().len() (the occupied/used space) which is misleading; rename
size_bytes() to used_bytes() (or another clear name) and update all call sites
to use the new name, keeping the implementation returning
self.active_segment().len() as u64; search for references to size_bytes(),
active_segment(), and any docs/comments in the Storage struct to update names
and wording to reflect "used bytes" semantics.
In `@magicblock-accounts-db/src/tests.rs`:
- Around line 477-485: The test currently inserts the same 50 accounts into db1
and db2 in identical order; change it so insertion order differs between the two
DBs to catch order-sensitive iteration bugs by first producing the set of
keys/accounts (using Pubkey::new_unique and AccountSharedData::new as currently
done), then insert them into db1 in one order and into db2 in a different order
(e.g., reverse the vector or shuffle using a deterministic RNG) before calling
db1.insert_account and db2.insert_account, so the same logical dataset is
present but insertion order differs.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (2)
Cargo.lockis excluded by!**/*.locktest-integration/Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (6)
Cargo.tomlmagicblock-accounts-db/Cargo.tomlmagicblock-accounts-db/src/lib.rsmagicblock-accounts-db/src/storage.rsmagicblock-accounts-db/src/tests.rstest-integration/Cargo.toml
ac34a0f to
a1d4b8a
Compare
93c53dc to
6e4f626
Compare
6e4f626 to
7912dff
Compare
34af2ce to
ed80def
Compare
* master: Fix: explorer rendering for failed transactions (#1032) feat: forward original bincoded transaction (#991) Improve commit limit exceeded error message (#1029) feat: allow for accountsdb checksum computation (#990) feat: modify account cloning to use transactions (#974) feat: backfill-aware subscriptions and throttled alerts (#1025) feat(committor): enforce per-account commit limit via MagicSys syscall (#1024) refactor: replace BaseTask trait objects with BaseTaskImpl enum (#973) fix: serialize nan for explorer compatibility (#1021)

Summary
Adds method to compute the checksum of current state of accountsdb.
The checksum computation is performed after acquisition of global lock.
Compatibility
Testing
Checklist
Summary by CodeRabbit
New Features
Improvements
Tests