diff --git a/state/aggregator22.go b/state/aggregator22.go index fd2afbdb7..ca3370c0a 100644 --- a/state/aggregator22.go +++ b/state/aggregator22.go @@ -287,6 +287,21 @@ func (a *Aggregator22) Unwind(ctx context.Context, txUnwindTo uint64, stateLoad return nil } + codeChanges := etl.NewCollector(a.logPrefix, "", etl.NewOldestEntryBuffer(etl.BufferOptimalSize)) + defer codeChanges.Close() + + if err := a.code.pruneF(step, txUnwindTo, math2.MaxUint64, func(txNum uint64, k, v []byte) error { + if err := codeChanges.Collect(k, v); err != nil { + return err + } + return nil + }); err != nil { + return err + } + if err := codeChanges.Load(a.rwTx, kv.PlainContractCode, etl.IdentityLoadFunc, etl.TransformArgs{Quit: ctx.Done()}); err != nil { + return err + } + stateChanges := etl.NewCollector(a.logPrefix, "", etl.NewOldestEntryBuffer(etl.BufferOptimalSize)) defer stateChanges.Close() @@ -311,21 +326,6 @@ func (a *Aggregator22) Unwind(ctx context.Context, txUnwindTo uint64, stateLoad return err } - codeChanges := etl.NewCollector(a.logPrefix, "", etl.NewOldestEntryBuffer(etl.BufferOptimalSize)) - defer codeChanges.Close() - - if err := a.code.pruneF(step, txUnwindTo, math2.MaxUint64, func(txNum uint64, k, v []byte) error { - if err := codeChanges.Collect(k, v); err != nil { - return err - } - return nil - }); err != nil { - return err - } - if err := codeChanges.Load(a.rwTx, kv.PlainContractCode, etl.IdentityLoadFunc, etl.TransformArgs{Quit: ctx.Done()}); err != nil { - return err - } - if err := a.logAddrs.prune(txUnwindTo, math2.MaxUint64); err != nil { return err } diff --git a/state/history.go b/state/history.go index 479a096b7..b04d1b4f0 100644 --- a/state/history.go +++ b/state/history.go @@ -524,14 +524,22 @@ func (h *History) pruneF(step uint64, txFrom, txTo uint64, f func(txNum uint64, if txNum >= txTo { break } - _, vv, _ := valsC.SeekExact(v[len(v)-8:]) - if err := f(txNum, v[:len(v)-8], vv); err != nil { - return err + key, txnNumBytes := v[:len(v)-8], v[len(v)-8:] + { + kk, vv, err := valsC.SeekExact(txnNumBytes) + if err != nil { + return err + } + if err := f(txNum, key, vv); err != nil { + return err + } + if kk != nil { + if err = valsC.DeleteCurrent(); err != nil { + return err + } + } } - if err = valsC.DeleteCurrent(); err != nil { - return err - } - if err = idxC.DeleteExact(v[:len(v)-8], k); err != nil { + if err = idxC.DeleteExact(key, k); err != nil { return err } // This DeleteCurrent needs to the the last in the loop iteration, because it invalidates k and v