Skip to content

Conversation

@holyfuchs
Copy link

@holyfuchs holyfuchs commented Jan 6, 2026

closes: #6462

Summary by CodeRabbit

  • Refactor

    • Consolidated account status into a single, compact on-disk layout and removed legacy migration variants.
  • Tests

    • Removed obsolete deserialization tests for older account formats; test suite now targets current serialization and invalid-size handling.
  • Bug Fix

    • Validation logic updated to use the unified minimum size for account status checks.

✏️ Tip: You can customize this high-level summary in your review settings.

@holyfuchs holyfuchs requested a review from a team as a code owner January 6, 2026 19:58
@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 6, 2026

📝 Walkthrough

Walkthrough

Removed legacy account-status formats and migration logic (v1/v2), consolidated to a single minimal packed layout (AccountStatusMinSize / accountStatusPacked), updated serialization/deserialization and receiver methods, removed corresponding legacy tests, and adjusted a storage validation size constant reference.

Changes

Cohort / File(s) Summary
Account status core
fvm/environment/accounts_status.go
Removed legacy v1/v2 size constants and migration branches; introduced AccountStatusMinSize and a packed representation (accountStatusPacked); unified serialization/deserialization and updated receiver methods to the packed layout.
Validation update
cmd/util/cmd/check-storage/account_key_validation.go
Replaced references to AccountStatusMinSizeV4 with AccountStatusMinSize in size checks, slice bounds, and error messages.
Removed legacy tests
cmd/util/ledger/migrations/storage_used_migration_test.go, fvm/environment/accounts_status_test.go
Deleted test cases covering legacy v1 and v2 account-status formats; retained tests for current format and invalid-size error handling.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I hop through bytes both small and packed,

Old crumbs swept out, the layout stacked.
V1 and V2 I left behind,
A tidy pack is what I find.
Carrot code and cleaner mind 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: removal of legacy account status format code, which aligns with the primary objective of the changeset.
Linked Issues check ✅ Passed All code changes directly address issue #6462: legacy account status formats (V1/V2) are removed from both production code and tests, leaving only V3 implementation.
Out of Scope Changes check ✅ Passed All changes are in-scope: removal of legacy AccountStatusSizeV1/V2/V3 constants, migration of v1/v2 test cases, and updating references in validation code align with the stated objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
fvm/environment/accounts_status.go (2)

78-83: Minor aliasing consideration.

Line 80 returns a slice backed by the internal array. If the caller modifies the returned slice, it would corrupt the AccountStatus. This is acceptable if callers treat the result as read-only (typical for storage serialization), but consider documenting this contract or returning a copy for defensive coding.

💡 Optional defensive copy
 func (a *AccountStatus) ToBytes() []byte {
 	if len(a.keyMetadataBytes) == 0 {
-		return a.accountStatusPacked[:]
+		result := make([]byte, AccountStatusMinSize)
+		copy(result, a.accountStatusPacked[:])
+		return result
 	}
 	return append(a.accountStatusPacked[:], a.keyMetadataBytes...)
 }

99-109: Consider version validation for defense-in-depth.

Per coding guidelines, "all inputs must be considered potentially byzantine." The function currently accepts any input ≥ 29 bytes without validating the version nibble. If legacy (non-v4) data somehow exists in storage, it would be silently misinterpreted rather than rejected.

Also, the error message could be more informative by including the expected size.

💡 Suggested hardening
 func accountStatusFromBytes(inp []byte) (accountStatusPacked, []byte, error) {
 	if len(inp) < AccountStatusMinSize {
-		return accountStatusPacked{}, nil, errors.NewValueErrorf(hex.EncodeToString(inp), "invalid account status size")
+		return accountStatusPacked{}, nil, errors.NewValueErrorf(
+			hex.EncodeToString(inp),
+			"invalid account status size: got %d bytes, expected at least %d",
+			len(inp),
+			AccountStatusMinSize,
+		)
 	}
 
 	inp, rest := inp[:AccountStatusMinSize], inp[AccountStatusMinSize:]
 	var as accountStatusPacked
 	copy(as[:], inp)
 
+	version := as.Version()
+	if version != 4 {
+		return accountStatusPacked{}, nil, errors.NewValueErrorf(
+			hex.EncodeToString(inp),
+			"unsupported account status version: got v%d, expected v4",
+			version,
+		)
+	}
+
 	return as, rest, nil
 }

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27f321a and 2f159f0.

📒 Files selected for processing (2)
  • cmd/util/cmd/check-storage/account_key_validation.go
  • fvm/environment/accounts_status.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/util/cmd/check-storage/account_key_validation.go
🧰 Additional context used
📓 Path-based instructions (4)
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/coding_conventions.mdc)

Follow Go coding conventions as documented in @docs/agents/CodingConventions.md

Follow Go coding standards and conventions as documented in @docs/agents/GoDocs.md

