Skip to content

state-diff configs & kv functions#15903

Merged
Inspector-Butters merged 9 commits into
developfrom
state-diff-configs
Nov 19, 2025
Merged

state-diff configs & kv functions#15903
Inspector-Butters merged 9 commits into
developfrom
state-diff-configs

Conversation

@Inspector-Butters

@Inspector-Butters Inspector-Butters commented Oct 20, 2025

Copy link
Copy Markdown
Contributor

What type of PR is this?
Feature

What does this PR do? Why is it needed?

  • This PR adds the initial configuration needed for the state diff feature to work.
  • It also adds the kv functions needed.

Note for reviewers:
Please review commit by commit.

Comment thread config/features/flags.go Outdated
Comment thread cmd/beacon-chain/flags/config.go Outdated
Comment thread cmd/beacon-chain/flags/config.go Outdated
Comment thread cmd/beacon-chain/flags/config.go Outdated
Comment thread cmd/beacon-chain/flags/config.go Outdated
Comment thread cmd/beacon-chain/main.go Outdated

@potuz potuz 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.

Config looks good, can we add the db paths to this PR?

@Inspector-Butters Inspector-Butters changed the title state-diff configs state-diff configs & kv functions Nov 3, 2025
Comment thread beacon-chain/db/kv/state_diff.go Outdated
Comment thread beacon-chain/db/kv/state_diff.go Outdated
Comment thread beacon-chain/db/kv/state_diff.go
Comment thread beacon-chain/db/kv/state_diff.go Outdated
Comment thread beacon-chain/db/kv/state_diff_cache.go Outdated
Comment thread beacon-chain/db/kv/state_diff_helpers.go
Comment thread beacon-chain/db/kv/state_diff_helpers.go Outdated
Comment thread beacon-chain/db/kv/state_diff_helpers.go Outdated
Comment thread beacon-chain/db/kv/state_diff_helpers.go Outdated
Comment thread beacon-chain/db/kv/state_diff_helpers.go Outdated
potuz
potuz previously approved these changes Nov 17, 2025

@prestonvanloon prestonvanloon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Partial review.

I am concerned about under/overflow checks. I would accept this in the validation of the flag inputs, but prefer that you defensively check over/underflows in the kv package.

Comment thread cmd/beacon-chain/flags/config.go
Comment thread cmd/beacon-chain/flags/config_test.go Outdated
Comment thread beacon-chain/db/kv/state_diff_helpers.go Outdated
Comment thread beacon-chain/db/kv/state_diff_helpers.go Outdated
ErrSlotBeforeOffset = errors.New("slot is before root offset")
)

func makeKey(level int, slot uint64) []byte {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This method name is not descriptive enough and there are many methods in this package that create keys. Please consider another name for this, perhaps mentioning state diff.

Comment thread beacon-chain/db/kv/state_diff_helpers.go
Comment thread beacon-chain/db/kv/state_diff_helpers.go
)

func makeKey(level int, slot uint64) []byte {
buf := make([]byte, 16)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is the key 16 bytes? Shouldn't it be 8 bytes for a Uint64?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's 1 byte for the level, and 8 bytes for the slot = 9 in total. 16 is for alignment.

Comment thread beacon-chain/db/kv/state_diff_helpers.go Outdated
Comment thread beacon-chain/db/kv/state_diff_helpers.go
type stateDiffCache struct {
sync.RWMutex
anchors []state.ReadOnlyBeaconState
offset uint64

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could use an atomic value here and not need a lock for the offset.

Consider this feedback optional unless you expect these methods to be a high throughput / blocking operation.

https://pkg.go.dev/sync/atomic#Uint64

@Inspector-Butters Inspector-Butters added this pull request to the merge queue Nov 19, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 19, 2025
@Inspector-Butters Inspector-Butters added this pull request to the merge queue Nov 19, 2025
Merged via the queue into develop with commit 207f360 Nov 19, 2025
24 checks passed
@Inspector-Butters Inspector-Butters deleted the state-diff-configs branch November 19, 2025 19:53
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.

4 participants