Skip to content

Commit 71d26cf

Browse files
songgaoyevladjdkAlex | Interchain Labs
authored
chore: minor update transientStorage (#257)
Co-authored-by: Vlad J <vladjdk@gmail.com> Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io>
1 parent 82a7981 commit 71d26cf

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

x/vm/statedb/transient_storage.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ func newTransientStorage() transientStorage {
1919
// Set sets the transient-storage `value` for `key` at the given `addr`.
2020
func (t transientStorage) Set(addr common.Address, key, value common.Hash) {
2121
if value == (common.Hash{}) { // this is a 'delete'
22-
if _, ok := t[addr]; ok {
23-
delete(t[addr], key)
24-
if len(t[addr]) == 0 {
22+
if storage, ok := t[addr]; ok {
23+
delete(storage, key)
24+
if len(storage) == 0 {
2525
delete(t, addr)
2626
}
2727
}
@@ -35,11 +35,10 @@ func (t transientStorage) Set(addr common.Address, key, value common.Hash) {
3535

3636
// Get gets the transient storage for `key` at the given `addr`.
3737
func (t transientStorage) Get(addr common.Address, key common.Hash) common.Hash {
38-
val, ok := t[addr]
39-
if !ok {
40-
return common.Hash{}
38+
if val, ok := t[addr]; ok {
39+
return val[key]
4140
}
42-
return val[key]
41+
return common.Hash{}
4342
}
4443

4544
// Copy does a deep copy of the transientStorage
@@ -54,16 +53,16 @@ func (t transientStorage) Copy() transientStorage {
5453
// PrettyPrint prints the contents of the access list in a human-readable form
5554
func (t transientStorage) PrettyPrint() string {
5655
out := new(strings.Builder)
57-
var sortedAddrs []common.Address
56+
sortedAddrs := make([]common.Address, 0, len(t))
5857
for addr := range t {
5958
sortedAddrs = append(sortedAddrs, addr)
60-
slices.SortFunc(sortedAddrs, common.Address.Cmp)
6159
}
60+
slices.SortFunc(sortedAddrs, common.Address.Cmp)
6261

6362
for _, addr := range sortedAddrs {
6463
fmt.Fprintf(out, "%#x:", addr)
65-
var sortedKeys []common.Hash
6664
storage := t[addr]
65+
sortedKeys := make([]common.Hash, 0, len(storage))
6766
for key := range storage {
6867
sortedKeys = append(sortedKeys, key)
6968
}

0 commit comments

Comments
 (0)