@@ -23,7 +23,6 @@ import (
23
23
"maps"
24
24
"math/big"
25
25
"slices"
26
- "sort"
27
26
"sync"
28
27
"sync/atomic"
29
28
"time"
@@ -48,11 +47,6 @@ import (
48
47
// TriesInMemory represents the number of layers that are kept in RAM.
49
48
const TriesInMemory = 128
50
49
51
- type revision struct {
52
- id int
53
- journalIndex int
54
- }
55
-
56
50
type mutationType int
57
51
58
52
const (
@@ -143,9 +137,7 @@ type StateDB struct {
143
137
144
138
// Journal of state modifications. This is the backbone of
145
139
// Snapshot and RevertToSnapshot.
146
- journal * journal
147
- validRevisions []revision
148
- nextRevisionId int
140
+ journal * journal
149
141
150
142
// State witness if cross validation is needed
151
143
witness * stateless.Witness
@@ -703,8 +695,6 @@ func (s *StateDB) Copy() *StateDB {
703
695
logSize : s .logSize ,
704
696
preimages : maps .Clone (s .preimages ),
705
697
journal : s .journal .copy (),
706
- validRevisions : slices .Clone (s .validRevisions ),
707
- nextRevisionId : s .nextRevisionId ,
708
698
709
699
// In order for the block producer to be able to use and make additions
710
700
// to the snapshot tree, we need to copy that as well. Otherwise, any
@@ -750,26 +740,12 @@ func (s *StateDB) Copy() *StateDB {
750
740
751
741
// Snapshot returns an identifier for the current revision of the state.
752
742
func (s * StateDB ) Snapshot () int {
753
- id := s .nextRevisionId
754
- s .nextRevisionId ++
755
- s .validRevisions = append (s .validRevisions , revision {id , s .journal .length ()})
756
- return id
743
+ return s .journal .Snapshot ()
757
744
}
758
745
759
746
// RevertToSnapshot reverts all state changes made since the given revision.
760
747
func (s * StateDB ) RevertToSnapshot (revid int ) {
761
- // Find the snapshot in the stack of valid snapshots.
762
- idx := sort .Search (len (s .validRevisions ), func (i int ) bool {
763
- return s .validRevisions [i ].id >= revid
764
- })
765
- if idx == len (s .validRevisions ) || s .validRevisions [idx ].id != revid {
766
- panic (fmt .Errorf ("revision id %v cannot be reverted" , revid ))
767
- }
768
- snapshot := s .validRevisions [idx ].journalIndex
769
-
770
- // Replay the journal to undo changes and remove invalidated snapshots
771
- s .journal .revert (s , snapshot )
772
- s .validRevisions = s .validRevisions [:idx ]
748
+ s .journal .RevertToSnapshot (revid , s )
773
749
}
774
750
775
751
// GetRefund returns the current value of the refund counter.
@@ -983,11 +959,8 @@ func (s *StateDB) SetTxContext(thash common.Hash, ti int) {
983
959
}
984
960
985
961
func (s * StateDB ) clearJournalAndRefund () {
986
- if len (s .journal .entries ) > 0 {
987
- s .journal = newJournal ()
988
- s .refund = 0
989
- }
990
- s .validRevisions = s .validRevisions [:0 ] // Snapshots can be created without journal entries
962
+ s .journal .Reset ()
963
+ s .refund = 0
991
964
}
992
965
993
966
// fastDeleteStorage is the function that efficiently deletes the storage trie
0 commit comments