**/*.go: Follow the existing module structure in /module/, /engine/, /model/ and use dependency injection patterns for component composition
Implement proper interfaces before concrete types
Follow Go naming conventions and the project's coding style defined in /docs/CodingConventions.md
Use mock generators: run make generate-mocks after interface changes
All inputs must be considered potentially byzantine; error classification is context-dependent and no code path is safe unless explicitly proven and documented
Use comprehensive error wrapping for debugging; avoid fmt.Errorf, use irrecoverable package for exceptions
NEVER log and continue on best effort basis; ALWAYS explicitly handle errors
Uses golangci-lint with custom configurations (.golangci.yml) and custom linters for Flow-specific conventions (struct write checking)

Files:

  • fvm/environment/accounts_status.go
{crypto,fvm,ledger,storage}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Security checks for cryptographic misuse must be enforced using gosec

Files:

  • fvm/environment/accounts_status.go
{crypto,fvm,ledger,access,engine}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Cryptographic operations require careful handling; refer to crypto library documentation for proper implementation

Files:

  • fvm/environment/accounts_status.go
{storage,ledger,execution,fvm}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

State consistency is paramount; use proper synchronization primitives

Files:

  • fvm/environment/accounts_status.go
🧬 Code graph analysis (1)
fvm/environment/accounts_status.go (1)
model/access/versioned.go (1)
  • Version (10-10)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (34)
  • GitHub Check: Lint (./insecure/)
  • GitHub Check: Lint (./integration/)
  • GitHub Check: Lint (./)
  • GitHub Check: Unit Tests (network/alsp)
  • GitHub Check: Unit Tests (engine/consensus)
  • GitHub Check: Unit Tests (network)
  • GitHub Check: Unit Tests (others)
  • GitHub Check: Unit Tests (network/p2p/connection)
  • GitHub Check: Unit Tests (engine/verification)
  • GitHub Check: Unit Tests (module)
  • GitHub Check: Unit Tests (engine/execution/ingestion)
  • GitHub Check: Unit Tests (module/dkg)
  • GitHub Check: Unit Tests (network/p2p/scoring)
  • GitHub Check: Unit Tests (engine/execution/computation)
  • GitHub Check: Unit Tests (network/test/cohort2)
  • GitHub Check: Unit Tests (engine/execution)
  • GitHub Check: Unit Tests (storage)
  • GitHub Check: Unit Tests (network/p2p)
  • GitHub Check: Unit Tests (engine)
  • GitHub Check: Unit Tests (state)
  • GitHub Check: Unit Tests (engine/common)
  • GitHub Check: Unit Tests (fvm)
  • GitHub Check: Unit Tests (consensus)
  • GitHub Check: Unit Tests (utils)
  • GitHub Check: Unit Tests (engine/access)
  • GitHub Check: Unit Tests (engine/collection)
  • GitHub Check: Unit Tests (ledger)
  • GitHub Check: Unit Tests (cmd)
  • GitHub Check: Unit Tests (admin)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/rpc_inspector)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/scoring)
  • GitHub Check: Unit Tests Insecure (insecure)
  • GitHub Check: analyze-code (go)
  • GitHub Check: Docker Build
🔇 Additional comments (6)
fvm/environment/accounts_status.go (6)

14-37: LGTM!

The constants are well-organized and the naming is now cleaner. The AccountStatusMinSize calculation is correct (1+8+8+4+8 = 29 bytes), and the index calculations properly chain from each preceding field.


51-56: LGTM!

The type refactoring from accountStatusV3 to accountStatusPacked is clean. The embedding pattern allows AccountStatus to inherit all the packed representation methods while extending with keyMetadataBytes for key metadata storage.


58-71: LGTM!

The initialization is correct with proper default values. Storage index starting at 1 is appropriate (0 is typically reserved). The byte count matches AccountStatusMinSize (29 bytes).


85-97: LGTM!

The defensive copy of rest via append([]byte(nil), rest...) ensures the returned AccountStatus doesn't alias the input slice. Error handling is correct.


111-163: LGTM!

The getter/setter methods are correctly refactored to use *accountStatusPacked receiver. The byte offset calculations using the index constants are correct, and the binary.BigEndian operations properly handle the serialization.


165-233: LGTM!

The key metadata methods correctly leverage the embedded accountStatusPacked methods through Go's type embedding. The logic remains unchanged and properly integrates with the refactored type structure.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
fvm/environment/accounts_status.go (1)

101-133: Remove dead code left over from migration logic removal.

The variable sizeChange is initialized to 0 on line 102 and never modified. The entire block at lines 113-130 is unreachable dead code since the condition sizeChange != 0 will always be false.

This appears to be leftover scaffolding from the removed v1/v2 migration logic. To complete the cleanup per the PR objective, remove this dead code.

🔎 Proposed fix
 func accountStatusV3FromBytes(inp []byte) (accountStatusV3, []byte, error) {
-	sizeChange := int64(0)
-
 	if len(inp) < accountStatusSizeV3 {
 		return accountStatusV3{}, nil, errors.NewValueErrorf(hex.EncodeToString(inp), "invalid account status size")
 	}

 	inp, rest := inp[:accountStatusSizeV3], inp[accountStatusSizeV3:]

 	var as accountStatusV3
 	copy(as[:], inp)

-	if sizeChange != 0 {
-		used := as.StorageUsed()
-
-		if sizeChange < 0 {
-			// check if the storage used is smaller than the size change
-			if used < uint64(-sizeChange) {
-				return accountStatusV3{}, nil, errors.NewValueErrorf(hex.EncodeToString(inp), "account would have negative storage used after migration")
-			}
-
-			used = used - uint64(-sizeChange)
-		}
-
-		if sizeChange > 0 {
-			used = used + uint64(sizeChange)
-		}
-
-		as.SetStorageUsed(used)
-	}
-
 	return as, rest, nil
 }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f8ed45 and bff30bf.

📒 Files selected for processing (3)
  • cmd/util/ledger/migrations/storage_used_migration_test.go
  • fvm/environment/accounts_status.go
  • fvm/environment/accounts_status_test.go
💤 Files with no reviewable changes (2)
  • cmd/util/ledger/migrations/storage_used_migration_test.go
  • fvm/environment/accounts_status_test.go
🧰 Additional context used
📓 Path-based instructions (4)
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/coding_conventions.mdc)

Follow Go coding conventions as documented in @docs/agents/CodingConventions.md

Follow Go coding standards and conventions as documented in @docs/agents/GoDocs.md

**/*.go: Follow the existing module structure in /module/, /engine/, /model/ and use dependency injection patterns for component composition
Implement proper interfaces before concrete types
Follow Go naming conventions and the project's coding style defined in /docs/CodingConventions.md
Use mock generators: run make generate-mocks after interface changes
All inputs must be considered potentially byzantine; error classification is context-dependent and no code path is safe unless explicitly proven and documented
Use comprehensive error wrapping for debugging; avoid fmt.Errorf, use irrecoverable package for exceptions
NEVER log and continue on best effort basis; ALWAYS explicitly handle errors
Uses golangci-lint with custom configurations (.golangci.yml) and custom linters for Flow-specific conventions (struct write checking)

