erigon-pulse/common/changeset/account_changeset_utils.go
Alex Sharov b3f1915d09
ChangeSets dupsort (#1342)
* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* change_set_dup

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* working version

* aa

* aa

* aa

* aa

* aa

* aa

* aa

* aa

* aa

* aa

* aa

* aa

* aa

* aa

* aa

* squash

* squash

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* history_early_stop

* history_early_stop

* vmConfig with ReadOnly false

* auto_increment

* auto_increment

* rebase master

Co-authored-by: Alexey Akhunov <akhounov@gmail.com>
2020-11-16 12:08:28 +00:00

37 lines
865 B
Go

package changeset
import (
"bytes"
"sort"
"github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/ethdb"
)
func findInAccountChangeSet(c ethdb.CursorDupSort, blockNumber uint64, key []byte, keyLen int) ([]byte, error) {
fromDBFormat := FromDBFormat(keyLen)
k, v, err := c.SeekBothRange(dbutils.EncodeBlockNumber(blockNumber), key)
if err != nil {
return nil, err
}
_, k, v = fromDBFormat(k, v)
if !bytes.HasPrefix(k, key) {
return nil, nil
}
return v, nil
}
func encodeAccounts2(blockN uint64, s *ChangeSet, f func(k, v []byte) error) error {
sort.Sort(s)
newK := dbutils.EncodeBlockNumber(blockN)
for _, cs := range s.Changes {
newV := make([]byte, len(cs.Key)+len(cs.Value))
copy(newV, cs.Key)
copy(newV[len(cs.Key):], cs.Value)
if err := f(newK, newV); err != nil {
return err
}
}
return nil
}