Skip to content

Commit bcd8aee

Browse files
committed
eth: add chaindbProperty to debug API
1 parent 05e257c commit bcd8aee

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

eth/api.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"math/big"
2727
"os"
2828
"runtime"
29+
"strings"
2930
"sync"
3031
"time"
3132

@@ -46,6 +47,7 @@ import (
4647
"github.com/ethereum/go-ethereum/p2p"
4748
"github.com/ethereum/go-ethereum/rlp"
4849
"github.com/ethereum/go-ethereum/rpc"
50+
"github.com/syndtr/goleveldb/leveldb"
4951
"golang.org/x/net/context"
5052
)
5153

@@ -1566,6 +1568,22 @@ func NewPrivateDebugAPI(config *core.ChainConfig, eth *Ethereum) *PrivateDebugAP
15661568
return &PrivateDebugAPI{config: config, eth: eth}
15671569
}
15681570

1571+
// ChaindbProperty returns leveldb properties of the chain database.
1572+
func (api *PrivateDebugAPI) ChaindbProperty(property string) (string, error) {
1573+
ldb, ok := api.eth.chainDb.(interface {
1574+
LDB() *leveldb.DB
1575+
})
1576+
if !ok {
1577+
return "", fmt.Errorf("chaindbProperty does not work for memory databases")
1578+
}
1579+
if property == "" {
1580+
property = "leveldb.stats"
1581+
} else if !strings.HasPrefix(property, "leveldb.") {
1582+
property = "leveldb." + property
1583+
}
1584+
return ldb.LDB().GetProperty(property)
1585+
}
1586+
15691587
// BlockTraceResults is the returned value when replaying a block to check for
15701588
// consensus results and full VM trace logs for all included transactions.
15711589
type BlockTraceResult struct {

rpc/javascript.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ web3._extend({
295295
call: 'debug_dumpBlock',
296296
params: 1
297297
}),
298+
new web3._extend.Method({
299+
name: 'chaindbProperty',
300+
call: 'debug_chaindbProperty',
301+
params: 1,
302+
outputFormatter: console.log
303+
}),
298304
new web3._extend.Method({
299305
name: 'metrics',
300306
call: 'debug_metrics',

0 commit comments

Comments
 (0)