feat(alpha): complete hardening backlog
Complete the alpha-hardening Ralph task set, including tracker billing/accounting guards, validator fraud-audit primitives, wallet binding proof support, documentation runbooks, and updated tests. Verification: .venv/bin/python -m compileall -q packages tests; .venv/bin/python -m pytest -q --tb=short (313 passed, 3 skipped, 1 failed: tests/test_mining_cli.py::test_legacy_start_without_port_uses_next_available_port because meshnet-node pid 1263451 is already listening on port 7000).
This commit is contained in:
@@ -1592,14 +1592,14 @@ def test_stats_gossip_endpoint_merges_peer_slice():
|
||||
|
||||
# ---------------------------------------------------------------- US-027 / US-028 routing
|
||||
|
||||
def _make_node(node_id, shard_start, shard_end, bench=1.0, queue_depth=0):
|
||||
def _make_node(node_id, shard_start, shard_end, bench=1.0, queue_depth=0, wallet_address=None):
|
||||
"""Helper: build a _NodeEntry with minimal fields."""
|
||||
from meshnet_tracker.server import _NodeEntry
|
||||
n = _NodeEntry(
|
||||
node_id=node_id, endpoint=f"http://fake:{9000 + shard_start}",
|
||||
shard_start=shard_start, shard_end=shard_end,
|
||||
model="m", shard_checksum=None, hardware_profile={},
|
||||
wallet_address=None, score=1.0,
|
||||
wallet_address=wallet_address, score=1.0,
|
||||
benchmark_tokens_per_sec=bench,
|
||||
)
|
||||
n.queue_depth = queue_depth
|
||||
@@ -1683,6 +1683,49 @@ def test_select_route_throughput_accounts_for_queue_depth():
|
||||
assert route[0].node_id in ("busy", "idle")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- AH-009 reputation-weighted routing
|
||||
|
||||
|
||||
def test_select_route_prefers_higher_reputation_when_throughput_equal():
|
||||
"""AH-009 test-first item 3: among candidates that advance coverage
|
||||
equally with the same effective throughput, the higher-reputation
|
||||
wallet's node wins the tiebreak (ADR-0018 §6 -- earnings scale with
|
||||
tenure/standing)."""
|
||||
from meshnet_contracts import LocalSolanaContracts
|
||||
from meshnet_tracker.server import _select_route
|
||||
|
||||
contracts = LocalSolanaContracts()
|
||||
contracts.registry.record_audit_outcome("wallet-veteran", passed=False) # 1.0 -> 0.7
|
||||
# wallet-fresh keeps the default reputation of 1.0
|
||||
|
||||
veteran = _make_node("veteran", 0, 11, bench=10.0, wallet_address="wallet-veteran")
|
||||
fresh = _make_node("fresh", 0, 11, bench=10.0, wallet_address="wallet-fresh")
|
||||
|
||||
route, err = _select_route([veteran, fresh], 0, 11, contracts=contracts)
|
||||
assert err == ""
|
||||
assert route[0].node_id == "fresh"
|
||||
|
||||
|
||||
def test_select_route_reputation_never_overrides_coverage():
|
||||
"""A lower-reputation node that covers more layers still wins -- the
|
||||
reputation multiplier is a tiebreak among equal-coverage candidates,
|
||||
never a substitute for coverage maximization."""
|
||||
from meshnet_contracts import LocalSolanaContracts
|
||||
from meshnet_tracker.server import _select_route
|
||||
|
||||
contracts = LocalSolanaContracts()
|
||||
contracts.registry.record_audit_outcome("wallet-shady", passed=False)
|
||||
for _ in range(9):
|
||||
contracts.registry.record_audit_outcome("wallet-shady", passed=False) # reputation -> 0.0
|
||||
|
||||
wide_shady = _make_node("wide-shady", 0, 11, bench=1.0, wallet_address="wallet-shady")
|
||||
narrow_good = _make_node("narrow-good", 0, 5, bench=1.0, wallet_address="wallet-good")
|
||||
|
||||
route, err = _select_route([wide_shady, narrow_good], 0, 11, contracts=contracts)
|
||||
assert err == ""
|
||||
assert [n.node_id for n in route] == ["wide-shady"]
|
||||
|
||||
|
||||
def test_two_stub_nodes_complete_pipeline_via_tracker():
|
||||
"""Integration: two StubNodeServer instances serving complementary shards
|
||||
produce a full inference response through the tracker route."""
|
||||
|
||||
Reference in New Issue
Block a user