Skip to content

feat: tree view state#168

Merged
wemeetagain merged 90 commits intomainfrom
tree-view-state
Jan 19, 2026
Merged

feat: tree view state#168
wemeetagain merged 90 commits intomainfrom
tree-view-state

Conversation

@wemeetagain
Copy link
Copy Markdown
Member

@wemeetagain wemeetagain commented Jan 14, 2026

This PR implements a major architectural change to migrate the beacon state from a value-based representation to a tree view representation using persistent merkle trees. This enables efficient state management with structural sharing and copy-on-write semantics for Ethereum consensus state transitions.

Changes:

  • Migrated BeaconStateAllForks to BeaconState using tree view representation with persistent merkle trees
  • Updated all state access patterns from direct field access to getter/setter methods
  • Refactored execution payload types to use values instead of pointers
  • Added Node.Pool initialization throughout the test suite for merkle tree node management

wemeetagain and others added 30 commits January 8, 2026 11:01
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Comment thread src/state_transition/types/beacon_state.zig Outdated
Comment thread src/state_transition/slot/upgrade_state_to_capella.zig Outdated
Comment thread src/ssz/tree_view/base.zig
Comment thread src/ssz/tree_view/base.zig
Comment thread src/ssz/tree_view/list_composite.zig
Comment thread src/state_transition/types/beacon_state.zig Outdated
Comment thread src/state_transition/types/beacon_state.zig Outdated
Comment thread src/ssz/tree_view/list_composite.zig Outdated
Comment thread src/era/Writer.zig
Comment on lines +188 to +189
var s = state;
const slot = try s.slot();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i guess this was changed during testing?

Comment on lines +472 to +479
pub fn hasField(comptime name: []const u8) bool {
inline for (fields) |field| {
if (std.mem.eql(u8, name, field.name)) {
return true;
}
}
return false;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

does @hasField not work for VariableContainerType and FixedContainerTypes?

This seems to work running zig build test:state_transition:

➜ jj diff --git
diff --git a/src/state_transition/types/beacon_state.zig b/src/state_transition/types/beacon_state.zig
index de8370ff5a..07adb91aff 100644
--- a/src/state_transition/types/beacon_state.zig
+++ b/src/state_transition/types/beacon_state.zig
@@ -776,7 +776,7 @@

         inline for (F.fields) |f| {
             // const field_name: []const u8 = comptime f.name[0..f.name.len];
-            if (comptime T.hasField(f.name)) {
+            if (comptime @hasField(T, f.name)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

should be @hasField(T.Fields, f.name) but imo this shows that its a little confusing and why not just add a comptime method here that is harder to screw up

Comment thread src/state_transition/block/process_consolidation_request.zig Outdated
@wemeetagain wemeetagain merged commit 08880db into main Jan 19, 2026
8 checks passed
twoeths pushed a commit that referenced this pull request Mar 2, 2026
This PR implements a major architectural change to migrate the beacon
state from a value-based representation to a tree view representation
using persistent merkle trees. This enables efficient state management
with structural sharing and copy-on-write semantics for Ethereum
consensus state transitions.

Changes:

- Migrated BeaconStateAllForks to BeaconState using tree view
representation with persistent merkle trees
- Updated all state access patterns from direct field access to
getter/setter methods
- Refactored execution payload types to use values instead of pointers
- Added Node.Pool initialization throughout the test suite for merkle
tree node management

---------

Signed-off-by: Chen Kai <281165273grape@gmail.com>
Co-authored-by: Chen Kai <281165273grape@gmail.com>
twoeths added a commit that referenced this pull request Mar 2, 2026
After cherry-picking "feat: tree view state (#168)", SSZ tree view conflicts
were resolved by keeping "ours", which lost new API functions the
state_transition code depends on. This commit adds back the missing APIs
and fixes all callers.

Key changes:
- Add missing tree view APIs: hashTreeRoot, fromValue, toValue, getReadonly,
  getValue, setValue, getFieldRoot, iteratorReadonly across container,
  array_basic, array_composite, list_basic, list_composite, bit_vector
- Fix CompositeChunks.get() to always mark changed (fixes attester_slashing
  failures where getReadonly cached a child without tracking, then get()
  returned the cached entry without marking it changed)
- Fix CompositeChunks.getAllValuesInto() to initialize variable-type values
  before toValue (fixes segfault from uninitialized BitList fields)
- Fix pointer type mismatches (*TreeView vs **TreeView) across callers
- Fix beacon_state field name bugs and return type mismatches
- Add @setEvalBranchQuota(20000) for comptime iteration over BeaconState

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

5 participants