Files:

  • fvm/environment/accounts_status.go
{crypto,fvm,ledger,storage}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Security checks for cryptographic misuse must be enforced using gosec

Files:

  • fvm/environment/accounts_status.go
{crypto,fvm,ledger,access,engine}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Cryptographic operations require careful handling; refer to crypto library documentation for proper implementation

Files:

  • fvm/environment/accounts_status.go
{storage,ledger,execution,fvm}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

State consistency is paramount; use proper synchronization primitives

Files:

  • fvm/environment/accounts_status.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (36)
  • GitHub Check: Lint (./insecure/)
  • GitHub Check: Lint (./)
  • GitHub Check: Lint (./integration/)
  • GitHub Check: Unit Tests (engine/execution/computation)
  • GitHub Check: Unit Tests (network/p2p/connection)
  • GitHub Check: Unit Tests (network/p2p/node)
  • GitHub Check: Unit Tests (network/test/cohort2)
  • GitHub Check: Unit Tests (network)
  • GitHub Check: Unit Tests (others)
  • GitHub Check: Unit Tests (network/p2p/scoring)
  • GitHub Check: Unit Tests (network/test/cohort1)
  • GitHub Check: Unit Tests (engine/execution)
  • GitHub Check: Unit Tests (network/p2p)
  • GitHub Check: Unit Tests (network/alsp)
  • GitHub Check: Unit Tests (module/dkg)
  • GitHub Check: Unit Tests (engine/execution/ingestion)
  • GitHub Check: Unit Tests (utils)
  • GitHub Check: Unit Tests (module)
  • GitHub Check: Unit Tests (storage)
  • GitHub Check: Unit Tests (engine/common)
  • GitHub Check: Unit Tests (engine/verification)
  • GitHub Check: Unit Tests (engine/access)
  • GitHub Check: Unit Tests (engine/consensus)
  • GitHub Check: Unit Tests (consensus)
  • GitHub Check: Unit Tests (state)
  • GitHub Check: Unit Tests (cmd)
  • GitHub Check: Unit Tests (engine)
  • GitHub Check: Unit Tests (admin)
  • GitHub Check: Unit Tests (engine/collection)
  • GitHub Check: Unit Tests (fvm)
  • GitHub Check: Unit Tests (ledger)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/scoring)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/rpc_inspector)
  • GitHub Check: Unit Tests Insecure (insecure)
  • GitHub Check: analyze-code (go)
  • GitHub Check: Docker Build
🔇 Additional comments (2)
fvm/environment/accounts_status.go (2)

14-38: LGTM! Constants are correctly defined and well-structured.

The size and index constants properly define the v3 layout:

  • Field sizes match their data types (uint64 → 8 bytes, uint32 → 4 bytes)
  • Index calculations are consistent with the sequential layout
  • accountStatusSizeV3 correctly sums to 29 bytes
  • AccountStatusMinSizeV4 aliasing accountStatusSizeV3 establishes forward compatibility

62-73: LGTM! Forward-compatible version initialization.

New accounts are correctly initialized with version 4 flag (0x40) while using the v3 layout. This design allows future version detection without changing the current structure size. The initialization values properly set:

  • Storage index to 1 (as documented)
  • All counters to 0
  • Version bits to 4

@codecov-commenter
Copy link

codecov-commenter commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 85.18519% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...d/util/cmd/check-storage/account_key_validation.go 0.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@holyfuchs holyfuchs force-pushed the holyfuchs/6462-remove-legacy-account-status branch from bff30bf to cd65ebe Compare January 6, 2026 20:22
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
fvm/environment/accounts_status.go (1)

113-115: Consider adding version validation for defense-in-depth.

