[DEV-355] Disable all mining-related API calls on partial nodes (#151)

* [DEV-355] Disallowed mining-related RPC commands from running on any sub-network besides the "all" sub-network.

* [DEV-335] Fixed formatting errors.

* [DEV-335] Fixed some more formatting errors.

* [DEV-335] Changed error type to ErrRPCInvalidRequest and rephrased the error message.

* [DEV-335] Fixed formatting.

* [DEV-335] Removed error from getGenerate.
This commit is contained in:
stasatdaglabs 2019-01-09 12:54:43 +02:00 committed by Svarog
parent 6feea90946
commit cc9b8da351

View File

@ -889,6 +889,13 @@ func handleGenerate(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte
}
}
if config.MainConfig().SubNetwork != wire.SubNetworkSupportsAll {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidRequest.Code,
Message: "`generate` is not supported on partial nodes.",
}
}
// Respond with an error if there's virtually 0 chance of mining a block
// with the CPU.
if !s.cfg.DAGParams.GenerateSupported {
@ -2223,6 +2230,13 @@ func handleGetGenerate(s *Server, cmd interface{}, closeChan <-chan struct{}) (i
// handleGetHashesPerSec implements the getHashesPerSec command.
func handleGetHashesPerSec(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
if config.MainConfig().SubNetwork != wire.SubNetworkSupportsAll {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidRequest.Code,
Message: "`getHashesPerSec` is not supported on partial nodes.",
}
}
return int64(s.cfg.CPUMiner.HashesPerSecond()), nil
}
@ -2305,6 +2319,13 @@ func handleGetMempoolInfo(s *Server, cmd interface{}, closeChan <-chan struct{})
// handleGetMiningInfo implements the getMiningInfo command. We only return the
// fields that are not related to wallet functionality.
func handleGetMiningInfo(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
if config.MainConfig().SubNetwork != wire.SubNetworkSupportsAll {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidRequest.Code,
Message: "`getMiningInfo` is not supported on partial nodes.",
}
}
// Create a default getNetworkHashPs command to use defaults and make
// use of the existing getNetworkHashPs handler.
gnhpsCmd := btcjson.NewGetNetworkHashPSCmd(nil, nil)
@ -2360,6 +2381,13 @@ func handleGetNetTotals(s *Server, cmd interface{}, closeChan <-chan struct{}) (
// This command had been (possibly temporarily) dropped.
// Originally it relied on height, which no longer makes sense.
func handleGetNetworkHashPS(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
if config.MainConfig().SubNetwork != wire.SubNetworkSupportsAll {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidRequest.Code,
Message: "`getNetworkHashPS` is not supported on partial nodes.",
}
}
return nil, ErrRPCUnimplemented
}
@ -3258,6 +3286,13 @@ func handleSendRawTransaction(s *Server, cmd interface{}, closeChan <-chan struc
// handleSetGenerate implements the setGenerate command.
func handleSetGenerate(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
if config.MainConfig().SubNetwork != wire.SubNetworkSupportsAll {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidRequest.Code,
Message: "`setGenerate` is not supported on partial nodes.",
}
}
c := cmd.(*btcjson.SetGenerateCmd)
// Disable generation regardless of the provided generate flag if the