erigon-pulse/common/changeset/storage_changeset.go

97 lines
2.7 KiB
Go
Raw Normal View History

package changeset
import (
"errors"
Merge account and storage resolvers (#504) * add_incarnation_to_acc_root_in_ih * merge cached resolver into stateful resolver * - move account root set to "post iteration" of resolver - rename "cache" to IntermediateHash * remove blockNR and bucket params from walker * fix out of range panic * calc acc.Root on the fly * remove fieldSet field from resolver, make logic of root - lazy * remove 2 parameters * working version of forward-only walk over Acc and Storage * improve test * rebase master * save progress - more tests for PrepareResolveParams, add dedicated ResolveSet for storage. Problem: See duplicates in ResolveSet hexes. Next test failing: oracle_test.go * skip old incarnations * don't rebuild when 0 requests * fix tests * start from account key when need resolve storage * Error: stateless prototype faced hashNode when extracting witness * Statless works: copy touches * Remove getAccRoot function * Remove "isAccount" parameter from resolver signature * Fix: use correct storageResolveSet in finaliseStorageRoot * Fix: when startKey changed - reset storage buffers also * Fix: if account incarnation=0 - set EmptyRoot * Fix: remove account roots by default from IntermediateHash bucket * Fix: skip abandoned storage - which appeared just after startKey * Fix: did reset acc key incorrectly * Fix: clean previous key if receive IH * Fix: IH observer - subscribe only to branch nodes (was subscribed to value nodes also) * Add DISABLE_IH and STORE_ACCOUNT_ROOT env variables for tests * Remove accNode from IH cycle * Fix flags * Fix: reset succStorage also * Fix: skip IH if it has wrong incarnation * Fix: skip IH if it has wrong incarnation * Fix: skip IH if it has wrong incarnation * Fix: use rssStorage to HashOnly check * Fix: remove termination symbol from resolveRequest * cleanup * Fix: skip abandoned storage after IH * Debug This reverts commit 9c5eb69465f25607d546b03359b2cbcb1bd46689. * Fix linters * add_incarnation_to_acc_root_in_ih * merge cached resolver into stateful resolver * - move account root set to "post iteration" of resolver - rename "cache" to IntermediateHash * remove blockNR and bucket params from walker * fix out of range panic * calc acc.Root on the fly * remove fieldSet field from resolver, make logic of root - lazy * remove 2 parameters * working version of forward-only walk over Acc and Storage * improve test * rebase master * save progress - more tests for PrepareResolveParams, add dedicated ResolveSet for storage. Problem: See duplicates in ResolveSet hexes. Next test failing: oracle_test.go * skip old incarnations * don't rebuild when 0 requests * fix tests * start from account key when need resolve storage * Error: stateless prototype faced hashNode when extracting witness * Statless works: copy touches * Remove getAccRoot function * Remove "isAccount" parameter from resolver signature * Fix: use correct storageResolveSet in finaliseStorageRoot * Fix: when startKey changed - reset storage buffers also * Fix: if account incarnation=0 - set EmptyRoot * Fix: remove account roots by default from IntermediateHash bucket * Fix: skip abandoned storage - which appeared just after startKey * Fix: did reset acc key incorrectly * Fix: clean previous key if receive IH * Fix: IH observer - subscribe only to branch nodes (was subscribed to value nodes also) * Add DISABLE_IH and STORE_ACCOUNT_ROOT env variables for tests * Remove accNode from IH cycle * Fix flags * Fix: reset succStorage also * Fix: skip IH if it has wrong incarnation * Fix: skip IH if it has wrong incarnation * Fix: skip IH if it has wrong incarnation * Fix: use rssStorage to HashOnly check * Fix: remove termination symbol from resolveRequest * cleanup * Fix: skip abandoned storage after IH * remove inc * remove inc from rss * tr.succStorage.Reset() * remove inc from rss * Remove hard-coding * succ.Reset * Enable CalcTrieRoots * Proper dumping of the trie * Debug * Fix for CalcTrieRoot * Fix another inteference bug * Temp * Fix test * Cleanup * remove STORE_ACCOUNT_ROOT=true flag * Fix linter * Fix linter * Disable getnodedata by default * Fix test * Fix test Co-authored-by: Alexey Akhunov <akhounov@gmail.com>
2020-05-02 18:00:57 +00:00
"github.com/ledgerwatch/turbo-geth/common"
)
const (
DefaultIncarnation = uint64(1)
)
var (
ErrNotFound = errors.New("not found")
errIncorrectData = errors.New("empty prepared data")
ErrFindValue = errors.New("find value error")
)
2020-02-26 22:36:34 +00:00
/* Hashed changesets (key is a hash of common.Address) */
func NewStorageChangeSet() *ChangeSet {
return &ChangeSet{
Changes: make([]Change, 0),
keyLen: 2*common.HashLength + common.IncarnationLength,
}
}
func EncodeStorage(s *ChangeSet) ([]byte, error) {
return encodeStorage(s, common.HashLength)
}
func DecodeStorage(b []byte) (*ChangeSet, error) {
cs := NewStorageChangeSet()
err := decodeStorage(b, common.HashLength, cs)
if err != nil {
return nil, err
}
return cs, nil
}
type StorageChangeSetBytes []byte
func (b StorageChangeSetBytes) Walk(f func(k, v []byte) error) error {
return walkStorageChangeSet(b, common.HashLength, f)
}
func (b StorageChangeSetBytes) Find(k []byte) ([]byte, error) {
return findWithoutIncarnationInStorageChangeSet(b, common.HashLength, k[:common.HashLength], k[common.HashLength:])
}
func (b StorageChangeSetBytes) FindWithIncarnation(k []byte) ([]byte, error) {
return findInStorageChangeSet(b, common.HashLength, k)
}
func (b StorageChangeSetBytes) FindWithoutIncarnation(addrHashToFind []byte, keyHashToFind []byte) ([]byte, error) {
return findWithoutIncarnationInStorageChangeSet(b, common.HashLength, addrHashToFind, keyHashToFind)
}
2020-02-26 22:36:34 +00:00
/* Plain changesets (key is a common.Address) */
2020-02-26 22:36:34 +00:00
func NewStorageChangeSetPlain() *ChangeSet {
return &ChangeSet{
Changes: make([]Change, 0),
keyLen: common.AddressLength + common.HashLength + common.IncarnationLength,
}
}
2020-02-26 22:36:34 +00:00
func EncodeStoragePlain(s *ChangeSet) ([]byte, error) {
return encodeStorage(s, common.AddressLength)
}
2020-02-26 22:36:34 +00:00
func DecodeStoragePlain(b []byte) (*ChangeSet, error) {
cs := NewStorageChangeSetPlain()
err := decodeStorage(b, common.AddressLength, cs)
if err != nil {
return nil, err
}
return cs, nil
}
type StorageChangeSetPlainBytes []byte
func (b StorageChangeSetPlainBytes) Walk(f func(k, v []byte) error) error {
return walkStorageChangeSet(b, common.AddressLength, f)
}
func (b StorageChangeSetPlainBytes) Find(k []byte) ([]byte, error) {
return findWithoutIncarnationInStorageChangeSet(b, common.AddressLength, k[:common.AddressLength], k[common.AddressLength:])
}
func (b StorageChangeSetPlainBytes) FindWithIncarnation(k []byte) ([]byte, error) {
return findInStorageChangeSet(b, common.AddressLength, k)
}
2020-02-28 19:48:52 +00:00
func (b StorageChangeSetPlainBytes) FindWithoutIncarnation(addressToFind []byte, keyToFind []byte) ([]byte, error) {
return findWithoutIncarnationInStorageChangeSet(b, common.AddressLength, addressToFind, keyToFind)
}