Save account revert fix#7883
Conversation
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
trackableDataTrieupdates 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.
| deletedData := core.TrieData{ | ||
| Key: dataTrieKey, | ||
| Value: nil, | ||
| }) | ||
| } |
There was a problem hiding this comment.
The version does not matter for a delete.
| GetCalled: func(key []byte) ([]byte, uint32, error) { | ||
| getCalls++ | ||
| if bytes.Equal(key, firstKey) { | ||
| return append(firstOldValue, append(firstKey, identifier...)...), 0, nil | ||
| } |
| 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 | ||
| } | ||
| }, |
Reasoning behind the pull request
Proposed changes
Testing procedure
Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
featbranch created?featbranch merging, do all satellite projects have a proper tag insidego.mod?