GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(validator): add an operator-only watermark reset command · CortexLM/cortex@6263a2a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • CHANGELOG.md
  • docs/external-miner
    • troubleshoot.md
    • validators.md
  • src/cortex
    • cli.py
    • validator
      • evidence.py
  • tests/validator
    • test_validator.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎CHANGELOG.md‎

Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
each paying `share * min(sum(leaves), 10^12) / 10^12`, remainder burned.
2424
Validators need no change beyond the release; they recompute signed leaves.
2525
- `GET /v1/metagraph/latest` serves the sealed hotkey map to challenges.
26+
- `cortex validator-watermark-reset`: operator-only, local repair that lowers a
27+
wrongly advanced `challenges_version`, `measurements_version` or `epoch`
28+
watermark (requires `--confirm`, never raises one) and audits it in
29+
`consensus_watermark_resets`.
2630

2731
### Changed
2832

Collapse file

‎docs/external-miner/troubleshoot.md‎

Copy file name to clipboardExpand all lines: docs/external-miner/troubleshoot.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ catalog; follow the documentation and checklist in the current signed topic.
105105
| Missing/invalid peer sample | Configure independently selected HTTPS peers with metagraph `validator_permit`; do not disable verification |
106106
| Conflicting signed roots or equivocation | Preserve the journal and signed evidence; reconcile the network state |
107107
| Stale block, future epoch, reorg or changed latest | Wait for a current valid seal; do not force-submit the old one |
108+
| `consensus rollback refused` | The gateway serves a lower `challenges_version`, `measurements_version` or epoch than this validator already accepted. Ask the master operator first; only if the higher value was advanced wrongly, lower it with `cortex validator-watermark-reset` (see [the validator guide](validators.md#repairing-a-consensus-watermark)). Do not delete the database |
108109
| Ambiguous chain dispatch remains pending | Reconcile inclusion/finalization before retrying; retain the SQLite journal |
109110
| CRv4 or drand failure | Do not fall back to public weights while chain commit-reveal is enabled |
110111
| `/v1/attest/*` returns `503` and `verified: false` | DCAP verification is not implemented in the Python validator |
Collapse file

‎docs/external-miner/validators.md‎

Copy file name to clipboardExpand all lines: docs/external-miner/validators.md
+25Lines changed: 25 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,31 @@ Only `not_broadcast` releases the epoch for a retry. Keep the underlying chain
234234
receipt or nonce query private; the journal stores its digest. Do not delete the
235235
database to force a retry.
236236

237+
### Repairing a consensus watermark
238+
239+
The journal keeps rollback watermarks for `challenges_version`,
240+
`measurements_version` and `epoch`; a lower served value fails with
241+
`consensus rollback refused`. If a watermark was advanced wrongly (for example a
242+
profile version published by mistake and then withdrawn), stop the validator and
243+
lower it locally. The command touches only the state database: no network, no
244+
wallet.
245+
246+
```bash
247+
cortex validator-watermark-reset \
248+
--state-db /var/lib/base/validator.sqlite3 \
249+
--name challenges_version --to 2 --confirm
250+
```
251+
252+
It refuses without `--confirm`, refuses a name outside those three, a negative
253+
value, a watermark that was never set and any value above the current one (it
254+
only lowers or repairs). It prints the old and new values and appends an audit
255+
row to `consensus_watermark_resets(name, old_value, new_value, at)` in the same
256+
transaction.
257+
258+
**Warning:** resetting below a version or epoch this validator really accepted
259+
re-opens rollback to that value. Confirm the correct value with the master
260+
operator first.
261+
237262
The peer listener exposes:
238263

239264
| Route | Response |
Collapse file

‎src/cortex/cli.py‎

Copy file name to clipboardExpand all lines: src/cortex/cli.py
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
from cortex.errors import ServiceError
1717
from cortex.http import read_private_file
1818
from cortex.miner import MinerClient, load_seed
19+
from cortex.protocol import ProtocolError
1920
from cortex.protocol.crypto import decode_hotkey
21+
from cortex.validator.evidence import RESETTABLE_WATERMARKS
2022
from cortex.wallet import HotkeySigner, load_wallet_hotkey
2123

2224

@@ -40,6 +42,14 @@ def parser() -> argparse.ArgumentParser:
4042
reconcile.add_argument("--attempt-id", required=True)
4143
reconcile.add_argument("--result", choices=("submitted", "not_broadcast"), required=True)
4244
reconcile.add_argument("--evidence-digest", required=True)
45+
reset = commands.add_parser(
46+
"validator-watermark-reset",
47+
help="lower one wrongly advanced consensus watermark (local state only)",
48+
)
49+
reset.add_argument("--state-db", type=Path, required=True)
50+
reset.add_argument("--name", choices=RESETTABLE_WATERMARKS, required=True)
51+
reset.add_argument("--to", type=int, required=True)
52+
reset.add_argument("--confirm", action="store_true")
4353
vm = commands.add_parser("vm-host", help="serve the dedicated Firecracker host")
4454
vm.add_argument("--config", type=Path, required=True)
4555
vm.add_argument(
@@ -230,6 +240,24 @@ def run_validator_reconcile(args: argparse.Namespace) -> None:
230240
print(json.dumps(result, indent=2, sort_keys=True))
231241

232242

243+
def run_validator_watermark_reset(args: argparse.Namespace) -> None:
244+
from cortex.validator import SubmissionJournal
245+
246+
# Refusal reasons are fixed strings with no credential, so show them to the operator.
247+
if not args.confirm:
248+
raise SystemExit("Cortex command failed: --confirm required; lowering re-opens rollback")
249+
if not args.state_db.is_file():
250+
raise SystemExit("Cortex command failed: validator state database not found")
251+
journal = SubmissionJournal(args.state_db)
252+
try:
253+
old = journal.evidence.reset_watermark(args.name, args.to)
254+
except ProtocolError as error:
255+
raise SystemExit(f"Cortex command failed: {error}") from None
256+
finally:
257+
journal.close()
258+
print(json.dumps({"name": args.name, "old_value": old, "new_value": args.to}, indent=2))
259+
260+
233261
def main(argv: list[str] | None = None) -> None:
234262
values = sys.argv[1:] if argv is None else argv
235263
if values and values[0] == "validator":
@@ -259,6 +287,8 @@ def main(argv: list[str] | None = None) -> None:
259287
serve(args.config)
260288
elif args.command == "validator-reconcile":
261289
run_validator_reconcile(args)
290+
elif args.command == "validator-watermark-reset":
291+
run_validator_watermark_reset(args)
262292
else:
263293
action = {"master": run_master, "miner": run_miner, "topic-create": run_topic_create}
264294
asyncio.run(action[args.command](args))
Collapse file

‎src/cortex/validator/evidence.py‎

Copy file name to clipboardExpand all lines: src/cortex/validator/evidence.py
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from cortex.protocol import Bundle, ProtocolError
1010
from cortex.protocol.consensus import Dissent, RootStatement
1111

12+
RESETTABLE_WATERMARKS = ("challenges_version", "measurements_version", "epoch")
13+
1214

1315
class EvidenceStore:
1416
def __init__(self, connection: sqlite3.Connection):
@@ -29,6 +31,10 @@ def __init__(self, connection: sqlite3.Connection):
2931
CREATE TABLE IF NOT EXISTS consensus_watermarks (
3032
name TEXT PRIMARY KEY, value TEXT NOT NULL
3133
);
34+
CREATE TABLE IF NOT EXISTS consensus_watermark_resets (
35+
name TEXT NOT NULL, old_value TEXT NOT NULL, new_value TEXT NOT NULL,
36+
at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
37+
);
3238
""")
3339

3440
def check_watermark(self, name: str, value: int) -> None:
@@ -46,6 +52,35 @@ def watermark(self, name: str, value: int) -> None:
4652
(name, str(value)),
4753
)
4854

55+
def reset_watermark(self, name: str, value: int) -> int:
56+
"""Operator repair: lower one rollback watermark and audit it; never raises one."""
57+
if name not in RESETTABLE_WATERMARKS:
58+
raise ProtocolError("unknown consensus watermark")
59+
if type(value) is not int or value < 0:
60+
raise ProtocolError("watermark must be a non-negative integer")
61+
self.connection.execute("BEGIN IMMEDIATE")
62+
try:
63+
row = self.connection.execute(
64+
"SELECT value FROM consensus_watermarks WHERE name=?", (name,)
65+
).fetchone()
66+
if row is None:
67+
raise ProtocolError("consensus watermark not set")
68+
old = int(row[0])
69+
if value > old:
70+
raise ProtocolError("watermark reset may only lower a value")
71+
self.connection.execute(
72+
"UPDATE consensus_watermarks SET value=? WHERE name=?", (str(value), name)
73+
)
74+
self.connection.execute(
75+
"INSERT INTO consensus_watermark_resets (name,old_value,new_value) VALUES (?,?,?)",
76+
(name, str(old), str(value)),
77+
)
78+
except BaseException:
79+
self.connection.execute("ROLLBACK")
80+
raise
81+
self.connection.execute("COMMIT")
82+
return old
83+
4984
def root(self, statement: RootStatement, *, local: bool = False) -> bool:
5085
statement.verify()
5186
epoch = f"{statement.epoch:020d}"
Collapse file

‎tests/validator/test_validator.py‎

Copy file name to clipboardExpand all lines: tests/validator/test_validator.py
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from dataclasses import replace
23
from hashlib import sha256
34
from types import SimpleNamespace
@@ -557,6 +558,53 @@ async def test_trust_version_rollback_is_refused_across_restart(network):
557558
assert len(network.chain.submissions) == 1
558559

559560

561+
def reset(db_path, *extra):
562+
from cortex.cli import main
563+
564+
main(["validator-watermark-reset", "--state-db", str(db_path), *extra])
565+
566+
567+
async def test_cli_watermark_reset_lowers_a_wrong_version_and_audits_it(network, capsys):
568+
import sqlite3
569+
570+
original = network.validator.trust
571+
network.validator.trust_loader = lambda _: replace(original, challenges_version=2)
572+
await network.validator.run_once()
573+
network.journal.close()
574+
args = ("--name", "challenges_version", "--to", "1")
575+
for refused in (
576+
args, # no --confirm
577+
("--name", "challenges_version", "--to", "3", "--confirm"), # raising
578+
("--name", "netuid", "--to", "1", "--confirm"),
579+
("--name", "challenges_version", "--to", "-1", "--confirm"),
580+
):
581+
with pytest.raises(SystemExit):
582+
reset(network.db_path, *refused)
583+
capsys.readouterr()
584+
reset(network.db_path, *args, "--confirm")
585+
assert json.loads(capsys.readouterr().out) == {
586+
"name": "challenges_version",
587+
"old_value": 2,
588+
"new_value": 1,
589+
}
590+
with sqlite3.connect(network.db_path) as connection:
591+
assert connection.execute(
592+
"SELECT name, old_value, new_value FROM consensus_watermark_resets"
593+
).fetchall() == [("challenges_version", "2", "1")]
594+
network.validator.journal = SubmissionJournal(network.db_path)
595+
network.validator.trust_loader = lambda _: original
596+
assert (await network.validator.run_once()).outcome == "already_submitted_or_pending"
597+
598+
599+
def test_cli_watermark_reset_refuses_an_unset_watermark_and_allows_equal(network, capsys):
600+
network.journal.evidence.watermark("epoch", 12)
601+
network.journal.close()
602+
with pytest.raises(SystemExit):
603+
reset(network.db_path, "--name", "measurements_version", "--to", "0", "--confirm")
604+
reset(network.db_path, "--name", "epoch", "--to", "12", "--confirm")
605+
assert json.loads(capsys.readouterr().out)["new_value"] == 12
606+
607+
560608
async def test_peer_api_serves_signed_evidence_and_never_claims_dcap_verified(network):
561609
from cortex.protocol.consensus import RootStatement
562610
from cortex.validator.evidence import peer_app

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.