erigon-pulse/turbo/trie/trie_observers.go

113 lines
3.3 KiB
Go
Raw Normal View History

package trie
import "github.com/ledgerwatch/turbo-geth/common"
type Observer interface {
BranchNodeCreated(hex []byte)
BranchNodeDeleted(hex []byte)
BranchNodeTouched(hex []byte)
CodeNodeCreated(hex []byte, size uint)
CodeNodeDeleted(hex []byte)
CodeNodeTouched(hex []byte)
CodeNodeSizeChanged(hex []byte, newSize uint)
WillUnloadBranchNode(key []byte, nodeHash common.Hash, incarnation uint64)
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
WillUnloadNode(key []byte, nodeHash common.Hash)
BranchNodeLoaded(prefixAsNibbles []byte, incarnation uint64)
}
var _ Observer = (*NoopObserver)(nil) // make sure that NoopTrieObserver is compliant
// NoopTrieObserver might be used to emulate optional methods in observers
type NoopObserver struct{}
func (*NoopObserver) BranchNodeCreated(_ []byte) {}
func (*NoopObserver) BranchNodeDeleted(_ []byte) {}
func (*NoopObserver) BranchNodeTouched(_ []byte) {}
func (*NoopObserver) CodeNodeCreated(_ []byte, _ uint) {}
func (*NoopObserver) CodeNodeDeleted(_ []byte) {}
func (*NoopObserver) CodeNodeTouched(_ []byte) {}
func (*NoopObserver) CodeNodeSizeChanged(_ []byte, _ uint) {}
func (*NoopObserver) WillUnloadBranchNode(_ []byte, _ common.Hash, _ uint64) {}
func (*NoopObserver) WillUnloadNode(_ []byte, _ common.Hash) {}
func (*NoopObserver) BranchNodeLoaded(_ []byte, _ uint64) {}
// TrieObserverMux multiplies the callback methods and sends them to
// all it's children.
type ObserverMux struct {
children []Observer
}
func NewTrieObserverMux() *ObserverMux {
return &ObserverMux{make([]Observer, 0)}
}
func (mux *ObserverMux) AddChild(child Observer) {
if child == nil {
return
}
mux.children = append(mux.children, child)
}
func (mux *ObserverMux) BranchNodeCreated(hex []byte) {
for _, child := range mux.children {
child.BranchNodeCreated(hex)
}
}
func (mux *ObserverMux) BranchNodeDeleted(hex []byte) {
for _, child := range mux.children {
child.BranchNodeDeleted(hex)
}
}
func (mux *ObserverMux) BranchNodeTouched(hex []byte) {
for _, child := range mux.children {
child.BranchNodeTouched(hex)
}
}
func (mux *ObserverMux) CodeNodeCreated(hex []byte, size uint) {
for _, child := range mux.children {
child.CodeNodeCreated(hex, size)
}
}
func (mux *ObserverMux) CodeNodeDeleted(hex []byte) {
for _, child := range mux.children {
child.CodeNodeDeleted(hex)
}
}
func (mux *ObserverMux) CodeNodeTouched(hex []byte) {
for _, child := range mux.children {
child.CodeNodeTouched(hex)
}
}
func (mux *ObserverMux) CodeNodeSizeChanged(hex []byte, newSize uint) {
for _, child := range mux.children {
child.CodeNodeSizeChanged(hex, newSize)
}
}
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
func (mux *ObserverMux) WillUnloadNode(key []byte, nodeHash common.Hash) {
for _, child := range mux.children {
child.WillUnloadNode(key, nodeHash)
}
}
func (mux *ObserverMux) WillUnloadBranchNode(key []byte, nodeHash common.Hash, incarnation uint64) {
for _, child := range mux.children {
child.WillUnloadBranchNode(key, nodeHash, incarnation)
}
}
func (mux *ObserverMux) BranchNodeLoaded(prefixAsNibbles []byte, incarnation uint64) {
for _, child := range mux.children {
child.BranchNodeLoaded(prefixAsNibbles, incarnation)
}
}