Skip to content

Commit ba3a617

Browse files
authored
Merge pull request #33 from Firstset/fee-recipient-check
Fee recipient check in check-relay
2 parents d579dc1 + 78722ca commit ba3a617

4 files changed

Lines changed: 58 additions & 38 deletions

File tree

addresses/holesky.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"accounting_address": "0xc093e53e8F4b55A223c18A2Da6fA00e60DD5EFE1",
66
"VEBO_address": "0xffDDF7025410412deaa05E3E1cE68FE53208afcb"
77
},
8-
"relay_allowlist_address": "0x2d86C5855581194a386941806E38cA119E50aEA3"
8+
"relay_allowlist_address": "0x2d86C5855581194a386941806E38cA119E50aEA3",
9+
"fee_recipient": "0xE73a3602b99f1f913e72F8bdcBC235e206794Ac8"
910
}

addresses/mainnet.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"accounting_address": "0x4d72BFF1BeaC69925F8Bd12526a39BAAb069e5Da",
66
"VEBO_address": "0x0De4Ea0184c2ad0BacA7183356Aea5B8d5Bf5c6e"
77
},
8-
"relay_allowlist_address": "0xF95f069F9AD107938F6ba802a3da87892298610E"
8+
"relay_allowlist_address": "0xF95f069F9AD107938F6ba802a3da87892298610E",
9+
"fee_recipient": "0x388C818CA8B9251b393131C08a736A67ccB19297"
910
}

swarm/relay_check.py

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,23 @@ async def get_whitelisted_relays(config):
1717
relays = await contract.functions.get_relays().call()
1818
return relays
1919

20-
async def check_validator_registration(session, relay_url, pubkey):
21-
"""Check if a validator is registered with a specific relay"""
20+
async def check_validator_registration(session, relay_url, pubkey, config):
21+
"""Check if a validator is registered with a specific relay and verify fee recipient"""
2222
url = f"{relay_url}/relay/v1/data/validator_registration"
23+
2324
try:
2425
async with session.get(url, params={'pubkey': pubkey}, timeout=5) as response:
2526
if response.status == 200:
26-
return True
27-
return False
27+
data = await response.json()
28+
if 'message' in data and 'fee_recipient' in data['message']:
29+
fee_recipient = data['message']['fee_recipient']
30+
# Return tuple of (registration status, fee recipient)
31+
return (True, fee_recipient.lower() == config['fee_recipient'].lower(), fee_recipient)
32+
return (False, False, None)
33+
return (False, False, None)
2834
except Exception as e:
2935
print(f"Warning: Could not check registration status for {relay_url}: {str(e)}")
30-
return None # Return None to indicate unknown status
36+
return None
3137

3238
async def get_validator_keys_from_csm(config):
3339
csm = CSM(config)
@@ -77,25 +83,31 @@ async def check_relays(config, args):
7783
'optional_total': 0,
7884
'mandatory_relays': [],
7985
'optional_relays': [],
80-
'unknown': []
86+
'unknown': [],
87+
'fee_mismatches': [] # Add this field to track fee mismatches
8188
}
8289
for relay_url in relay_urls:
83-
tasks.append(check_validator_registration(session, relay_url, validator))
90+
tasks.append(check_validator_registration(session, relay_url, validator, config))
8491

8592
chunk_results = await asyncio.gather(*tasks)
8693

8794
for validator_idx, validator in enumerate(validator_chunk):
88-
for relay_idx, is_registered in enumerate(chunk_results[validator_idx * len(relay_urls):(validator_idx + 1) * len(relay_urls)]):
95+
for relay_idx, result in enumerate(chunk_results[validator_idx * len(relay_urls):(validator_idx + 1) * len(relay_urls)]):
8996
relay_url = relay_urls[relay_idx]
90-
if is_registered is True:
91-
if relay_url in mandatory_relays:
92-
results[validator]['mandatory_total'] += 1
93-
results[validator]['mandatory_relays'].append(relay_url)
94-
else:
95-
results[validator]['optional_total'] += 1
96-
results[validator]['optional_relays'].append(relay_url)
97-
elif is_registered is None:
97+
if result is None:
9898
results[validator]['unknown'].append(relay_url)
99+
else:
100+
is_registered, fee_matches, fee_recipient = result
101+
if is_registered:
102+
if not fee_matches:
103+
results[validator]['fee_mismatches'].append((relay_url, fee_recipient))
104+
105+
if relay_url in mandatory_relays:
106+
results[validator]['mandatory_total'] += 1
107+
results[validator]['mandatory_relays'].append(relay_url)
108+
else:
109+
results[validator]['optional_total'] += 1
110+
results[validator]['optional_relays'].append(relay_url)
99111

