Split ih cursors (#1459)

This commit is contained in:
Alex Sharov 2021-01-29 10:42:48 +07:00 committed by GitHub
parent 906d3eefb6
commit 1828bb32fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -385,7 +385,7 @@ func (l *FlatDBTrieLoader) CalcTrieRoot(db ethdb.Database, quit <-chan struct{})
var filter = func(k []byte) bool {
return !l.rd.Retain(k)
}
ih := IH(filter, tx.CursorDupSort(l.intermediateHashesBucket))
ih := IH(filter, tx.CursorDupSort(l.intermediateHashesBucket), tx.CursorDupSort(l.intermediateHashesBucket))
if err := l.iteration(c, ih, true /* first */); err != nil {
return EmptyRoot, err
}
@ -733,12 +733,13 @@ const IHDupKeyLen = 2 * (common.HashLength + common.IncarnationLength)
// IHCursor - holds logic related to iteration over IH bucket
type IHCursor struct {
c ethdb.CursorDupSort
filter Filter
c ethdb.CursorDupSort
cForDelete ethdb.CursorDupSort
filter Filter
}
func IH(f Filter, c ethdb.CursorDupSort) *IHCursor {
return &IHCursor{c: c, filter: f}
func IH(f Filter, c ethdb.CursorDupSort, cDelete ethdb.CursorDupSort) *IHCursor {
return &IHCursor{c: c, filter: f, cForDelete: cDelete}
}
func (c *IHCursor) _seek(seek []byte) (k, v []byte, err error) {
@ -763,6 +764,7 @@ func (c *IHCursor) _seek(seek []byte) (k, v []byte, err error) {
return nil, nil, nil
}
kCopy, vCopy := common.CopyBytes(k), common.CopyBytes(v)
if len(v) > common.HashLength {
keyPart := len(v) - common.HashLength
k = append(k, v[:keyPart]...)
@ -773,7 +775,7 @@ func (c *IHCursor) _seek(seek []byte) (k, v []byte, err error) {
return k, v, nil
}
err = c.c.DeleteCurrent()
err = c.cForDelete.Delete(kCopy, vCopy)
if err != nil {
return []byte{}, nil, err
}
@ -791,6 +793,7 @@ func (c *IHCursor) _next() (k, v []byte, err error) {
return nil, nil, nil
}
kCopy, vCopy := common.CopyBytes(k), common.CopyBytes(v)
if len(v) > common.HashLength {
keyPart := len(v) - common.HashLength
k = append(k, v[:keyPart]...)
@ -801,7 +804,7 @@ func (c *IHCursor) _next() (k, v []byte, err error) {
return k, v, nil
}
err = c.c.DeleteCurrent()
err = c.cForDelete.Delete(kCopy, vCopy)
if err != nil {
return []byte{}, nil, err
}