The Version() method exists but is not used during deserialization in accountStatusV3FromBytes. Adding a version check would provide fail-fast behavior if legacy data is accidentally encountered, rather than silently misinterpreting it.

Proposed defensive version check

Add version validation in accountStatusV3FromBytes:

 func accountStatusV3FromBytes(inp []byte) (accountStatusV3, []byte, error) {
 	if len(inp) < accountStatusSizeV3 {
 		return accountStatusV3{}, nil, errors.NewValueErrorf(hex.EncodeToString(inp), "invalid account status size")
 	}
 
 	inp, rest := inp[:accountStatusSizeV3], inp[accountStatusSizeV3:]
 	var as accountStatusV3
 	copy(as[:], inp)
+	
+	// Validate version is v3+ (version >= 3, or v4+ with 0x40 flag)
+	version := as.Version()
+	if version != 0 && version < 3 {
+		return accountStatusV3{}, nil, errors.NewValueErrorf(hex.EncodeToString(inp), "unsupported account status version %d (expected v3+)", version)
+	}
 
 	return as, rest, nil
 }

Note: This assumes version 0 with flag 0x40 represents v4, and versions 1-2 are legacy formats that should be rejected.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bff30bf and cd65ebe.

📒 Files selected for processing (3)
  • cmd/util/ledger/migrations/storage_used_migration_test.go
  • fvm/environment/accounts_status.go
  • fvm/environment/accounts_status_test.go
💤 Files with no reviewable changes (2)
  • cmd/util/ledger/migrations/storage_used_migration_test.go
  • fvm/environment/accounts_status_test.go
🧰 Additional context used
📓 Path-based instructions (4)
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/coding_conventions.mdc)

Follow Go coding conventions as documented in @docs/agents/CodingConventions.md

Follow Go coding standards and conventions as documented in @docs/agents/GoDocs.md

**/*.go: Follow the existing module structure in /module/, /engine/, /model/ and use dependency injection patterns for component composition
Implement proper interfaces before concrete types
Follow Go naming conventions and the project's coding style defined in /docs/CodingConventions.md
Use mock generators: run make generate-mocks after interface changes
All inputs must be considered potentially byzantine; error classification is context-dependent and no code path is safe unless explicitly proven and documented
Use comprehensive error wrapping for debugging; avoid fmt.Errorf, use irrecoverable package for exceptions
NEVER log and continue on best effort basis; ALWAYS explicitly handle errors
Uses golangci-lint with custom configurations (.golangci.yml) and custom linters for Flow-specific conventions (struct write checking)

Files:

  • fvm/environment/accounts_status.go
{crypto,fvm,ledger,storage}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Security checks for cryptographic misuse must be enforced using gosec

Files:

  • fvm/environment/accounts_status.go
{crypto,fvm,ledger,access,engine}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Cryptographic operations require careful handling; refer to crypto library documentation for proper implementation

Files:

  • fvm/environment/accounts_status.go
{storage,ledger,execution,fvm}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

State consistency is paramount; use proper synchronization primitives

Files:

  • fvm/environment/accounts_status.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (37)
  • GitHub Check: Lint (./integration/)
  • GitHub Check: Lint (./)
  • GitHub Check: Lint (./insecure/)
  • GitHub Check: Unit Tests (network/p2p/node)
  • GitHub Check: Unit Tests (others)
  • GitHub Check: Unit Tests (network/test/cohort2)
  • GitHub Check: Unit Tests (engine/verification)
  • GitHub Check: Unit Tests (network)
  • GitHub Check: Unit Tests (fvm)
  • GitHub Check: Unit Tests (network/p2p/scoring)
  • GitHub Check: Unit Tests (state)
  • GitHub Check: Unit Tests (engine/common)
  • GitHub Check: Unit Tests (network/p2p/connection)
  • GitHub Check: Unit Tests (network/alsp)
  • GitHub Check: Unit Tests (network/test/cohort1)
  • GitHub Check: Unit Tests (consensus)
  • GitHub Check: Unit Tests (storage)
  • GitHub Check: Unit Tests (utils)
  • GitHub Check: Unit Tests (module)
  • GitHub Check: Unit Tests (engine/consensus)
  • GitHub Check: Unit Tests (engine/execution)
  • GitHub Check: Unit Tests (admin)
  • GitHub Check: Unit Tests (network/p2p)
  • GitHub Check: Unit Tests (module/dkg)
  • GitHub Check: Unit Tests (engine/execution/computation)
  • GitHub Check: Unit Tests (engine/execution/ingestion)
  • GitHub Check: Unit Tests (cmd)
  • GitHub Check: Unit Tests (engine)
  • GitHub Check: Unit Tests (engine/collection)
  • GitHub Check: Unit Tests (engine/access)
  • GitHub Check: Unit Tests (ledger)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/scoring)
  • GitHub Check: Unit Tests Insecure (insecure)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/rpc_inspector)
  • GitHub Check: Integration Tests Others (integration)
  • GitHub Check: Docker Build
  • GitHub Check: analyze-code (go)
🔇 Additional comments (2)
fvm/environment/accounts_status.go (2)

27-38: Verify that v4+ constants are intentionally defined but largely unused.

The v4+ layout constants (flagIndex, storageUsedStartIndex, etc.) and version-related constants (versionMask, accountStatusV4DefaultVersionAndFlag) are defined, but the code primarily operates on accountStatusV3 structure. Only NewAccountStatus uses accountStatusV4DefaultVersionAndFlag for initialization.

Ensure this is intentional—either these constants are reserved for future migration work, or there's missing v4 implementation code.

#!/bin/bash
# Description: Search for usage of v4 constants to verify they're not orphaned

echo "=== Searching for v4 constant usage ==="
rg -n "AccountStatusMinSizeV4|accountStatusV4DefaultVersionAndFlag|flagIndex|storageUsedStartIndex|storageIndexStartIndex|accountPublicKeyCountsStartIndex|addressIdCounterStartIndex" --type=go -C2

echo -e "\n=== Searching for any v4 or version 4 references ==="
rg -n "v4|version.?4" --type=go fvm/environment/ -C2

101-111: No critical issue - this is correct migration design, not a regression.

The commit "[FVM] Remove legacy account status formats code" intentionally eliminated v1/v2 support. The accountStatusV3FromBytes function assumes all input is v4+ format by design, not by accident. This is guaranteed by the migration pipeline, which explicitly sets all accounts to version 4 (0x40) before they enter production. The validation code in account_key_deduplication_migration_validation.go (line 116-119) enforces that only v4 accounts exist post-migration. All tests confirm accounts carry version 4. Version validation in accountStatusV3FromBytes is unnecessary because the deserialization function is never called on pre-migrated data—the 29-byte size check is sufficient for format compatibility.

Likely an incorrect or invalid review comment.

Copy link
Contributor

@janezpodhostnik janezpodhostnik left a comment

Choose a reason for hiding this comment

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

Looks good. Just had one comment about naming.

Copy link
Member

@fxamacker fxamacker left a comment

Choose a reason for hiding this comment

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

Nice! I left a comment about renaming accountStatusSize, etc.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
fvm/environment/accounts_status.go (1)

51-51: Consider renaming to remove version suffix.

Now that legacy formats have been removed, the V3 suffix in accountStatusV3 is no longer necessary and may cause confusion (especially since v4 is the current format per accountStatusV4DefaultVersionAndFlag). Consider renaming to accountStatus along with related function names like accountStatusV3FromBytes.

Based on past review comments suggesting similar naming cleanup.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd65ebe and 23a9579.

📒 Files selected for processing (1)
  • fvm/environment/accounts_status.go
🧰 Additional context used
📓 Path-based instructions (4)
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/coding_conventions.mdc)

Follow Go coding conventions as documented in @docs/agents/CodingConventions.md

Follow Go coding standards and conventions as documented in @docs/agents/GoDocs.md

**/*.go: Follow the existing module structure in /module/, /engine/, /model/ and use dependency injection patterns for component composition
Implement proper interfaces before concrete types
Follow Go naming conventions and the project's coding style defined in /docs/CodingConventions.md
Use mock generators: run make generate-mocks after interface changes
All inputs must be considered potentially byzantine; error classification is context-dependent and no code path is safe unless explicitly proven and documented
Use comprehensive error wrapping for debugging; avoid fmt.Errorf, use irrecoverable package for exceptions
NEVER log and continue on best effort basis; ALWAYS explicitly handle errors
Uses golangci-lint with custom configurations (.golangci.yml) and custom linters for Flow-specific conventions (struct write checking)

