bugfix: restore node_db_prefix's previous prefix/suffix calculation#476
Conversation
a30e20e to
7553912
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughRefactors Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/lib/src/model/merkle_tree/merkle_hash.rs`:
- Around line 128-130: node_db_prefix() can return a single-segment path when
hash_str is too short; ensure a true 2-level path by guaranteeing dir_suffix is
never empty: if hash_str.len() <= DIR_PREFIX_LEN then left-pad the hex string
with leading '0's up to DIR_PREFIX_LEN + 1 before computing dir_prefix and
dir_suffix (use the existing DIR_PREFIX_LEN, node_db_prefix(), dir_prefix and
dir_suffix symbols to locate the logic). Also add deterministic unit tests for
short values (< 0x1000) such as 0x0, 0xa, 0xff, 0xabc to assert the returned
Path always has two segments.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6a160176-2481-47f4-8032-9b85377e8fb9
📒 Files selected for processing (1)
crates/lib/src/model/merkle_tree/merkle_hash.rs
7553912 to
23517f3
Compare
The hexadecimal formatting for `MerkleHash` does not fix the size of the resulting string. Leading 0s are dropped. This means that `node_db_prefix` could index into a string that is shorter than 4 characters, causing a panic. This PR restores the previous hash directory prefix and suffix calculation. Hash values that are smaller than 4 hex characters can result in malformed or empty-string named directories. Additionally, the `test_hex_hash_conversions_and_node_db_prefix` test was fixed to correctly run 1k randomized `MerkleHash` -> `HexHash` conversions. Before, it was only running a single randomized conversion.
23517f3 to
774bb26
Compare
The hexadecimal formatting for
MerkleHashdoes not fix the size of the resulting string.Leading 0s are dropped. This means that
node_db_prefixcould index into a string thatis shorter than 4 characters, causing a panic. This PR restores the previous hash directory
prefix and suffix calculation. Hash values that are smaller than 4 hex characters can result
in malformed or empty-string named directories.
Additionally, the
test_hex_hash_conversions_and_node_db_prefixtest was fixed tocorrectly run 1k randomized
MerkleHash->HexHashconversions. Before, it was onlyrunning a single randomized conversion.