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
}
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
}

View File

@ -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