Files:

  • fvm/environment/accounts_status.go
{crypto,fvm,ledger,storage}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Security checks for cryptographic misuse must be enforced using gosec

Files:

  • fvm/environment/accounts_status.go
{crypto,fvm,ledger,access,engine}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Cryptographic operations require careful handling; refer to crypto library documentation for proper implementation

Files:

  • fvm/environment/accounts_status.go
{storage,ledger,execution,fvm}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

State consistency is paramount; use proper synchronization primitives

Files:

  • fvm/environment/accounts_status.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (37)
  • GitHub Check: Lint (./integration/)
  • GitHub Check: Lint (./)
  • GitHub Check: Lint (./insecure/)
  • GitHub Check: Integration Tests Others (integration)
  • GitHub Check: Unit Tests (network/test/cohort1)
  • GitHub Check: Unit Tests (engine/execution/ingestion)
  • GitHub Check: Unit Tests (network/p2p/connection)
  • GitHub Check: Unit Tests (others)
  • GitHub Check: Unit Tests (engine/execution/computation)
  • GitHub Check: Unit Tests (network/alsp)
  • GitHub Check: Unit Tests (network)
  • GitHub Check: Unit Tests (network/p2p)
  • GitHub Check: Unit Tests (network/p2p/node)
  • GitHub Check: Unit Tests (module)
  • GitHub Check: Unit Tests (engine)
  • GitHub Check: Unit Tests (engine/collection)
  • GitHub Check: Unit Tests (network/test/cohort2)
  • GitHub Check: Unit Tests (engine/common)
  • GitHub Check: Unit Tests (network/p2p/scoring)
  • GitHub Check: Unit Tests (module/dkg)
  • GitHub Check: Unit Tests (storage)
  • GitHub Check: Unit Tests (ledger)
  • GitHub Check: Unit Tests (cmd)
  • GitHub Check: Unit Tests (engine/verification)
  • GitHub Check: Unit Tests (engine/execution)
  • GitHub Check: Unit Tests (utils)
  • GitHub Check: Unit Tests (consensus)
  • GitHub Check: Unit Tests (engine/consensus)
  • GitHub Check: Unit Tests (admin)
  • GitHub Check: Unit Tests (state)
  • GitHub Check: Unit Tests (engine/access)
  • GitHub Check: Unit Tests (fvm)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/scoring)
  • GitHub Check: Unit Tests Insecure (insecure)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/rpc_inspector)
  • GitHub Check: Docker Build
  • GitHub Check: analyze-code (go)
