2019-07-22 09:17:27 +00:00
|
|
|
// Copyright 2014 The go-ethereum Authors
|
2015-07-22 16:48:40 +00:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-07-07 00:54:22 +00:00
|
|
|
//
|
2015-07-23 16:35:11 +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.
|
|
|
|
//
|
2015-07-22 16:48:40 +00:00
|
|
|
// 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
|
2015-07-22 16:48:40 +00:00
|
|
|
// 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
|
2015-07-22 16:48:40 +00:00
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-07-07 00:54:22 +00:00
|
|
|
|
2019-03-26 14:48:31 +00:00
|
|
|
// Package ethdb defines the interfaces for an Ethereum data store.
|
2014-02-14 22:56:09 +00:00
|
|
|
package ethdb
|
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
import (
|
|
|
|
"bytes"
|
2020-03-20 10:06:14 +00:00
|
|
|
"context"
|
2018-09-24 12:57:49 +00:00
|
|
|
|
2020-01-31 04:11:20 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
2020-03-11 10:31:49 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/core/types/accounts"
|
2020-05-28 11:34:37 +00:00
|
|
|
)
|
|
|
|
|
2020-05-30 08:12:21 +00:00
|
|
|
// Type which expecting sequence of triplets: dbi, key, value, ....
|
|
|
|
// It sorts entries by dbi name, then inside dbi clusters sort by keys
|
2020-05-17 04:46:30 +00:00
|
|
|
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]
|
|
|
|
}
|
|
|
|
|
2020-05-27 16:24:34 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-04-18 20:09:44 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-05-11 04:46:07 +00:00
|
|
|
func Bytesmask(fixedbits int) (fixedbytes int, mask byte) {
|
|
|
|
fixedbytes = (fixedbits + 7) / 8
|
2019-05-27 13:51:49 +00:00
|
|
|
shiftbits := fixedbits & 7
|
|
|
|
mask = byte(0xff)
|
|
|
|
if shiftbits != 0 {
|
|
|
|
mask = 0xff << (8 - shiftbits)
|
|
|
|
}
|
|
|
|
return fixedbytes, mask
|
all: integrate the freezer with fast sync
* all: freezer style syncing
core, eth, les, light: clean up freezer relative APIs
core, eth, les, trie, ethdb, light: clean a bit
core, eth, les, light: add unit tests
core, light: rewrite setHead function
core, eth: fix downloader unit tests
core: add receipt chain insertion test
core: use constant instead of hardcoding table name
core: fix rollback
core: fix setHead
core/rawdb: remove canonical block first and then iterate side chain
core/rawdb, ethdb: add hasAncient interface
eth/downloader: calculate ancient limit via cht first
core, eth, ethdb: lots of fixes
* eth/downloader: print ancient disable log only for fast sync
2019-04-25 14:59:48 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-07-19 08:11:53 +00:00
|
|
|
func NewDatabaseWithFreezer(db *ObjectDatabase, dir, suffix string) (*ObjectDatabase, error) {
|
2019-05-27 13:51:49 +00:00
|
|
|
// FIXME: implement freezer in Turbo-Geth
|
|
|
|
return db, nil
|
2018-01-30 17:03:31 +00:00
|
|
|
}
|