11from modules .module import MtcModule
22from mypylib import color_print , print_table
3- from mytoncore import b642hex , signed_int_to_hex64
3+ from mytoncore import b642hex , signed_int_to_hex64 , shard_prefix_len , hex_shard_to_int , shard_prefix , shard_is_ancestor
44from mytonctrl .utils import pop_arg_from_args
55
66
@@ -15,6 +15,32 @@ def add_collator_to_vc(self, adnl_addr: str, shard: str):
1515 result = self .ton .validatorConsole .Run (f"add-collator { adnl_addr } { shard } " )
1616 return result
1717
18+ @staticmethod
19+ def _check_input_shards (node_shards : list , shards_need_to_add : list , monitor_min_split : int ):
20+ true_monitoring_shards = []
21+ for sh in node_shards :
22+ shard_id = hex_shard_to_int (sh )
23+ if shard_id ['workchain' ] == - 1 :
24+ continue
25+ shard = shard_id ['shard' ]
26+ if shard_prefix_len (shard ) > monitor_min_split :
27+ shard_id ['shard' ] = shard_prefix (shard , monitor_min_split )
28+ true_monitoring_shards .append (shard_id )
29+ for sh in shards_need_to_add :
30+ shard_id = hex_shard_to_int (sh )
31+ found = False
32+ for true_shard in true_monitoring_shards :
33+ if shard_id ['workchain' ] == true_shard ['workchain' ] and \
34+ shard_is_ancestor (true_shard ['shard' ], shard_id ['shard' ]):
35+ found = True
36+ break
37+ if not found :
38+ raise Exception (
39+ f'This node already has shards to monitor, '
40+ f'but shard { shard_id } is not monitored by the node: { true_monitoring_shards } It\' s highly not recommended to add new shards for node to monitor. '
41+ f'If you are sure you want to add new collator use option `--force`.'
42+ )
43+
1844 def setup_collator (self , args : list ):
1945 from mytoninstaller .mytoninstaller import set_node_argument
2046 from mytoninstaller .node_args import get_node_args
@@ -29,10 +55,12 @@ def setup_collator(self, args: list):
2955 node_args = get_node_args ()
3056 if '--add-shard' not in node_args :
3157 node_args ['--add-shard' ] = []
32- shards_need_to_add = [shard for shard in shards if shard not in node_args ['--add-shard' ]]
33- if '-M' in node_args and shards_need_to_add and not force :
34- raise Exception (f'This node already has shards to monitor. It\' s highly not recommended to add new shards for node to monitor. If you are sure you want to add new collator use option `--force`.' )
3558
59+ node_shards = node_args ['--add-shard' ]
60+ shards_need_to_add = [shard for shard in shards if shard not in node_shards ]
61+ if not force and shards_need_to_add and '-M' in node_args :
62+ monitor_min_split = self .ton .get_basechain_config ()['monitor_min_split' ]
63+ self ._check_input_shards (node_shards , shards_need_to_add , monitor_min_split )
3664 if adnl_addr is None :
3765 adnl_addr = self .ton .CreateNewKey ()
3866 self .ton .AddAdnlAddrToValidator (adnl_addr )
0 commit comments