Skip to content

refactor(core): read and write classes through ClassBucket - #4235

Merged
infrmtcs merged 1 commit into
mainfrom
danielntmd/cbor-typed-buckets
Nov 3, 2026
Merged

infrmtcs merged 1 commit into
mainfrom
danielntmd/cbor-typed-buckets

Conversation

@danielntmd

@danielntmd danielntmd commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Route the class Get, Write and Delete accessors (core and core/state) through ClassBucket.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @danielntmd's task in 17m 40s —— View job


Review complete

  • Gather context (diff, changed files)
  • Review db/typed/bucket.go changes (GetPtr)
  • Review core/accessors.go changes
  • Review core/state/accessors.go changes
  • Review core/typed_buckets.go changes (Cbor serializer for ClassBucket)
  • Review db/typed/bucket_test.go changes
  • Post findings

Summary: Clean, mechanical refactor. No blockers or important issues found.

Notes from the review (no action needed):

  • Bucket.GetPtr (db/typed/bucket.go:43) correctly allocates new(V) on the heap and returns nil, err on failure, matching the pre-existing var x *T; ...; return x, err pattern it replaces — including returning nil rather than a half-populated struct when the key is missing.
  • Switching ClassBucket (core/typed_buckets.go:25-29) from value.Binary[...] to value.Cbor[...] is correct and not a storage-format change: the old core.GetClass/WriteClass already called the generic cbor.Marshal/cbor.Unmarshal on *DeclaredClassDefinition directly (not .MarshalBinary()/.UnmarshalBinary()), so the on-disk bytes are unchanged — value.Cbor[V]() just makes the typed bucket match what was already being written. value.Binary[V]() would have bypassed the CBOR byte-string wrapping fxamacker's lib applies for encoding.BinaryMarshaler types and produced different bytes, so the bucket was correctly left unintegrated (TODO) until this change.
  • core/state/accessors.go's GetClass/WriteClass/DeleteClass now delegate to core.ClassBucket instead of duplicating the cbor encode/decode logic — removes duplication without behavior change.
  • Key casts like (*felt.ClassHash)(classHash) are safe since felt.ClassHash and felt.Felt are both Typed[K] fp.Element aliases with identical underlying type, and this conversion pattern already exists elsewhere in the codebase (e.g. rpc/v10/transaction.go:169).
  • Test additions in db/typed/bucket_test.go adequately cover GetPtr's success/not-found paths alongside the existing Get assertions.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Title

(Describe updated until commit f583c12)

refactor(core): read and write classes through ClassBucket


PR Type

Enhancement, Tests


Description

  • Route class read/write/delete accessors through ClassBucket

  • Add BinaryCbor serializer encoding CBOR over MarshalBinary

  • Switch class, bloom filter, event filter buckets to BinaryCbor

  • Add literal and random tests for new serializer


File Walkthrough

Relevant files
Enhancement
accessors.go
Route core class accessors through ClassBucket                     

core/accessors.go

  • GetClass now delegates to ClassBucket.Get and returns a pointer to the
    decoded class
  • WriteClass delegates persistence to ClassBucket.Put, removing manual
    CBOR marshal code
+6/-11   
accessors.go
Delegate state class accessors to ClassBucket                       

core/state/accessors.go

  • WriteClass, DeleteClass, and GetClass now delegate to core.ClassBucket
    operations
  • Removes direct CBOR marshaling and raw key handling from state class
    accessors
  • Drops the now-unused utils/cbor import
+4/-15   
typed_buckets.go
Switch buckets to BinaryCbor serializer                                   

core/typed_buckets.go

  • ClassBucket value serializer changed from value.Binary to
    value.BinaryCbor, matching stored class encoding
  • AggregatedBloomFiltersBucket and RunningEventFilterBucket switched
    from value.Cbor to value.BinaryCbor
  • Removes the TODO: Integrate this bucket comment for ClassBucket
+3/-4     
binary.go
Add binaryCborSerializer value serializer type                     

db/typed/value/binary.go

  • Adds binaryCborSerializer type constrained to binaryMarshaler values
  • Marshals and unmarshals values via the utils/cbor package, preserving
    stored byte format
+12/-0   
value.go
Expose BinaryCbor serializer constructor                                 

db/typed/value/value.go

  • Adds BinaryCbor constructor returning the new CBOR-over-binary
    serializer
+4/-0     
Tests
value_test.go
Test BinaryCbor serializer round trips                                     

db/typed/value/value_test.go

  • Adds literal round-trip test for BinaryCbor with db.BlockNumIndexKey,
    asserting exact encoded bytes
  • Adds random round-trip test for BinaryCbor serializer
