Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions core/state/access_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package state

import (
"github.com/CortexFoundation/CortexTheseus/common"
"maps"
)

type accessList struct {
Expand Down Expand Up @@ -57,16 +58,10 @@ func newAccessList() *accessList {
// Copy creates an independent copy of an accessList.
func (a *accessList) Copy() *accessList {
cp := newAccessList()
for k, v := range a.addresses {
cp.addresses[k] = v
}
cp.addresses = maps.Clone(a.addresses)
cp.slots = make([]map[common.Hash]struct{}, len(a.slots))
for i, slotMap := range a.slots {
newSlotmap := make(map[common.Hash]struct{}, len(slotMap))
for k := range slotMap {
newSlotmap[k] = struct{}{}
}
cp.slots[i] = newSlotmap
cp.slots[i] = maps.Clone(slotMap)
}
return cp
}
Expand Down
8 changes: 2 additions & 6 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"io"
"maps"
"math/big"
"time"

Expand Down Expand Up @@ -48,12 +49,7 @@ func (s Storage) String() (str string) {
}

func (s Storage) Copy() Storage {
cpy := make(Storage)
for key, value := range s {
cpy[key] = value
}

return cpy
return maps.Clone(s)
}

// stateObject represents an Cortex account which is being modified.
Expand Down
22 changes: 10 additions & 12 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package state
import (
"errors"
"fmt"
"maps"
"math/big"
"slices"
"sort"
Expand Down Expand Up @@ -816,10 +817,8 @@ func (s *StateDB) Copy() *StateDB {
}
state.stateObjectsDirty[addr] = struct{}{}
}
// Deep copy the destruction flag.
for addr, value := range s.stateObjectsDestruct {
state.stateObjectsDestruct[addr] = value
}
// Deep copy the destruction markers.
state.stateObjectsDestruct = maps.Clone(s.stateObjectsDestruct)
// Deep copy the state changes made in the scope of block
// along with their original values.
state.accounts = copySet(s.accounts)
Expand All @@ -837,14 +836,13 @@ func (s *StateDB) Copy() *StateDB {
state.logs[hash] = cpy
}
// Deep copy the preimages occurred in the scope of block
for hash, preimage := range s.preimages {
state.preimages[hash] = preimage
}
// Do we need to copy the access list? In practice: No. At the start of a
// transaction, the access list is empty. In practice, we only ever copy state
// _between_ transactions/blocks, never in the middle of a transaction.
// However, it doesn't cost us much to copy an empty list, so we do it anyway
// to not blow up if we ever decide copy it in the middle of a transaction
state.preimages = maps.Clone(s.preimages)
// Do we need to copy the access list and transient storage?
// In practice: No. At the start of a transaction, these two lists are empty.
// In practice, we only ever copy state _between_ transactions/blocks, never
// in the middle of a transaction. However, it doesn't cost us much to copy
// empty lists, so we do it anyway to not blow up if we ever decide copy them
// in the middle of a transaction.
state.accessList = s.accessList.Copy()
state.transientStorage = s.transientStorage.Copy()

Expand Down