()
| 138 | } |
| 139 | |
| 140 | function _persistState() { |
| 141 | // NOTE(windows): mode 0o700 / 0o600 are silently ignored on Windows. |
| 142 | // The stake-state file will NOT be access-restricted to the current user. |
| 143 | // Only user-profile directory ACLs provide isolation on Windows. |
| 144 | try { |
| 145 | const file = _stateFile(); |
| 146 | const dir = path.dirname(file); |
| 147 | if (!fs.existsSync(dir)) { |
| 148 | fs.mkdirSync(dir, { recursive: true, mode: 0o700 }); |
| 149 | } |
| 150 | const snapshot = { |
| 151 | nextAttemptAt: _state.nextAttemptAt, |
| 152 | transientFailures: _state.transientFailures, |
| 153 | fundsFailures: _state.fundsFailures, |
| 154 | lastSuccessAt: _state.lastSuccessAt, |
| 155 | // disabledUntilRestart intentionally omitted |
| 156 | savedAt: Date.now(), |
| 157 | }; |
| 158 | fs.writeFileSync(file, JSON.stringify(snapshot), { encoding: 'utf8', mode: 0o600 }); |
| 159 | } catch (_) { |
| 160 | // best-effort: ignore disk failures (e.g. read-only FS in sandbox) |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | function resetBackoff() { |
| 165 | _state.transientFailures = 0; |
no test coverage detected