Skip to content

Commit 3ede7d8

Browse files
committed
improve collator ux
1 parent 2fa592c commit 3ede7d8

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

modules/collator.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from modules.module import MtcModule
22
from mypylib import color_print, print_table
3-
from mytoncore import b642hex
3+
from mytoncore import b642hex, signed_int_to_hex64
44
from mytonctrl.utils import pop_arg_from_args
55

66

@@ -44,7 +44,11 @@ def setup_collator(self, args: list):
4444
shards_need_to_add = [shard for shard in shards if shard not in node_args['--add-shard']]
4545
if shards_need_to_add:
4646
set_node_argument(self.local, ['--add-shard', ' '.join(node_args['--add-shard'] + shards_need_to_add)])
47-
self.local.add_log(f'Collator enabled for shards {shards}\n')
47+
commands_text = [f'`add_collator {s} {adnl_addr}`' for s in shards]
48+
self.local.add_log(f'Collator enabled for shards {shards}\n'
49+
f'To add this collator to validator use command:\n'
50+
+ '\n'.join(commands_text))
51+
color_print("setup_collator - {green}OK{endc}")
4852

4953
def get_collators(self):
5054
return self.ton.GetValidatorConfig()['collators']
@@ -57,7 +61,7 @@ def print_collators(self, args: list = None):
5761
print("Collators list:")
5862
table = [['ADNL Address', 'Shard']]
5963
for c in collators:
60-
table.append([b642hex(c['adnl_id']).upper(), f"{c['shard']['workchain']}:{c['shard']['shard']}"])
64+
table.append([b642hex(c['adnl_id']).upper(), f"{c['shard']['workchain']}:{signed_int_to_hex64(int(c['shard']['shard']))}"])
6165
print_table(table)
6266

6367

modules/validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def set_collators_list(self, collators_list: dict):
157157

158158
def add_collator(self, args: list):
159159
if len(args) < 2:
160-
color_print("{red}Bad args. Usage:{endc} add_shard_collators <shard> <adnl> [--self-collate <true/false>] [--select-mode <random/ordered/round_robin>]")
160+
color_print("{red}Bad args. Usage:{endc} add_collator <shard> <adnl> [--self-collate <true/false>] [--select-mode <random/ordered/round_robin>]")
161161
return
162162
shard = args[0]
163163
shard_id = hex_shard_to_int(shard)

mytoncore/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,8 @@ def hex_shard_to_int(shard_id_str: str) -> dict:
112112
return {"workchain": wc, "shard": shard}
113113
except (ValueError, IndexError):
114114
raise Exception(f'Invalid shard ID "{shard_id_str}"')
115+
116+
def signed_int_to_hex64(value):
117+
if value < 0:
118+
value = (1 << 64) + value
119+
return f"{value:016X}"

0 commit comments

Comments
 (0)