mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
63 lines
No EOL
1.7 KiB
Go
63 lines
No EOL
1.7 KiB
Go
// +build !js
|
|
package ethapi
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
"github.com/ethereum/go-ethereum/log"
|
|
"github.com/syndtr/goleveldb/leveldb"
|
|
"github.com/syndtr/goleveldb/leveldb/util"
|
|
)
|
|
|
|
// PrivateDebugAPI is the collection of Ethereum APIs exposed over the private
|
|
// debugging endpoint.
|
|
type PrivateDebugAPI struct {
|
|
b Backend
|
|
}
|
|
|
|
// NewPrivateDebugAPI creates a new API definition for the private debug methods
|
|
// of the Ethereum service.
|
|
func NewPrivateDebugAPI(b Backend) *PrivateDebugAPI {
|
|
return &PrivateDebugAPI{b: b}
|
|
}
|
|
|
|
// ChaindbProperty returns leveldb properties of the chain database.
|
|
func (api *PrivateDebugAPI) ChaindbProperty(property string) (string, error) {
|
|
ldb, ok := api.b.ChainDb().(interface {
|
|
LDB() *leveldb.DB
|
|
})
|
|
if !ok {
|
|
return "", fmt.Errorf("chaindbProperty does not work for memory databases")
|
|
}
|
|
if property == "" {
|
|
property = "leveldb.stats"
|
|
} else if !strings.HasPrefix(property, "leveldb.") {
|
|
property = "leveldb." + property
|
|
}
|
|
return ldb.LDB().GetProperty(property)
|
|
}
|
|
|
|
func (api *PrivateDebugAPI) ChaindbCompact() error {
|
|
ldb, ok := api.b.ChainDb().(interface {
|
|
LDB() *leveldb.DB
|
|
})
|
|
if !ok {
|
|
return fmt.Errorf("chaindbCompact does not work for memory databases")
|
|
}
|
|
for b := byte(0); b < 255; b++ {
|
|
log.Info("Compacting chain database", "range", fmt.Sprintf("0x%0.2X-0x%0.2X", b, b+1))
|
|
err := ldb.LDB().CompactRange(util.Range{Start: []byte{b}, Limit: []byte{b + 1}})
|
|
if err != nil {
|
|
log.Error("Database compaction failed", "err", err)
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// SetHead rewinds the head of the blockchain to a previous block.
|
|
func (api *PrivateDebugAPI) SetHead(number hexutil.Uint64) {
|
|
api.b.SetHead(uint64(number))
|
|
} |