@@ -992,76 +992,70 @@ func (s *StateDB) clearJournalAndRefund() {
992
992
// of a specific account. It leverages the associated state snapshot for fast
993
993
// storage iteration and constructs trie node deletion markers by creating
994
994
// stack trie with iterated slots.
995
- func (s * StateDB ) fastDeleteStorage (addrHash common.Hash , root common.Hash ) (common. StorageSize , map [common.Hash ][]byte , * trienode.NodeSet , error ) {
995
+ func (s * StateDB ) fastDeleteStorage (addrHash common.Hash , root common.Hash ) (map [common.Hash ][]byte , * trienode.NodeSet , error ) {
996
996
iter , err := s .snaps .StorageIterator (s .originalRoot , addrHash , common.Hash {})
997
997
if err != nil {
998
- return 0 , nil , nil , err
998
+ return nil , nil , err
999
999
}
1000
1000
defer iter .Release ()
1001
1001
1002
1002
var (
1003
- size common.StorageSize
1004
1003
nodes = trienode .NewNodeSet (addrHash )
1005
1004
slots = make (map [common.Hash ][]byte )
1006
1005
)
1007
1006
stack := trie .NewStackTrie (func (path []byte , hash common.Hash , blob []byte ) {
1008
1007
nodes .AddNode (path , trienode .NewDeleted ())
1009
- size += common .StorageSize (len (path ))
1010
1008
})
1011
1009
for iter .Next () {
1012
1010
slot := common .CopyBytes (iter .Slot ())
1013
1011
if err := iter .Error (); err != nil { // error might occur after Slot function
1014
- return 0 , nil , nil , err
1012
+ return nil , nil , err
1015
1013
}
1016
- size += common .StorageSize (common .HashLength + len (slot ))
1017
1014
slots [iter .Hash ()] = slot
1018
1015
1019
1016
if err := stack .Update (iter .Hash ().Bytes (), slot ); err != nil {
1020
- return 0 , nil , nil , err
1017
+ return nil , nil , err
1021
1018
}
1022
1019
}
1023
1020
if err := iter .Error (); err != nil { // error might occur during iteration
1024
- return 0 , nil , nil , err
1021
+ return nil , nil , err
1025
1022
}
1026
1023
if stack .Hash () != root {
1027
- return 0 , nil , nil , fmt .Errorf ("snapshot is not matched, exp %x, got %x" , root , stack .Hash ())
1024
+ return nil , nil , fmt .Errorf ("snapshot is not matched, exp %x, got %x" , root , stack .Hash ())
1028
1025
}
1029
- return size , slots , nodes , nil
1026
+ return slots , nodes , nil
1030
1027
}
1031
1028
1032
1029
// slowDeleteStorage serves as a less-efficient alternative to "fastDeleteStorage,"
1033
1030
// employed when the associated state snapshot is not available. It iterates the
1034
1031
// storage slots along with all internal trie nodes via trie directly.
1035
- func (s * StateDB ) slowDeleteStorage (addr common.Address , addrHash common.Hash , root common.Hash ) (common. StorageSize , map [common.Hash ][]byte , * trienode.NodeSet , error ) {
1032
+ func (s * StateDB ) slowDeleteStorage (addr common.Address , addrHash common.Hash , root common.Hash ) (map [common.Hash ][]byte , * trienode.NodeSet , error ) {
1036
1033
tr , err := s .db .OpenStorageTrie (s .originalRoot , addr , root , s .trie )
1037
1034
if err != nil {
1038
- return 0 , nil , nil , fmt .Errorf ("failed to open storage trie, err: %w" , err )
1035
+ return nil , nil , fmt .Errorf ("failed to open storage trie, err: %w" , err )
1039
1036
}
1040
1037
it , err := tr .NodeIterator (nil )
1041
1038
if err != nil {
1042
- return 0 , nil , nil , fmt .Errorf ("failed to open storage iterator, err: %w" , err )
1039
+ return nil , nil , fmt .Errorf ("failed to open storage iterator, err: %w" , err )
1043
1040
}
1044
1041
var (
1045
- size common.StorageSize
1046
1042
nodes = trienode .NewNodeSet (addrHash )
1047
1043
slots = make (map [common.Hash ][]byte )
1048
1044
)
1049
1045
for it .Next (true ) {
1050
1046
if it .Leaf () {
1051
1047
slots [common .BytesToHash (it .LeafKey ())] = common .CopyBytes (it .LeafBlob ())
1052
- size += common .StorageSize (common .HashLength + len (it .LeafBlob ()))
1053
1048
continue
1054
1049
}
1055
1050
if it .Hash () == (common.Hash {}) {
1056
1051
continue
1057
1052
}
1058
- size += common .StorageSize (len (it .Path ()))
1059
1053
nodes .AddNode (it .Path (), trienode .NewDeleted ())
1060
1054
}
1061
1055
if err := it .Error (); err != nil {
1062
- return 0 , nil , nil , err
1056
+ return nil , nil , err
1063
1057
}
1064
- return size , slots , nodes , nil
1058
+ return slots , nodes , nil
1065
1059
}
1066
1060
1067
1061
// deleteStorage is designed to delete the storage trie of a designated account.
@@ -1070,34 +1064,22 @@ func (s *StateDB) slowDeleteStorage(addr common.Address, addrHash common.Hash, r
1070
1064
// efficient approach.
1071
1065
func (s * StateDB ) deleteStorage (addr common.Address , addrHash common.Hash , root common.Hash ) (map [common.Hash ][]byte , * trienode.NodeSet , error ) {
1072
1066
var (
1073
- start = time .Now ()
1074
1067
err error
1075
- size common.StorageSize
1076
1068
slots map [common.Hash ][]byte
1077
1069
nodes * trienode.NodeSet
1078
1070
)
1079
1071
// The fast approach can be failed if the snapshot is not fully
1080
1072
// generated, or it's internally corrupted. Fallback to the slow
1081
1073
// one just in case.
1082
1074
if s .snap != nil {
1083
- size , slots , nodes , err = s .fastDeleteStorage (addrHash , root )
1075
+ slots , nodes , err = s .fastDeleteStorage (addrHash , root )
1084
1076
}
1085
1077
if s .snap == nil || err != nil {
1086
- size , slots , nodes , err = s .slowDeleteStorage (addr , addrHash , root )
1078
+ slots , nodes , err = s .slowDeleteStorage (addr , addrHash , root )
1087
1079
}
1088
1080
if err != nil {
1089
1081
return nil , nil , err
1090
1082
}
1091
- // Report the metrics
1092
- n := int64 (len (slots ))
1093
-
1094
- slotDeletionMaxCount .UpdateIfGt (int64 (len (slots )))
1095
- slotDeletionMaxSize .UpdateIfGt (int64 (size ))
1096
-
1097
- slotDeletionTimer .UpdateSince (start )
1098
- slotDeletionCount .Mark (n )
1099
- slotDeletionSize .Mark (int64 (size ))
1100
-
1101
1083
return slots , nodes , nil
1102
1084
}
1103
1085
0 commit comments