Skip to content

Commit d6775e7

Browse files
committed
Add safe mode config and startup override
1 parent 0daaba8 commit d6775e7

File tree

9 files changed

+61
-1
lines changed

9 files changed

+61
-1
lines changed

config_build.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func buildBaseFileConfig(cfg Config) baseFileConfig {
2828
StratumPasswordEnabled: cfg.StratumPasswordEnabled,
2929
StratumPassword: cfg.StratumPassword,
3030
StratumPasswordPublic: cfg.StratumPasswordPublic,
31+
SafeMode: cfg.SafeMode,
3132
},
3233
Node: nodeConfig{
3334
RPCURL: cfg.RPCURL,
@@ -198,6 +199,7 @@ func (cfg Config) Effective() EffectiveConfig {
198199
StratumTLSListen: cfg.StratumTLSListen,
199200
StratumFastDecodeEnabled: cfg.StratumFastDecodeEnabled,
200201
StratumFastEncodeEnabled: cfg.StratumFastEncodeEnabled,
202+
SafeMode: cfg.SafeMode,
201203
CKPoolEmulate: cfg.CKPoolEmulate,
202204
StratumTCPReadBufferBytes: cfg.StratumTCPReadBufferBytes,
203205
StratumTCPWriteBufferBytes: cfg.StratumTCPWriteBufferBytes,

config_examples.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ func baseConfigDocComments() []byte {
9494
# - [stratum].stratum_password_enabled: Require miners to send a password on authorize (requires restart).
9595
# - [stratum].stratum_password: Password string checked against mining.authorize params (requires restart).
9696
# - [stratum].stratum_password_public: Show the stratum password on the public connect panel (requires restart).
97+
# - [stratum].safe_mode: Force conservative compatibility/safety behavior (disables fast-path Stratum tuning and unsafe debug/public-RPC toggles).
98+
# - Runtime override: --safe-mode=true/false
9799
#
98100
# Logging
99101
# - [logging].level: debug, info, warn, error (requires restart).

config_file_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type stratumConfig struct {
3939
StratumPasswordEnabled bool `toml:"stratum_password_enabled"`
4040
StratumPassword string `toml:"stratum_password"`
4141
StratumPasswordPublic bool `toml:"stratum_password_public"`
42+
SafeMode bool `toml:"safe_mode"`
4243
}
4344

4445
type authConfig struct {

config_load.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ func applyBaseConfig(cfg *Config, fc baseFileConfigRead) (configChanged bool, mi
233233
cfg.StratumPassword = ""
234234
}
235235
cfg.StratumPasswordPublic = fc.Stratum.StratumPasswordPublic
236+
cfg.SafeMode = fc.Stratum.SafeMode
236237
if fc.Node.RPCURL != "" {
237238
cfg.RPCURL = fc.Node.RPCURL
238239
}

config_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ type Config struct {
6161
// Stratum fast encode: enables canned/manual JSON encoding for common Stratum
6262
// responses to reduce allocations (encode path only).
6363
StratumFastEncodeEnabled bool
64+
// Safe mode: force conservative compatibility/safety-oriented runtime behavior.
65+
SafeMode bool
6466
// CKPool compatibility mode: advertise a minimal CKPool-style subscribe
6567
// result (mining.notify tuple only) while keeping other compatibility paths.
6668
CKPoolEmulate bool
@@ -205,6 +207,7 @@ type EffectiveConfig struct {
205207
StratumTLSListen string `json:"stratum_tls_listen,omitempty"`
206208
StratumFastDecodeEnabled bool `json:"stratum_fast_decode_enabled"`
207209
StratumFastEncodeEnabled bool `json:"stratum_fast_encode_enabled"`
210+
SafeMode bool `json:"safe_mode,omitempty"`
208211
CKPoolEmulate bool `json:"ckpool_emulate"`
209212
StratumTCPReadBufferBytes int `json:"stratum_tcp_read_buffer_bytes,omitempty"`
210213
StratumTCPWriteBufferBytes int `json:"stratum_tcp_write_buffer_bytes,omitempty"`

data/config/examples/config.toml.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# - [stratum].stratum_password_enabled: Require miners to send a password on authorize (requires restart).
1010
# - [stratum].stratum_password: Password string checked against mining.authorize params (requires restart).
1111
# - [stratum].stratum_password_public: Show the stratum password on the public connect panel (requires restart).
12+
# - [stratum].safe_mode: Force conservative compatibility/safety behavior (restart to apply).
13+
# - Runtime override: --safe-mode=true/false
1214
#
1315
# Logging
1416
# - [logging].level: debug, info, warn, error (requires restart).
@@ -52,6 +54,7 @@
5254
status_tls_listen = ":443"
5355

5456
[stratum]
57+
safe_mode = false
5558
stratum_password = ""
5659
stratum_password_enabled = false
5760
stratum_password_public = false

defaults.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func defaultConfig() Config {
1818
StratumPasswordEnabled: false,
1919
StratumPassword: "",
2020
StratumPasswordPublic: false,
21+
SafeMode: false,
2122
CKPoolEmulate: true,
2223
StratumFastDecodeEnabled: false,
2324
StratumFastEncodeEnabled: false,

main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ func main() {
4444
statusAddrFlag := flag.String("status", "", "override status HTTP listen address (e.g. :80)")
4545
statusTLSAddrFlag := flag.String("status-tls", "", "override status HTTPS listen address (e.g. :443)")
4646
stratumTLSFlag := flag.String("stratum-tls", "", "override stratum TLS listen address (e.g. :24333)")
47+
var safeModeFlag *bool
48+
flag.Func("safe-mode", "force conservative compatibility/safety profile (true/false)", func(v string) error {
49+
b, err := strconv.ParseBool(strings.TrimSpace(v))
50+
if err != nil {
51+
return err
52+
}
53+
safeModeFlag = &b
54+
return nil
55+
})
4756
var ckpoolEmulateFlag *bool
4857
flag.Func("ckpool-emulate", "override Stratum subscribe response shape compatibility (true/false)", func(v string) error {
4958
b, err := strconv.ParseBool(strings.TrimSpace(v))
@@ -125,6 +134,7 @@ func main() {
125134
statusAddr: *statusAddrFlag,
126135
statusTLSAddr: *statusTLSAddrFlag,
127136
stratumTLSListen: *stratumTLSFlag,
137+
safeMode: safeModeFlag,
128138
ckpoolEmulate: ckpoolEmulateFlag,
129139
stratumFastDecode: fastDecodeFlag,
130140
stratumFastEncode: fastEncodeFlag,
@@ -311,6 +321,7 @@ func main() {
311321
"component", "startup",
312322
"kind", "config",
313323
"listen_addr", cfg.ListenAddr,
324+
"safe_mode", cfg.SafeMode,
314325
"stratum_tls_listen", cfg.StratumTLSListen,
315326
"status_addr", cfg.StatusAddr,
316327
"status_tls_addr", cfg.StatusTLSAddr,

runtime_overrides.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type runtimeOverrides struct {
1212
statusAddr string
1313
statusTLSAddr string
1414
stratumTLSListen string
15+
safeMode *bool
1516
ckpoolEmulate *bool
1617
stratumFastDecode *bool
1718
stratumFastEncode *bool
@@ -78,7 +79,6 @@ func applyRuntimeOverrides(cfg *Config, overrides runtimeOverrides) error {
7879
if overrides.allowPublicRPC {
7980
cfg.AllowPublicRPC = true
8081
}
81-
8282
if overrides.bind != "" {
8383
_, port, err := net.SplitHostPort(cfg.ListenAddr)
8484
if err != nil {
@@ -131,6 +131,9 @@ func applyRuntimeOverrides(cfg *Config, overrides runtimeOverrides) error {
131131
if overrides.ckpoolEmulate != nil {
132132
cfg.CKPoolEmulate = *overrides.ckpoolEmulate
133133
}
134+
if overrides.safeMode != nil {
135+
cfg.SafeMode = *overrides.safeMode
136+
}
134137
if overrides.stratumFastDecode != nil {
135138
cfg.StratumFastDecodeEnabled = *overrides.stratumFastDecode
136139
}
@@ -154,6 +157,39 @@ func applyRuntimeOverrides(cfg *Config, overrides runtimeOverrides) error {
154157
if cfg.ZMQHashBlockAddr == "" && cfg.ZMQRawBlockAddr == "" {
155158
logger.Warn("zmq is not configured; using RPC/longpoll-only mode", "hint", "set node.zmq_hashblock_addr/node.zmq_rawblock_addr in config.toml to enable ZMQ (legacy node.zmq_block_addr is read-only for migration)")
156159
}
160+
if cfg.SafeMode {
161+
applySafeModeProfile(cfg)
162+
}
157163

158164
return nil
159165
}
166+
167+
func applySafeModeProfile(cfg *Config) {
168+
if cfg == nil {
169+
return
170+
}
171+
cfg.SafeMode = true
172+
173+
// Conservative compatibility/safety defaults for troubleshooting and broad miner support.
174+
cfg.CKPoolEmulate = true
175+
cfg.StratumFastDecodeEnabled = false
176+
cfg.StratumFastEncodeEnabled = false
177+
cfg.StratumTCPReadBufferBytes = 0
178+
cfg.StratumTCPWriteBufferBytes = 0
179+
180+
cfg.LogDebug = false
181+
cfg.LogNetDebug = false
182+
183+
cfg.ShareRequireAuthorizedConnection = true
184+
cfg.ShareCheckParamFormat = true
185+
cfg.ShareCheckDuplicate = true
186+
cfg.ShareRequireJobID = true
187+
cfg.SubmitProcessInline = false
188+
189+
// Prefer widest miner compatibility over stricter policy checks.
190+
cfg.ShareCheckNTimeWindow = false
191+
cfg.ShareCheckVersionRolling = false
192+
cfg.ShareRequireWorkerMatch = false
193+
194+
cfg.DisableConnectRateLimits = true
195+
}

0 commit comments

Comments
 (0)