mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-07-09 14:22:33 +00:00
[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:
parent
6feea90946
commit
cc9b8da351
@ -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
|
// Respond with an error if there's virtually 0 chance of mining a block
|
||||||
// with the CPU.
|
// with the CPU.
|
||||||
if !s.cfg.DAGParams.GenerateSupported {
|
if !s.cfg.DAGParams.GenerateSupported {
|
||||||
@ -2223,6 +2230,13 @@ func handleGetGenerate(s *Server, cmd interface{}, closeChan <-chan struct{}) (i
|
|||||||
|
|
||||||
// handleGetHashesPerSec implements the getHashesPerSec command.
|
// handleGetHashesPerSec implements the getHashesPerSec command.
|
||||||
func handleGetHashesPerSec(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
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
|
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
|
// handleGetMiningInfo implements the getMiningInfo command. We only return the
|
||||||
// fields that are not related to wallet functionality.
|
// fields that are not related to wallet functionality.
|
||||||
func handleGetMiningInfo(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
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
|
// Create a default getNetworkHashPs command to use defaults and make
|
||||||
// use of the existing getNetworkHashPs handler.
|
// use of the existing getNetworkHashPs handler.
|
||||||
gnhpsCmd := btcjson.NewGetNetworkHashPSCmd(nil, nil)
|
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.
|
// This command had been (possibly temporarily) dropped.
|
||||||
// Originally it relied on height, which no longer makes sense.
|
// Originally it relied on height, which no longer makes sense.
|
||||||
func handleGetNetworkHashPS(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
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
|
return nil, ErrRPCUnimplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3258,6 +3286,13 @@ func handleSendRawTransaction(s *Server, cmd interface{}, closeChan <-chan struc
|
|||||||
|
|
||||||
// handleSetGenerate implements the setGenerate command.
|
// handleSetGenerate implements the setGenerate command.
|
||||||
func handleSetGenerate(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
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)
|
c := cmd.(*btcjson.SetGenerateCmd)
|
||||||
|
|
||||||
// Disable generation regardless of the provided generate flag if the
|
// Disable generation regardless of the provided generate flag if the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user