@@ -19,7 +19,6 @@ package state
1919
2020import (
2121 "fmt"
22- "sort"
2322 "time"
2423
2524 "github.com/ethereum/go-ethereum/common"
@@ -42,11 +41,6 @@ const (
4241 storageDeleteLimit = 512 * 1024 * 1024
4342)
4443
45- type revision struct {
46- id int
47- journalIndex int
48- }
49-
5044// StateDB structs within the ethereum protocol are used to store anything
5145// within the merkle trie. StateDBs take care of caching and storing
5246// nested states. It's the general query interface to retrieve:
@@ -113,9 +107,7 @@ type StateDB struct {
113107
114108 // Journal of state modifications. This is the backbone of
115109 // Snapshot and RevertToSnapshot.
116- journal * journal
117- validRevisions []revision
118- nextRevisionId int
110+ journal * journal
119111
120112 // Measurements gathered during execution for debugging purposes
121113 AccountReads time.Duration
@@ -774,26 +766,12 @@ func (s *StateDB) Copy() *StateDB {
774766
775767// Snapshot returns an identifier for the current revision of the state.
776768func (s * StateDB ) Snapshot () int {
777- id := s .nextRevisionId
778- s .nextRevisionId ++
779- s .validRevisions = append (s .validRevisions , revision {id , s .journal .length ()})
780- return id
769+ return s .journal .Snapshot ()
781770}
782771
783772// RevertToSnapshot reverts all state changes made since the given revision.
784773func (s * StateDB ) RevertToSnapshot (revid int ) {
785- // Find the snapshot in the stack of valid snapshots.
786- idx := sort .Search (len (s .validRevisions ), func (i int ) bool {
787- return s .validRevisions [i ].id >= revid
788- })
789- if idx == len (s .validRevisions ) || s .validRevisions [idx ].id != revid {
790- panic (fmt .Errorf ("revision id %v cannot be reverted" , revid ))
791- }
792- snapshot := s .validRevisions [idx ].journalIndex
793-
794- // Replay the journal to undo changes and remove invalidated snapshots
795- s .journal .revert (s , snapshot )
796- s .validRevisions = s .validRevisions [:idx ]
774+ s .journal .RevertToSnapshot (revid , s )
797775}
798776
799777// GetRefund returns the current value of the refund counter.
@@ -924,11 +902,8 @@ func (s *StateDB) SetTxContext(thash common.Hash, ti int) {
924902}
925903
926904func (s * StateDB ) clearJournalAndRefund () {
927- if len (s .journal .entries ) > 0 {
928- s .journal = newJournal ()
929- s .refund = 0
930- }
931- s .validRevisions = s .validRevisions [:0 ] // Snapshots can be created without journal entries
905+ s .journal .Reset ()
906+ s .refund = 0
932907}
933908
934909// fastDeleteStorage is the function that efficiently deletes the storage trie
0 commit comments