Skip to content

Save account revert fix#7883

Merged
sstanculeanu merged 9 commits into
feat/testnet-fixesfrom
save-account-revert-fix
Jun 25, 2026
Merged

Save account revert fix#7883
sstanculeanu merged 9 commits into
feat/testnet-fixesfrom
save-account-revert-fix

Conversation

@BeniaminDrasovean

@BeniaminDrasovean BeniaminDrasovean commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Reasoning behind the pull request

  • This branch improves the atomicity of account state updates. Previously, saving an account could modify several data-trie or code entries before encountering an error. Although SaveAccount returned an error, some earlier changes could remain applied, leaving the in-memory state inconsistent with the account journal.

Proposed changes

  • Partially applied data-trie updates are rolled back when saving fails.
  • Code changes are journaled before reference counts are modified.
  • Reverting code restores the exact previous state instead of relying on inverse reference-count operations.
  • Retrying a failed snapshot revert does not execute already completed journal entries again.

Testing procedure

  • Normal tests + import-db

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

@BeniaminDrasovean BeniaminDrasovean self-assigned this Jun 18, 2026
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.67%. Comparing base (0f0c82c) to head (ad39c2a).

Files with missing lines Patch % Lines
state/trackableDataTrie/trackableDataTrie.go 88.46% 2 Missing and 1 partial ⚠️
state/accountsDB.go 97.50% 1 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                   @@
##           feat/testnet-fixes    #7883      +/-   ##
======================================================
+ Coverage               77.63%   77.67%   +0.04%     
======================================================
  Files                     885      885              
  Lines                  125570   125579       +9     
======================================================
+ Hits                    97490    97549      +59     
+ Misses                  21590    21563      -27     
+ Partials                 6490     6467      -23     

☔ 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.

sstanculeanu
sstanculeanu previously approved these changes Jun 22, 2026
Comment thread state/trackableDataTrie/trackableDataTrie.go
Comment thread state/trackableDataTrie/trackableDataTrie_test.go
Comment thread state/trackableDataTrie/trackableDataTrie_test.go

Copilot AI 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.

Pull request overview

This PR tightens the atomicity of state changes during SaveAccount() by ensuring partially-applied trie/code updates are rolled back correctly on failures, and by making snapshot reverts retry-safe (completed journal entries aren’t re-executed on retry).

Changes:

  • Add rollback support for partially-applied trackableDataTrie updates when a later step fails.
  • Journal code entry state before reference-count mutations and revert code by restoring exact prior trie state.
  • Update RevertToSnapshot() to retain only the failing + pending journal entries on error, enabling safe retries; add targeted regression tests.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
state/trackableDataTrie/trackableDataTrie.go Adds rollback of already-applied trie updates when subsequent operations fail.
state/trackableDataTrie/trackableDataTrie_test.go Adds regression tests for rollback behavior (some need stabilizing due to map iteration order).
state/trackableDataTrie/export_test.go Exposes helpers for tests to manipulate dirty-data internals.
state/journalEntries.go Makes code journal entries able to restore exact old/new code trie state.
state/journalEntries_test.go Updates constructor calls to match new journal entry signature.
state/export_test.go Exposes AccountsDB.journalize for tests.
state/accountsDB.go Reorders code journaling vs refcount updates and improves snapshot-revert retry behavior.
state/accountsDB_test.go Adds tests covering code revert correctness and snapshot revert retry semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +317 to +320
deletedData := core.TrieData{
Key: dataTrieKey,
Value: nil,
})
}

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.

The version does not matter for a delete.

Comment on lines +1204 to +1208
GetCalled: func(key []byte) ([]byte, uint32, error) {
getCalls++
if bytes.Equal(key, firstKey) {
return append(firstOldValue, append(firstKey, identifier...)...), 0, nil
}

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.

Fixed

Comment on lines +1269 to +1290
UpdateWithVersionCalled: func(key, value []byte, version core.TrieNodeVersion) error {
updateCalls++
switch updateCalls {
case 1:
assert.Equal(t, firstKey, key)
assert.Equal(t, append(firstNewValue, append(firstKey, identifier...)...), value)
assert.Equal(t, core.NotSpecified, version)
return nil
case 2:
assert.Equal(t, secondKey, key)
return expectedErr
case 3:
assert.Equal(t, firstKey, key)
assert.Equal(t, append(firstOldValue, append(firstKey, identifier...)...), value)
assert.Equal(t, core.NotSpecified, version)
rollbackCalled = true
return nil
default:
require.Fail(t, "unexpected update call")
return nil
}
},

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.

Fixed

Comment thread state/trackableDataTrie/trackableDataTrie.go Outdated
@sstanculeanu sstanculeanu merged commit 143c2f4 into feat/testnet-fixes Jun 25, 2026
11 checks passed
@sstanculeanu sstanculeanu deleted the save-account-revert-fix branch June 25, 2026 14:24
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