🔇 Additional comments (2)
fvm/environment/accounts_status.go (2)

15-37: LGTM: Constants are well-structured and self-documenting.

The refactoring of size constants into individual components and the computed accountStatusMinSize improves maintainability and clarity. The layout indices correctly derive from the size constants, preventing potential misalignment issues.


99-109: The migration code removal is intentional and was completed during Crescendo spork.

The on-the-fly migration code that handled v1→v2→v3 format conversions was removed on Sep 4, 2025 as a planned cleanup. The TODO comments in the previous version explicitly indicated the code would be removed after a full migration during Crescendo. The current implementation assumes all accounts have been migrated to V3+ format and will fail with "invalid account status size" for any legacy formats.

This removal is safe: there are no remaining constants for accountStatusSizeV1 or accountStatusSizeV2 in the codebase, all tests expect version 4, and the code has been deployed for 4+ months without errors indicating the migration was successfully completed.

@holyfuchs holyfuchs force-pushed the holyfuchs/6462-remove-legacy-account-status branch from 23a9579 to d35512f Compare January 7, 2026 18:58
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @fvm/environment/accounts_status.go:
- Around line 101-111: The function accountStatusV3FromBytes should return a
clearer error and validate the embedded version: when len(inp) <
accountStatusMinSize (29) return an error that includes the actual length and
the expected minimum (29) instead of just hex data; after slicing/copying into
accountStatusV3, verify the version nibble matches v4 (use the Version() method
on accountStatusV3 or check the upper 4 bits of the first byte == 0x4) and
return a descriptive error if it does not; keep using accountStatusMinSize and
accountStatusV3 identifiers so changes are localized.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 23a9579 and d35512f.

📒 Files selected for processing (1)
  • fvm/environment/accounts_status.go
🧰 Additional context used
📓 Path-based instructions (4)
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/coding_conventions.mdc)

Follow Go coding conventions as documented in @docs/agents/CodingConventions.md

Follow Go coding standards and conventions as documented in @docs/agents/GoDocs.md

