Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
Add panic if copy is performed with non-empty stack of snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Wazzymandias committed Aug 7, 2023
1 parent b88d807 commit 9640bc2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 0 additions & 3 deletions core/state/multi_tx_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,6 @@ func (stack *MultiTxSnapshotStack) Size() int {

// Invalidate invalidates the latest snapshot. This is used when state changes are committed to trie.
func (stack *MultiTxSnapshotStack) Invalidate() {
// TODO: if latest snapshot is invalid, then all previous snapshots
// would also be invalidated, need to update logic to reflect that
size := len(stack.snapshots)
if size == 0 {
return
Expand All @@ -561,7 +559,6 @@ func (stack *MultiTxSnapshotStack) Invalidate() {
head.invalid = true
stack.snapshots = stack.snapshots[:0]
stack.snapshots = append(stack.snapshots, head)
//stack.snapshots[size-1].invalid = true
}

// UpdatePendingStatus updates the pending status for an address.
Expand Down
5 changes: 5 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,11 @@ func (s *StateDB) Copy() *StateDB {
hasher: crypto.NewKeccakState(),
}
// Initialize new multi-transaction snapshot stack for the copied state
// NOTE(wazzymandias): We avoid copying the snapshot stack from the original state
// because it may contain snapshots that are not valid for the copied state.
if s.multiTxSnapshotStack.Size() > 0 {
panic("cannot copy state with active multi-transaction snapshot stack")
}
state.multiTxSnapshotStack = NewMultiTxSnapshotStack(state)
// Copy the dirty states, logs, and preimages
for addr := range s.journal.dirties {
Expand Down

0 comments on commit 9640bc2

Please sign in to comment.