mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-28 14:47:16 +00:00
af4a99b977
* 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>
84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
package state
|
|
|
|
import (
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/common/dbutils"
|
|
"github.com/ledgerwatch/turbo-geth/common/pool"
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
"github.com/ledgerwatch/turbo-geth/log"
|
|
"github.com/ledgerwatch/turbo-geth/metrics"
|
|
"github.com/ledgerwatch/turbo-geth/trie"
|
|
)
|
|
|
|
var (
|
|
InsertCounter = metrics.NewRegisteredCounter("db/ih/insert", nil)
|
|
DeleteCounter = metrics.NewRegisteredCounter("db/ih/delete", nil)
|
|
)
|
|
|
|
const keyBufferSize = 64
|
|
|
|
type IntermediateHashes struct {
|
|
trie.NoopObserver // make sure that we don't need to subscribe to unnecessary methods
|
|
putter ethdb.Putter
|
|
deleter ethdb.Deleter
|
|
}
|
|
|
|
func NewIntermediateHashes(putter ethdb.Putter, deleter ethdb.Deleter) *IntermediateHashes {
|
|
return &IntermediateHashes{putter: putter, deleter: deleter}
|
|
}
|
|
|
|
func (ih *IntermediateHashes) WillUnloadBranchNode(prefixAsNibbles []byte, nodeHash common.Hash, incarnation uint64) {
|
|
// only put to bucket prefixes with even number of nibbles
|
|
if len(prefixAsNibbles) == 0 || len(prefixAsNibbles)%2 == 1 {
|
|
return
|
|
}
|
|
|
|
InsertCounter.Inc(1)
|
|
|
|
buf := pool.GetBuffer(keyBufferSize)
|
|
defer pool.PutBuffer(buf)
|
|
trie.CompressNibbles(prefixAsNibbles, &buf.B)
|
|
|
|
var key []byte
|
|
if len(buf.B) > common.HashLength {
|
|
if incarnation == 0 {
|
|
panic("0 incarnation")
|
|
}
|
|
|
|
key = dbutils.GenerateCompositeStoragePrefix(buf.B[:common.HashLength], incarnation, buf.B[common.HashLength:])
|
|
} else {
|
|
key = common.CopyBytes(buf.B)
|
|
}
|
|
|
|
if err := ih.putter.Put(dbutils.IntermediateTrieHashBucket, key, common.CopyBytes(nodeHash[:])); err != nil {
|
|
log.Warn("could not put intermediate trie hash", "err", err)
|
|
}
|
|
}
|
|
|
|
func (ih *IntermediateHashes) BranchNodeLoaded(prefixAsNibbles []byte, incarnation uint64) {
|
|
// only put to bucket prefixes with even number of nibbles
|
|
if len(prefixAsNibbles) == 0 || len(prefixAsNibbles)%2 == 1 {
|
|
return
|
|
}
|
|
DeleteCounter.Inc(1)
|
|
|
|
buf := pool.GetBuffer(keyBufferSize)
|
|
defer pool.PutBuffer(buf)
|
|
trie.CompressNibbles(prefixAsNibbles, &buf.B)
|
|
|
|
var key []byte
|
|
if len(buf.B) > common.HashLength {
|
|
if incarnation == 0 {
|
|
panic("0 incarnation")
|
|
}
|
|
key = dbutils.GenerateCompositeStoragePrefix(buf.B[:common.HashLength], incarnation, buf.B[common.HashLength:])
|
|
} else {
|
|
key = common.CopyBytes(buf.B)
|
|
}
|
|
|
|
if err := ih.deleter.Delete(dbutils.IntermediateTrieHashBucket, key); err != nil {
|
|
log.Warn("could not delete intermediate trie hash", "err", err)
|
|
return
|
|
}
|
|
}
|