**/*.go: Follow the existing module structure in /module/, /engine/, /model/ and use dependency injection patterns for component composition
Implement proper interfaces before concrete types
Follow Go naming conventions and the project's coding style defined in /docs/CodingConventions.md
Use mock generators: run make generate-mocks after interface changes
All inputs must be considered potentially byzantine; error classification is context-dependent and no code path is safe unless explicitly proven and documented
Use comprehensive error wrapping for debugging; avoid fmt.Errorf, use irrecoverable package for exceptions
NEVER log and continue on best effort basis; ALWAYS explicitly handle errors
Uses golangci-lint with custom configurations (.golangci.yml) and custom linters for Flow-specific conventions (struct write checking)

Files:

  • fvm/environment/accounts_status.go
{crypto,fvm,ledger,storage}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Security checks for cryptographic misuse must be enforced using gosec

Files:

  • fvm/environment/accounts_status.go
{crypto,fvm,ledger,access,engine}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Cryptographic operations require careful handling; refer to crypto library documentation for proper implementation

Files:

  • fvm/environment/accounts_status.go
{storage,ledger,execution,fvm}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

State consistency is paramount; use proper synchronization primitives

Files:

  • fvm/environment/accounts_status.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (37)
  • GitHub Check: Lint (./insecure/)
  • GitHub Check: Lint (./integration/)
  • GitHub Check: Lint (./)
  • GitHub Check: Integration Tests Others (integration)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/scoring)
  • GitHub Check: Unit Tests Insecure (insecure)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/rpc_inspector)
  • GitHub Check: Unit Tests (admin)
  • GitHub Check: Unit Tests (network/p2p/connection)
  • GitHub Check: Unit Tests (network/test/cohort1)
  • GitHub Check: Unit Tests (engine/common)
  • GitHub Check: Unit Tests (fvm)
  • GitHub Check: Unit Tests (others)
  • GitHub Check: Unit Tests (network/test/cohort2)
  • GitHub Check: Unit Tests (network/alsp)
  • GitHub Check: Unit Tests (cmd)
  • GitHub Check: Unit Tests (engine)
  • GitHub Check: Unit Tests (network/p2p/scoring)
  • GitHub Check: Unit Tests (engine/execution/computation)
  • GitHub Check: Unit Tests (storage)
  • GitHub Check: Unit Tests (network)
  • GitHub Check: Unit Tests (engine/collection)
  • GitHub Check: Unit Tests (module)
  • GitHub Check: Unit Tests (engine/execution/ingestion)
  • GitHub Check: Unit Tests (network/p2p)
  • GitHub Check: Unit Tests (engine/execution)
  • GitHub Check: Unit Tests (network/p2p/node)
  • GitHub Check: Unit Tests (ledger)
  • GitHub Check: Unit Tests (state)
  • GitHub Check: Unit Tests (consensus)
  • GitHub Check: Unit Tests (engine/access)
  • GitHub Check: Unit Tests (engine/verification)
  • GitHub Check: Unit Tests (engine/consensus)
  • GitHub Check: Unit Tests (module/dkg)
  • GitHub Check: Unit Tests (utils)
  • GitHub Check: Docker Build
  • GitHub Check: analyze-code (go)
🔇 Additional comments (4)
fvm/environment/accounts_status.go (4)

15-25: LGTM! Clear and maintainable size constant definitions.

The refactoring to explicit component sizes with a computed accountStatusMinSize improves readability and maintainability. The calculation is correct (1+8+8+4+8 = 29 bytes).


53-53: LGTM! Type definition consistently updated.

The type definition correctly references the new accountStatusMinSize constant, maintaining consistency with the refactored size constants. Keeping the V3 designation aligns with the maintainer's decision to preserve version separation for potential future migrations.


62-73: LGTM! Accessor methods correctly use new layout constants.

The NewAccountStatus function properly initializes with accountStatusV4DefaultVersionAndFlag, and all accessor methods (SetStorageUsed, StorageUsed, SetStorageIndex, SlabIndex, SetAccountPublicKeyCount, AccountPublicKeyCount, SetAccountIdCounter, AccountIdCounter) correctly reference the new index constants. The logic remains functionally equivalent to the previous implementation.

Also applies to: 126-165


27-39: No action required. The migration code in cmd/util/ledger/migrations/account_key_deduplication_migration_validation.go is fully compatible with the AccountStatusMinSizeV4 constant. It uses the constant correctly at lines 126, 127, 135, and 139 for size validation and metadata offset calculations. The constant's reference to accountStatusMinSize (25 bytes) is properly defined and matches the expected behavior.

@holyfuchs holyfuchs force-pushed the holyfuchs/6462-remove-legacy-account-status branch from b9efcdc to 27f321a Compare January 11, 2026 09:41
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @fvm/environment/accounts_status.go:
- Around line 99-109: The function accountStatusV3FromBytes actually parses the
V4 format; rename it to accountStatusV4FromBytes and update internal identifiers
(e.g., asv3 -> asv4, any comments mentioning V3) to reflect V4, then update all
call sites to use accountStatusV4FromBytes so behavior (size check against
AccountStatusMinSize and return values) remains unchanged; ensure unit tests and
any documentation referencing accountStatusV3FromBytes are updated accordingly.
🧹 Nitpick comments (1)
fvm/environment/accounts_status.go (1)

86-97: Inconsistent naming: function and comment reference "V3" after consolidation.

While the implementation correctly uses accountStatusPacked, there are naming inconsistencies:

  • Line 87: The called function is still named accountStatusV3FromBytes
  • Line 92: Comment still mentions accountStatusV3

These should be updated to reflect the new naming scheme for consistency.

♻️ Suggested refactor for naming consistency

Update the function name:

-func AccountStatusFromBytes(inp []byte) (*AccountStatus, error) {
-	asv3, rest, err := accountStatusV3FromBytes(inp)
+func AccountStatusFromBytes(inp []byte) (*AccountStatus, error) {
+	asPacked, rest, err := accountStatusPackedFromBytes(inp)
 	if err != nil {
 		return nil, err
 	}
 
-	// NOTE: both accountStatusV3 and keyMetadataBytes are copies.
+	// NOTE: both accountStatusPacked and keyMetadataBytes are copies.
 	return &AccountStatus{
-		accountStatusPacked: asv3,
+		accountStatusPacked: asPacked,
 		keyMetadataBytes:    append([]byte(nil), rest...),
 	}, nil
 }

Also update the function definition at line 99:

-func accountStatusV3FromBytes(inp []byte) (accountStatusPacked, []byte, error) {
+func accountStatusPackedFromBytes(inp []byte) (accountStatusPacked, []byte, error) {
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d35512f and 27f321a.

📒 Files selected for processing (2)
  • cmd/util/cmd/check-storage/account_key_validation.go
  • fvm/environment/accounts_status.go
🧰 Additional context used
📓 Path-based instructions (5)
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/coding_conventions.mdc)

Follow Go coding conventions as documented in @docs/agents/CodingConventions.md

Follow Go coding standards and conventions as documented in @docs/agents/GoDocs.md

**/*.go: Follow the existing module structure in /module/, /engine/, /model/ and use dependency injection patterns for component composition
Implement proper interfaces before concrete types
Follow Go naming conventions and the project's coding style defined in /docs/CodingConventions.md
Use mock generators: run make generate-mocks after interface changes
All inputs must be considered potentially byzantine; error classification is context-dependent and no code path is safe unless explicitly proven and documented
Use comprehensive error wrapping for debugging; avoid fmt.Errorf, use irrecoverable package for exceptions
NEVER log and continue on best effort basis; ALWAYS explicitly handle errors
Uses golangci-lint with custom configurations (.golangci.yml) and custom linters for Flow-specific conventions (struct write checking)

Files:

  • cmd/util/cmd/check-storage/account_key_validation.go
  • fvm/environment/accounts_status.go
{module,engine,cmd}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

