[rpc] dont enable unsafe by default; limit /blockchain_info to 20 blocks

This commit is contained in:
Ethan Buchman
2017-05-22 07:51:14 -04:00
parent 3fbe286e5a
commit 4f27752468
2 changed files with 11 additions and 6 deletions

View File

@ -10,7 +10,7 @@ import (
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// TODO: limit/permission on (max - min) // Returns at most 20 blocks
func BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) { func BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) {
if maxHeight == 0 { if maxHeight == 0 {
maxHeight = blockStore.Height() maxHeight = blockStore.Height()
@ -19,7 +19,10 @@ func BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, err
} }
if minHeight == 0 { if minHeight == 0 {
minHeight = MaxInt(1, maxHeight-20) minHeight = MaxInt(1, maxHeight-20)
} else {
minHeight = MaxInt(minHeight, maxHeight-20)
} }
logger.Debug("BlockchainInfoHandler", "maxHeight", maxHeight, "minHeight", minHeight) logger.Debug("BlockchainInfoHandler", "maxHeight", maxHeight, "minHeight", minHeight)
blockMetas := []*types.BlockMeta{} blockMetas := []*types.BlockMeta{}

View File

@ -31,13 +31,15 @@ var Routes = map[string]*rpc.RPCFunc{
// abci API // abci API
"abci_query": rpc.NewRPCFunc(ABCIQuery, "path,data,prove"), "abci_query": rpc.NewRPCFunc(ABCIQuery, "path,data,prove"),
"abci_info": rpc.NewRPCFunc(ABCIInfo, ""), "abci_info": rpc.NewRPCFunc(ABCIInfo, ""),
}
func AddUnsafeRoutes() {
// control API // control API
"dial_seeds": rpc.NewRPCFunc(UnsafeDialSeeds, "seeds"), Routes["dial_seeds"] = rpc.NewRPCFunc(UnsafeDialSeeds, "seeds")
"unsafe_flush_mempool": rpc.NewRPCFunc(UnsafeFlushMempool, ""), Routes["unsafe_flush_mempool"] = rpc.NewRPCFunc(UnsafeFlushMempool, "")
// profiler API // profiler API
"unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfiler, "filename"), Routes["unsafe_start_cpu_profiler"] = rpc.NewRPCFunc(UnsafeStartCPUProfiler, "filename")
"unsafe_stop_cpu_profiler": rpc.NewRPCFunc(UnsafeStopCPUProfiler, ""), Routes["unsafe_stop_cpu_profiler"] = rpc.NewRPCFunc(UnsafeStopCPUProfiler, "")
"unsafe_write_heap_profile": rpc.NewRPCFunc(UnsafeWriteHeapProfile, "filename"), Routes["unsafe_write_heap_profile"] = rpc.NewRPCFunc(UnsafeWriteHeapProfile, "filename")
} }