Harden bucket index handling with helpers and bounds checks#12
Merged
laurenshareshian merged 1 commit intomainfrom Mar 19, 2026
Merged
Harden bucket index handling with helpers and bounds checks#12laurenshareshian merged 1 commit intomainfrom
laurenshareshian merged 1 commit intomainfrom
Conversation
Add toArrayIndex/toBucketIndex helpers to replace raw BUCKET_MAX - bucket arithmetic, guard against out-of-bounds bucket indices from the public MempoolSnapshot API, and assert BUCKET_MIN matches its documented derivation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
aicamargo
approved these changes
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
toArrayIndex/toBucketIndexhelpers toBucketCreatorto replace rawBUCKET_MAX - bucketarithmetic scattered across the codebaseMempoolSnapshotAPI by checking both lower and upper bounds (BUCKET_MIN..BUCKET_MAX)BUCKET_MINmatches its documented derivation (round(ln(0.1) * 100))Context
Follow-up hardening from PR #10 (sub-1 sat/vB support). The previous PR only guarded
bucket >= BUCKET_MIN, leaving the upper bound unchecked — a caller using the publicMempoolSnapshotconstructor with a bucket >BUCKET_MAXwould cause a negative array index crash.Test plan
test BUCKET_MIN matches ln(0_1) times 100 rounded— validates constant derivationfromMempoolSnapshot drops buckets above BUCKET_MAX— confirms oversized buckets are silently dropped🤖 Generated with Claude Code