All major processing components must implement the Component interface from /module/component/component.go to ensure consistent lifecycle management and graceful shutdown patterns

Files:

  • cmd/util/cmd/check-storage/account_key_validation.go
{crypto,fvm,ledger,storage}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Security checks for cryptographic misuse must be enforced using gosec

Files:

  • fvm/environment/accounts_status.go
{crypto,fvm,ledger,access,engine}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Cryptographic operations require careful handling; refer to crypto library documentation for proper implementation

Files:

  • fvm/environment/accounts_status.go
{storage,ledger,execution,fvm}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

State consistency is paramount; use proper synchronization primitives

Files:

  • fvm/environment/accounts_status.go
🧠 Learnings (1)
📚 Learning: 2025-12-23T00:28:41.005Z
Learnt from: CR
Repo: onflow/flow-go PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-23T00:28:41.005Z
Learning: Applies to {crypto,fvm,ledger,access,engine}/**/*.go : Cryptographic operations require careful handling; refer to crypto library documentation for proper implementation

Applied to files:

  • fvm/environment/accounts_status.go
🧬 Code graph analysis (1)
cmd/util/cmd/check-storage/account_key_validation.go (2)
fvm/environment/accounts_status.go (1)
  • AccountStatusMinSize (21-25)
fvm/environment/account-key-metadata/metadata.go (1)
  • DecodeKeyMetadata (371-407)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (37)
  • GitHub Check: Lint (./)
  • GitHub Check: Lint (./insecure/)
  • GitHub Check: Lint (./integration/)
  • GitHub Check: Unit Tests (network/test/cohort1)
  • GitHub Check: Unit Tests (engine/execution)
  • GitHub Check: Unit Tests (engine/execution/computation)
  • GitHub Check: Unit Tests (network/p2p/node)
  • GitHub Check: Unit Tests (network/p2p)
  • GitHub Check: Unit Tests (network/p2p/connection)
  • GitHub Check: Unit Tests (engine)
  • GitHub Check: Unit Tests (others)
  • GitHub Check: Unit Tests (network/alsp)
  • GitHub Check: Unit Tests (engine/execution/ingestion)
  • GitHub Check: Unit Tests (network)
  • GitHub Check: Unit Tests (network/test/cohort2)
  • GitHub Check: Unit Tests (network/p2p/scoring)
  • GitHub Check: Unit Tests (engine/common)
  • GitHub Check: Unit Tests (engine/collection)
  • GitHub Check: Unit Tests (module/dkg)
  • GitHub Check: Unit Tests (engine/verification)
  • GitHub Check: Unit Tests (engine/access)
  • GitHub Check: Unit Tests (module)
  • GitHub Check: Unit Tests (storage)
  • GitHub Check: Unit Tests (utils)
  • GitHub Check: Unit Tests (engine/consensus)
  • GitHub Check: Unit Tests (consensus)
  • GitHub Check: Unit Tests (cmd)
  • GitHub Check: Unit Tests (ledger)
  • GitHub Check: Unit Tests (admin)
  • GitHub Check: Unit Tests (fvm)
  • GitHub Check: Unit Tests (state)
  • GitHub Check: Integration Tests Others (integration)
  • GitHub Check: Unit Tests Insecure (insecure)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/scoring)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/rpc_inspector)
  • GitHub Check: Docker Build
  • GitHub Check: analyze-code (go)
🔇 Additional comments (5)
fvm/environment/accounts_status.go (3)

51-51: LGTM: Type rename improves clarity.

The rename from accountStatusV3 to accountStatusPacked appropriately removes version-specific naming and better describes the binary representation.


111-163: LGTM: Receiver type updates are consistent across all methods.

All method receivers have been correctly updated from *accountStatusV3 to *accountStatusPacked. The method implementations remain unchanged, ensuring backward compatibility at the API level.


36-36: The account status version target is correctly V4; no discrepancy exists.

The code correctly uses V4 (0x40) as the default account status version. The accountStatusV3FromBytes function exists for backwards compatibility to read existing V3 data during migration, not to maintain V3 as an active standard. The PR objectives referenced in the original comment ("all account statuses should have been upgraded to V3") cannot be found in the provided codebase, and the RELEASE.md contains no mention of account status version targets.

Likely an incorrect or invalid review comment.

cmd/util/cmd/check-storage/account_key_validation.go (2)

125-127: LGTM: Size validation correctly updated.

The constant reference has been properly updated from AccountStatusMinSizeV4 to AccountStatusMinSize, maintaining the correct validation logic for accounts with one or fewer public keys.


133-140: LGTM: Key metadata extraction correctly updated.

Both references to the constant in the slice operations (lines 134 and 138) have been consistently updated. The logic correctly extracts key metadata starting after the base account status structure.

@holyfuchs holyfuchs force-pushed the holyfuchs/6462-remove-legacy-account-status branch from 27f321a to 2f159f0 Compare January 14, 2026 15:58
Copy link
Member

@fxamacker fxamacker left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for working on this! 👍

Copy link
Contributor

@janezpodhostnik janezpodhostnik left a comment

Choose a reason for hiding this comment

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

Nice

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.

[FVM] Remove legacy account status formats code

6 participants