Skip to content

feat(migration): headstate migration#3657

Open
MaksymMalicki wants to merge 2 commits into
mainfrom
maksym/headstate-migration
Open

feat(migration): headstate migration#3657
MaksymMalicki wants to merge 2 commits into
mainfrom
maksym/headstate-migration

Conversation

@MaksymMalicki
Copy link
Copy Markdown
Contributor

@MaksymMalicki MaksymMalicki commented May 19, 2026

Summary

Adds the headstate migration: a resume-safe transform that consolidates the deprecated per-field contract layout (ContractClassHash, ContractNonce, ContractDeploymentHeight) into the single Contract record introduced by the new-state work. Gated behind the existing --new-state flag. First of three new-state migrations.

How it works

ContractClassHash[addr]
ContractNonce[addr]
ContractDeploymentHeight[addr]
          │
          ▼
Contract[addr] = { ClassHash, Nonce, DeployedHeight }

Iterates the ContractClassHash bucket to discover every contract address. Four worker goroutines (ingestorCount) read the three deprecated fields per address into shared db.Batches; one committer drains batches at 96 MB. A semaphore caps in-flight batches at ingestorCount + 1. After all records are written, the three deprecated buckets are wiped via DeleteRange.

StorageRoot is left zero on each new record — the running node lazily backfills it on the contract's first storage write.

What changes

  • New migration/headstate/ package (migrator, ingestor, committer, counter, tests).
  • Registered in node/migration.go as an optional migration gated by cfg.NewState.
  • state.WriteContract in core/state/accessors.go gains a public overload taking raw fields, used by the migration.

Resume safety

  • state.HasContract skips addresses whose Contract record already exists — no overwrite of newer running-node data.
  • The trailing wipe re-issues DeleteRange over any residual ranges; already-empty ranges are no-ops.
  • Ctx cancellation returns (shouldRerun, ctx.Err()) so the runner re-invokes on next start.

@MaksymMalicki MaksymMalicki marked this pull request as draft May 19, 2026 11:20
@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 65.00000% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.18%. Comparing base (7aedc3a) to head (c2eacce).

Files with missing lines Patch % Lines
migration/headstate/migrator.go 65.62% 16 Missing and 6 partials ⚠️
migration/headstate/ingestor.go 63.63% 9 Missing and 7 partials ⚠️
migration/headstate/counter.go 43.47% 12 Missing and 1 partial ⚠️
migration/headstate/committer.go 89.47% 1 Missing and 1 partial ⚠️
node/migration.go 0.00% 2 Missing ⚠️
core/state/state.go 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3657      +/-   ##
==========================================
- Coverage   76.25%   76.18%   -0.08%     
==========================================
  Files         396      400       +4     
  Lines       36424    36571     +147     
==========================================
+ Hits        27775    27861      +86     
- Misses       6677     6715      +38     
- Partials     1972     1995      +23     

☔ View full report in Codecov by Sentry.
📢 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.

@MaksymMalicki MaksymMalicki marked this pull request as ready for review May 19, 2026 21:53
@MaksymMalicki MaksymMalicki force-pushed the maksym/headstate-migration branch from 0f8a352 to c2eacce Compare May 20, 2026 12:55
elapsed := now.Sub(c.start).Seconds()
if elapsed > c.timeLogRate.Seconds() {
mbs := float64(c.size) / float64(db.Megabyte)
c.logger.Info(
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.

example log output:

juno      | 11:22:12.007 26/05/2026 +00:00      INFO    headstate/counter.go:35 write speed     {"MB": 377.31350898742676, "MB/s": 3.1230496120267954, "completedContracts": 3768018, "completedContracts/s": 31188.141618862945, "time": 120.815726889}

ideally, we should round to ~last 2 digits after .

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.

2 participants