erigon-pulse/ethdb/bolt_db.go

102 lines
2.9 KiB
Go
Raw Normal View History

2019-07-22 09:17:27 +00:00
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
2015-07-07 00:54:22 +00:00
//
// The go-ethereum library is free software: you can redistribute it and/or modify
2015-07-07 00:54:22 +00:00
// 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,
2015-07-07 00:54:22 +00:00
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2015-07-07 00:54:22 +00:00
// 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/>.
2015-07-07 00:54:22 +00:00
// Package ethdb defines the interfaces for an Ethereum data store.
2014-02-14 22:56:09 +00:00
package ethdb
import (
"bytes"
"context"
"github.com/ledgerwatch/turbo-geth/common"
Intermediate hash phase 3 (#377) * #remove debug prints * remove storage-mode="i" * minnet re-execute hack with checkpoints * minnet re-execute hack with checkpoints * rollback to master setup * mainnet re-exec hack * rollback some changes * v0 of "push down" functionality * move all logic to own functions * handle case when re-created account already has some storage * clear path for storage * try to rely on tree structure (but maybe need to rely on DB because can be intra-block re-creations of account) * fix some bugs with indexes, moving to tests * tests added * make linter happy * make linter happy * simplify logic * adjust comparison of keys with and without incarnation * test for keyIsBefore * test for keyIsBefore * better nibbles alignment * better nibbles alignment * cleanup * continue work on tests * simplify test * check tombstone existence before pushing it down. * put tombstone only when account deleted, not created * put tombstone only when account has storage * make linter happy * test for storage resolver * make fixedbytes work without incarnation * fix panic on short keys * use special comparison only when working with keys from cache * add blockNr for better tracing * fix: incorrect tombstone check * fix: incorrect tombstone check * trigger ci * hack for problem block * more test-cases * add test case for too long keys * speedup cached resolver by removing bucket creation transaction * remove parent type check in pruning, remove unused copy from mutation.put * dump resolving info on fail * dump resolving info on fail * set tombstone everytime for now to check if it will help * on unload: check parent type, not type of node * fix wrong order of checking node type * fix wrong order of checking node type * rebase to new master * make linter happy * rebase to new master * place tombstone only if acc has storage * rebase master * rebase master * rebase master * rebase master Co-authored-by: alex.sharov <alex.sharov@lazada.com>
2020-03-11 10:31:49 +00:00
"github.com/ledgerwatch/turbo-geth/core/types/accounts"
)
// Type which expecting sequence of triplets: dbi, key, value, ....
// It sorts entries by dbi name, then inside dbi clusters sort by keys
type MultiPutTuples [][]byte
func (t MultiPutTuples) Len() int { return len(t) / 3 }
func (t MultiPutTuples) Less(i, j int) bool {
cmp := bytes.Compare(t[i*3], t[j*3])
if cmp == -1 {
return true
}
if cmp == 0 {
return bytes.Compare(t[i*3+1], t[j*3+1]) == -1
}
return false
}
func (t MultiPutTuples) Swap(i, j int) {
t[i*3], t[j*3] = t[j*3], t[i*3]
t[i*3+1], t[j*3+1] = t[j*3+1], t[i*3+1]
t[i*3+2], t[j*3+2] = t[j*3+2], t[i*3+2]
}
func Get(db KV, bucket, key []byte) ([]byte, error) {
// Retrieve the key and increment the miss counter if not found
var dat []byte
err := db.View(context.Background(), func(tx Tx) error {
b := tx.Bucket(bucket)
if b != nil {
v, _ := b.Get(key)
if v != nil {
dat = make([]byte, len(v))
copy(dat, v)
}
}
return nil
})
if dat == nil {
return nil, ErrKeyNotFound
}
return dat, err
}
func HackAddRootToAccountBytes(accNoRoot []byte, root []byte) (accWithRoot []byte, err error) {
var acc accounts.Account
if err := acc.DecodeForStorage(accNoRoot); err != nil {
return nil, err
}
acc.Root = common.BytesToHash(root)
accWithRoot = make([]byte, acc.EncodingLengthForStorage())
acc.EncodeForStorage(accWithRoot)
return accWithRoot, nil
}
func Bytesmask(fixedbits int) (fixedbytes int, mask byte) {
fixedbytes = (fixedbits + 7) / 8
shiftbits := fixedbits & 7
mask = byte(0xff)
if shiftbits != 0 {
mask = 0xff << (8 - shiftbits)
}
return fixedbytes, mask
}
func InspectDatabase(db Database) error {
// FIXME: implement in Turbo-Geth
// see https://github.com/ethereum/go-ethereum/blob/f5d89cdb72c1e82e9deb54754bef8dd20bf12591/core/rawdb/database.go#L224
return errNotSupported
2019-03-14 06:59:47 +00:00
}
func NewDatabaseWithFreezer(db *ObjectDatabase, dir, suffix string) (*ObjectDatabase, error) {
// FIXME: implement freezer in Turbo-Geth
return db, nil
}