Skip to content

Commit 5c8d607

Browse files
authored
Sign competition GC logging requests 🔐 (#66)
1 parent b7f2a17 commit 5c8d607

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

neurons/_validator/competitions/competition_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import json
88
import os
99
import enum
10+
import cli_parser
1011
from utils.gc_logging import gc_log_competition_metrics
1112

1213

@@ -69,6 +70,7 @@ def __init__(self, config_dir: str):
6970
self.config_file = os.path.join(config_dir, "competition_config.json")
7071
self.current_competition: Optional[CompetitionConfig] = None
7172
self.state = CompetitionState()
73+
self.wallet = bt.wallet(config=cli_parser.config)
7274

7375
self._load_state()
7476
self._load_config()
@@ -188,7 +190,7 @@ def log_metrics(self, metrics: dict):
188190
**metrics,
189191
}
190192

191-
gc_log_competition_metrics(comp_metrics)
193+
gc_log_competition_metrics(comp_metrics, self.wallet.hotkey)
192194
except Exception as e:
193195
bt.logging.error(f"Error logging metrics: {e}")
194196

neurons/utils/gc_logging.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,27 @@ def log_responses(
6969
return None
7070

7171

72-
def gc_log_competition_metrics(metrics: dict) -> Optional[requests.Response]:
72+
def gc_log_competition_metrics(
73+
metrics: dict, hotkey: bt.Keypair
74+
) -> Optional[requests.Response]:
7375
"""
7476
Log competition metrics to the centralized logging server.
7577
"""
7678
try:
79+
metrics["validator_key"] = hotkey.ss58_address
7780
input_bytes = json.dumps(metrics).encode("utf-8")
81+
# sign the inputs with your hotkey
82+
signature = hotkey.sign(input_bytes)
83+
# encode the inputs and signature as base64
84+
signature_str = base64.b64encode(signature).decode("utf-8")
85+
7886
return session.post(
7987
COMPETITION_LOGGING_URL,
8088
data=input_bytes,
81-
headers={"Content-Type": "application/json"},
89+
headers={
90+
"Content-Type": "application/json",
91+
"X-Request-Signature": signature_str,
92+
},
8293
timeout=5,
8394
)
8495
except requests.exceptions.RequestException as e:

0 commit comments

Comments
 (0)