+17/-0   

@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.15%. Comparing base (0d2fd9f) to head (f583c12).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4235      +/-   ##
==========================================
- Coverage   81.27%   81.15%   -0.12%     
==========================================
  Files         485      485              
  Lines       35667    35661       -6     
==========================================
- Hits        28988    28942      -46     
- Misses       6673     6713      +40     
  Partials        6        6              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@danielntmd
danielntmd deployed to Development October 30, 2026 00:20 — with GitHub Actions Active
@danielntmd
danielntmd requested a review from infrmtcs October 30, 2026 12:43
Comment thread db/typed/bucket.go Resolved
Comment thread core/typed_buckets.go Resolved
@rodrodros

Copy link
Copy Markdown
Contributor

@danielntmd there is no reason to return by pointer ever, since the way to do it in lang exists already via the use of new()

func A -> returns `T`
   return t


func B -> returns `*T`
   return new(A())

Route the class accessors through ClassBucket and store it with the new
BinaryCbor serializer, which names the byte string of MarshalBinary that
the cbor library already writes. The stored bytes do not change.
@danielntmd
danielntmd force-pushed the danielntmd/cbor-typed-buckets branch from 3ced76a to f583c12 Compare November 2, 2026 12:45
@danielntmd danielntmd changed the title refactor(core): read headers, state updates and classes through typed buckets refactor(core): read and write classes through ClassBucket Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @danielntmd's task in 11m 58s —— View job


Review complete

  • Gather context (diff since last review, changed files)
  • Review db/typed/value/binary.go / value.go (new BinaryCbor serializer)
  • Review core/typed_buckets.go (ClassBucket, AggregatedBloomFiltersBucket, RunningEventFilterBucket)
  • Review core/accessors.go / core/state/accessors.go
  • Review db/typed/value/value_test.go
  • Post findings

Summary: Clean follow-up addressing the earlier review thread. No blockers or important issues found.

Notes (no action needed):

  • The new value.BinaryCbor[V, P]() (db/typed/value/binary.go:21-29) still routes through cbor.Marshal/cbor.Unmarshal, relying on fxamacker's implicit encoding.BinaryMarshaler byte-string-wrap hook — same as before, just named and constrained to types that actually implement MarshalBinary/UnmarshalBinary. This matches what @infrmtcs and @danielntmd converged on in the thread (pin the behavior with a literal/golden test rather than hand-rolling an explicit wrap now, with a "real" BinaryCbor implementation deferred to a later PR).
  • value_test.go:86-94 adds a hardcoded hex literal test for BinaryCbor[db.BlockNumIndexKey]. The 50 prefix (CBOR byte-string, length 16) followed by the exact same 16 bytes as the plain Binary test above it confirms the implicit wrap is happening, and will fail loudly if fxamacker/cbor ever stops doing this — satisfying the regression-guard concern raised in review.
  • Switching AggregatedBloomFiltersBucket / RunningEventFilterBucket from value.Cbor[...] to value.BinaryCbor[...] (core/typed_buckets.go:140-150) is a type-safety-only change (adds the binaryMarshaler constraint); the Marshal/Unmarshal bodies are identical (cbor.Marshal/cbor.Unmarshal), so on-disk bytes are unaffected.
  • ClassBucket switching from value.Binary[...] to value.BinaryCbor[...] (core/typed_buckets.go:25-29) correctly matches the pre-existing on-disk format, since core.GetClass/WriteClass previously called cbor.Marshal/cbor.Unmarshal directly (which already applied the implicit wrap), not .MarshalBinary()/.UnmarshalBinary() directly — a plain value.Binary[...]() would have produced different (unwrapped) bytes.
  • The GetPtr addition from the prior round was removed, consistent with @rodrodros's feedback that pointer-returning accessors don't need a dedicated bucket method (callers can take &value themselves, as core.GetClass/core/state.GetClass now do).
  • core.ClassBucket.Get/Put/Delete wiring in core/accessors.go:23-33 and core/state/accessors.go:104-122 is behavior-preserving relative to the manual CBOR encode/decode it replaces.
    · branch danielntmd/cbor-typed-buckets

@danielntmd
danielntmd deployed to Development November 2, 2026 12:59 — with GitHub Actions Active
@infrmtcs
infrmtcs merged commit afcf02f into main Nov 3, 2026
27 of 28 checks passed
@infrmtcs
infrmtcs deleted the danielntmd/cbor-typed-buckets branch November 3, 2026 13:16

This branch was successfully deployed

1 active deployment
Development — f583c121 Deployed Nov 2, 2026 by danielntmd via dev_deploy_test / deploy #6266
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.

3 participants