100112
if not args.pubkey: # Only show progress for bulk checks
101113
print(f"Processed {min(i + chunk_size, len(validator_keys))}/{len(validator_keys)} validators...")
@@ -113,12 +125,18 @@ def print_summary_report(results, mandatory_relays, optional_relays):
113125

114126
ok_count = 0
115127
not_ok_count = 0
128+
fee_mismatch_count = 0
116129

117130
for validator, data in results.items():
118-
is_ok = data['mandatory_total'] >= 2 # At least 2 mandatory relays required
131+
has_fee_mismatch = len(data.get('fee_mismatches', [])) > 0
132+
is_ok = data['mandatory_total'] >= 2 and not has_fee_mismatch # At least 2 mandatory relays required and no fee mismatches
133+
119134
status = "OK" if is_ok else "NOT OK"
135+
if has_fee_mismatch:
136+
status += " (⚠️ Fee mismatch)"
137+
fee_mismatch_count += 1
120138

121-
if is_ok:
139+
if is_ok and not has_fee_mismatch:
122140
ok_count += 1
123141
else:
124142
not_ok_count += 1
@@ -129,36 +147,33 @@ def print_summary_report(results, mandatory_relays, optional_relays):
129147
print(f"Validator {validator} : {status:6} (Mandatory: {mandatory_coverage}, Optional: {optional_coverage})")
130148

131149
print(f"\nSummary: {ok_count} validators OK, {not_ok_count} validators NOT OK")
150+
if fee_mismatch_count > 0:
151+
print(f"Warning: {fee_mismatch_count} validators have fee recipient mismatches")
152+
else:
153+
print("All validators have correct fee recipient set")
132154

133155
def print_detailed_report(results, relay_tuples, mandatory_relays, optional_relays):
134156
"""Print detailed report of validator relay registration status"""
135157
print("\nDetailed Relay Coverage Report:")
136158
print("-" * 50)
137159

138160
for validator, data in results.items():
139-
is_ok = data['mandatory_total'] >= 2
161+
has_fee_mismatch = len(data.get('fee_mismatches', [])) > 0
162+
is_ok = data['mandatory_total'] >= 2 and not has_fee_mismatch
163+
140164
status = "OK" if is_ok else "NOT OK"
165+
if has_fee_mismatch:
166+
status += " (⚠️ Fee mismatch)"
141167

142168
print(f"\nValidator {validator} : {status}")
143169
print(f"Registered with {data['mandatory_total']}/{len(mandatory_relays)} mandatory relays")
144170
print(f"Registered with {data['optional_total']}/{len(optional_relays)} optional relays")
145171

146-
if data['unknown']:
147-
print(f"Could not check status for {len(data['unknown'])} relay(s):")
148-
for relay in data['unknown']:
172+
if data.get('fee_mismatches'):
173+
print("\nFee recipient mismatches:")
174+
for relay, incorrect_fee in data['fee_mismatches']:
149175
relay_info = next(r for r in relay_tuples if r[0] == relay)
150-
print(f" ? {relay} ({relay_info[1]} - {relay_info[3]})")
151-
152-
missing_mandatory = set(mandatory_relays) - set(data['mandatory_relays'])
153-
if missing_mandatory:
154-
print("Missing mandatory registrations:")
155-
for relay in missing_mandatory:
156-
relay_info = next(r for r in relay_tuples if r[0] == relay)
157-
print(f" - {relay} ({relay_info[1]} - {relay_info[3]})")
176+
print(f" ! {relay} ({relay_info[1]} - {relay_info[3]}) - Incorrect fee recipient: {incorrect_fee}")
177+
else:
178+
print("Fee recipient is correctly set for all relays")
158179

159-
missing_optional = set(optional_relays) - set(data['optional_relays'])
160-
if missing_optional:
161-
print("Missing optional registrations:")
162-
for relay in missing_optional:
163-
relay_info = next(r for r in relay_tuples if r[0] == relay)
164-
print(f" - {relay} ({relay_info[1]} - {relay_info[3]})")

swarm/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,7 @@ def load_chain_addresses(config: dict) -> dict:
5858
# Add relay allowlist address
5959
config['relay_allowlist_address'] = addresses['relay_allowlist_address']
6060

61+
# Add fee recipient
62+
config['fee_recipient'] = addresses['fee_recipient']
63+
6164
return config

0 commit comments

Comments
 (0)