mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
* core/state: typo Signed-off-by: Delweng <delweng@gmail.com> * core/rawdb: backport from https://github.com/bnb-chain/bsc/pull/543 Signed-off-by: Delweng <delweng@gmail.com> * eth,ethdb,node,core/state: backport from https://github.com/bnb-chain/bsc/pull/543 Signed-off-by: Delweng <delweng@gmail.com> * eth,core: backport from https://github.com/bnb-chain/bsc/pull/543 Signed-off-by: Delweng <delweng@gmail.com> * cmd: open db with freeze disabled Signed-off-by: Delweng <delweng@gmail.com> * cli: snapshot prune-block Signed-off-by: Delweng <delweng@gmail.com> * fix typo Signed-off-by: Delweng <delweng@gmail.com> * cli/snapshot: fix the issue of dup open db error Signed-off-by: Delweng <delweng@gmail.com> * cli/snapshot: resolve datadir and ancient before backup Signed-off-by: Delweng <delweng@gmail.com> * core: more prune-block log Signed-off-by: Delweng <delweng@gmail.com> * core: truncatetail missing f.offset Signed-off-by: Delweng <delweng@gmail.com> * core/rawdb: indextx adjust offset of pruned block Signed-off-by: Delweng <delweng@gmail.com> * core/rawdb: freezer batch should implement the offset commit, ref https://github.com/bnb-chain/bsc/pull/1005 Signed-off-by: Delweng <delweng@gmail.com> * core: check of ancientdb, backport https://github.com/bnb-chain/bsc/pull/817 Signed-off-by: Delweng <delweng@gmail.com> * core/state: read raw borReceipt to backup Signed-off-by: Delweng <delweng@gmail.com> * core/rawdb: bor receipt maybe in []Receipt or Receipt RLP format Signed-off-by: Delweng <delweng@gmail.com> * core/state: typo and error msg Signed-off-by: Delweng <delweng@gmail.com> * core/rawdb: offSet -> offset Signed-off-by: Delweng <delweng@gmail.com> * cli/snapshot: comment Signed-off-by: Delweng <delweng@gmail.com> * cli/snapshot: add prune-block doc Signed-off-by: Delweng <delweng@gmail.com> * docs: add prune-block document Signed-off-by: Delweng <delweng@gmail.com> * core/rawdb: print wrong bor-receipt length Signed-off-by: Delweng <delweng@gmail.com> * internal/cli: add snapshot prune block tests (referenced from bsc's PR) * improve errors * cmd, core, eth, internal: fix lint * internal/cli: refactor snapshot prune block test * fix linters in tests * internal/cli: add inspect-ancient-db command, update docs * pruner: use a generic function for simplification * internal/cli: fixes for inspect-db command * internal/cli: improve pruning tests * core/rawdb: update end block calculation logic in inspect command * core/rawdb: improve checks db initialisation * core/rawdb: remove offset check * update mocks for span, ethdb and add command in makefile * docs/cli: update docs with inspect command * go mod tidy * refactor and resolve conflicts * resolve more conflicts * refactor * explicitly read node for hash scheme * add check for hash scheme, fix tests * fix typo * update docs and add warning * raise error if pbss is enabled * revert read raw bor receipt change * consensus/bor: handle nil header case in get root hash * address comments * core/rawdb: check chain continuity by matching parent hash * core/rawdb: account for pruned ancient blocks * go mod tidy * fix tests * fix tests --------- Signed-off-by: Delweng <delweng@gmail.com> Co-authored-by: Delweng <delweng@gmail.com>
171 lines
4.1 KiB
Go
171 lines
4.1 KiB
Go
// Copyright 2022 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 remotedb implements the key-value database layer based on a remote geth
|
|
// node. Under the hood, it utilises the `debug_dbGet` method to implement a
|
|
// read-only database.
|
|
// There really are no guarantees in this database, since the local geth does not
|
|
// exclusive access, but it can be used for basic diagnostics of a remote node.
|
|
package remotedb
|
|
|
|
import (
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
)
|
|
|
|
// Database is a key-value lookup for a remote database via debug_dbGet.
|
|
type Database struct {
|
|
remote *rpc.Client
|
|
}
|
|
|
|
func (db *Database) Has(key []byte) (bool, error) {
|
|
if _, err := db.Get(key); err != nil {
|
|
//nolint:nilerr
|
|
return false, nil
|
|
}
|
|
|
|
return true, nil
|
|
}
|
|
|
|
func (db *Database) Get(key []byte) ([]byte, error) {
|
|
var resp hexutil.Bytes
|
|
err := db.remote.Call(&resp, "debug_dbGet", hexutil.Bytes(key))
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return resp, nil
|
|
}
|
|
|
|
func (db *Database) HasAncient(kind string, number uint64) (bool, error) {
|
|
if _, err := db.Ancient(kind, number); err != nil {
|
|
//nolint:nilerr
|
|
return false, nil
|
|
}
|
|
|
|
return true, nil
|
|
}
|
|
|
|
func (db *Database) Ancient(kind string, number uint64) ([]byte, error) {
|
|
var resp hexutil.Bytes
|
|
err := db.remote.Call(&resp, "debug_dbAncient", kind, number)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return resp, nil
|
|
}
|
|
|
|
func (db *Database) AncientRange(kind string, start, count, maxBytes uint64) ([][]byte, error) {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) Ancients() (uint64, error) {
|
|
var resp uint64
|
|
err := db.remote.Call(&resp, "debug_dbAncients")
|
|
|
|
return resp, err
|
|
}
|
|
|
|
func (db *Database) AncientOffSet() uint64 {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) ItemAmountInAncient() (uint64, error) {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) Tail() (uint64, error) {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) AncientSize(kind string) (uint64, error) {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) ReadAncients(fn func(op ethdb.AncientReaderOp) error) (err error) {
|
|
return fn(db)
|
|
}
|
|
|
|
func (db *Database) Put(key []byte, value []byte) error {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) Delete(key []byte) error {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) ModifyAncients(f func(ethdb.AncientWriteOp) error) (int64, error) {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) TruncateHead(n uint64) (uint64, error) {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) TruncateTail(n uint64) (uint64, error) {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) Sync() error {
|
|
return nil
|
|
}
|
|
|
|
func (db *Database) MigrateTable(s string, f func([]byte) ([]byte, error)) error {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) NewBatch() ethdb.Batch {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) NewBatchWithSize(size int) ethdb.Batch {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) Stat(property string) (string, error) {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) AncientDatadir() (string, error) {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) Compact(start []byte, limit []byte) error {
|
|
return nil
|
|
}
|
|
|
|
func (db *Database) NewSnapshot() (ethdb.Snapshot, error) {
|
|
panic("not supported")
|
|
}
|
|
|
|
func (db *Database) Close() error {
|
|
db.remote.Close()
|
|
return nil
|
|
}
|
|
|
|
func New(client *rpc.Client) ethdb.Database {
|
|
return &Database{
|
|
remote: client,
|
|
}
|
|
}
|