Skip to content

Commit

Permalink
snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Jan 11, 2025
1 parent cb62b4d commit 49c76a0
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions state/factory/workingsetstore_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type stateDBWorkingSetStoreWithErigonOutput struct {
reader
store *stateDBWorkingSetStore
erigonStore *erigonStore
snDiff int
snMap map[int]int
}

type erigonStore struct {
Expand All @@ -58,6 +58,7 @@ func newStateDBWorkingSetStoreWithErigonOutput(store *stateDBWorkingSetStore, er
reader: store,
store: store,
erigonStore: erigonStore,
snMap: make(map[int]int),
}
}

Expand Down Expand Up @@ -102,22 +103,24 @@ func (store *stateDBWorkingSetStoreWithErigonOutput) Commit(ctx context.Context)
func (store *stateDBWorkingSetStoreWithErigonOutput) Snapshot() int {
sn := store.store.Snapshot()
isn := store.erigonStore.intraBlockState.Snapshot()
diff := isn - sn
if store.snDiff != 0 && diff != store.snDiff {
log.L().Panic("snapshot diff changed", zap.Int("old", store.snDiff), zap.Int("new", diff))
}
store.snDiff = diff
store.snMap[sn] = isn
return sn
}

func (store *stateDBWorkingSetStoreWithErigonOutput) RevertSnapshot(sn int) error {
store.store.RevertSnapshot(sn)
store.erigonStore.intraBlockState.RevertToSnapshot(sn + store.snDiff)
if isn, ok := store.snMap[sn]; ok {
store.erigonStore.intraBlockState.RevertToSnapshot(isn)
delete(store.snMap, sn)
} else {
panic(fmt.Sprintf("no isn for sn %d", sn))
}
return nil
}

func (store *stateDBWorkingSetStoreWithErigonOutput) ResetSnapshots() {
store.store.ResetSnapshots()
store.snMap = make(map[int]int)
}

func (store *stateDBWorkingSetStoreWithErigonOutput) Close() {
Expand Down

0 comments on commit 49c76a0

Please sign in to comment.