erigon22: prune - check key existance (#588)

This commit is contained in:
Alex Sharov 2022-08-15 14:33:32 +07:00 committed by GitHub
parent 4945162dd7
commit 59dfcc471c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 22 deletions

View File

@ -287,6 +287,21 @@ func (a *Aggregator22) Unwind(ctx context.Context, txUnwindTo uint64, stateLoad
return nil 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)) stateChanges := etl.NewCollector(a.logPrefix, "", etl.NewOldestEntryBuffer(etl.BufferOptimalSize))
defer stateChanges.Close() defer stateChanges.Close()
@ -311,21 +326,6 @@ func (a *Aggregator22) Unwind(ctx context.Context, txUnwindTo uint64, stateLoad
return err 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 { if err := a.logAddrs.prune(txUnwindTo, math2.MaxUint64); err != nil {
return err return err
} }

View File

@ -524,14 +524,22 @@ func (h *History) pruneF(step uint64, txFrom, txTo uint64, f func(txNum uint64,
if txNum >= txTo { if txNum >= txTo {
break break
} }
_, vv, _ := valsC.SeekExact(v[len(v)-8:]) key, txnNumBytes := v[:len(v)-8], v[len(v)-8:]
if err := f(txNum, v[:len(v)-8], vv); err != nil { {
return err 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 { if err = idxC.DeleteExact(key, k); err != nil {
return err
}
if err = idxC.DeleteExact(v[:len(v)-8], k); err != nil {
return err return err
} }
// This DeleteCurrent needs to the the last in the loop iteration, because it invalidates k and v // This DeleteCurrent needs to the the last in the loop iteration, because it invalidates k and v