diff --git a/cmd/kaspaminer/config.go b/cmd/kaspaminer/config.go index 68423b5ac..f78860feb 100644 --- a/cmd/kaspaminer/config.go +++ b/cmd/kaspaminer/config.go @@ -17,8 +17,9 @@ import ( ) const ( - defaultLogFilename = "kaspaminer.log" - defaultErrLogFilename = "kaspaminer_err.log" + defaultLogFilename = "kaspaminer.log" + defaultErrLogFilename = "kaspaminer_err.log" + defaultTargetBlockRateRatio = 2.0 ) var ( @@ -30,13 +31,13 @@ var ( ) type configFlags struct { - ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"` - RPCServer string `short:"s" long:"rpcserver" description:"RPC server to connect to"` - MiningAddr string `long:"miningaddr" description:"Address to mine to"` - NumberOfBlocks uint64 `short:"n" long:"numblocks" description:"Number of blocks to mine. If omitted, will mine until the process is interrupted."` - MineWhenNotSynced bool `long:"mine-when-not-synced" description:"Mine even if the node is not synced with the rest of the network."` - Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"` - TargetBlocksPerSecond float64 `long:"target-blocks-per-second" description:"Sets a maximum block rate. This flag is for debugging purposes."` + ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"` + RPCServer string `short:"s" long:"rpcserver" description:"RPC server to connect to"` + MiningAddr string `long:"miningaddr" description:"Address to mine to"` + NumberOfBlocks uint64 `short:"n" long:"numblocks" description:"Number of blocks to mine. If omitted, will mine until the process is interrupted."` + MineWhenNotSynced bool `long:"mine-when-not-synced" description:"Mine even if the node is not synced with the rest of the network."` + Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"` + TargetBlocksPerSecond *float64 `long:"target-blocks-per-second" description:"Sets a maximum block rate. 0 means no limit (The default one is 2 * target network block rate)"` config.NetworkFlags } @@ -64,6 +65,11 @@ func parseConfig() (*configFlags, error) { return nil, err } + if cfg.TargetBlocksPerSecond == nil { + targetBlocksPerSecond := defaultTargetBlockRateRatio / cfg.NetParams().TargetTimePerBlock.Seconds() + cfg.TargetBlocksPerSecond = &targetBlocksPerSecond + } + if cfg.Profile != "" { profilePort, err := strconv.Atoi(cfg.Profile) if err != nil || profilePort < 1024 || profilePort > 65535 { diff --git a/cmd/kaspaminer/main.go b/cmd/kaspaminer/main.go index 27729b511..593451eee 100644 --- a/cmd/kaspaminer/main.go +++ b/cmd/kaspaminer/main.go @@ -48,7 +48,7 @@ func main() { doneChan := make(chan struct{}) spawn("mineLoop", func() { - err = mineLoop(client, cfg.NumberOfBlocks, cfg.TargetBlocksPerSecond, cfg.MineWhenNotSynced, miningAddr) + err = mineLoop(client, cfg.NumberOfBlocks, *cfg.TargetBlocksPerSecond, cfg.MineWhenNotSynced, miningAddr) if err != nil { panic(errors.Wrap(err, "error in mine loop")) }