erigon-pulse/core/rawdb/accessors_account.go

60 lines
1.9 KiB
Go
Raw Normal View History

// Copyright 2018 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package rawdb
import (
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/core/types/accounts"
)
// ReadAccount reading account object from multiple buckets of db
func ReadAccount(db DatabaseReader, addrHash common.Hash, acc *accounts.Account) (bool, error) {
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
addrHashBytes := addrHash[:]
enc, err := db.Get(dbutils.CurrentStateBucket, addrHashBytes)
if err != nil {
return false, err
}
if err = acc.DecodeForStorage(enc); err != nil {
return false, err
}
return true, nil
}
func WriteAccount(db DatabaseWriter, addrHash common.Hash, acc accounts.Account) error {
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
//fmt.Printf("WriteAccount: %x %x\n", addrHash, acc.Root)
addrHashBytes := addrHash[:]
value := make([]byte, acc.EncodingLengthForStorage())
acc.EncodeForStorage(value)
return db.Put(dbutils.CurrentStateBucket, addrHashBytes, value)
}
type DatabaseReaderDeleter interface {
DatabaseReader
DatabaseDeleter
}
func DeleteAccount(db DatabaseReaderDeleter, addrHash common.Hash) error {
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
addrHashBytes := addrHash[:]
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
if err := db.Delete(dbutils.CurrentStateBucket, addrHashBytes); err != nil {
return err
}
return nil
}