1+ import datetime
12import os
23import os .path
34import time
2122 Dict , int2ip
2223)
2324from mytoninstaller .utils import StartValidator , StartMytoncore , start_service , stop_service , get_ed25519_pubkey , \
24- disable_service
25+ disable_service , is_testnet , get_block_from_toncenter
2526from mytoninstaller .config import SetConfig , GetConfig , get_own_ip , backup_config
2627from mytoncore .utils import hex2b64
2728
@@ -70,7 +71,15 @@ def FirstNodeSettings(local):
7071
7172 # Прописать автозагрузку
7273 cpus = psutil .cpu_count () - 1
74+
75+ ttl_cmd = ''
76+ if archive_ttl == - 1 and local .buffer .mode == 'liteserver' :
77+ archive_ttl = 10 ** 9
78+ ttl_cmd = f' --state-ttl { 10 ** 9 } --permanent-celldb'
79+
80+
7381 cmd = f"{ validatorAppPath } --threads { cpus } --daemonize --global-config { globalConfigPath } --db { ton_db_dir } --logname { tonLogPath } --archive-ttl { archive_ttl } --verbosity 1"
82+ cmd += ttl_cmd
7483
7584 if os .getenv ('ADD_SHARD' ):
7685 add_shard = os .getenv ('ADD_SHARD' )
@@ -103,14 +112,6 @@ def FirstNodeSettings(local):
103112 StartValidator (local )
104113#end define
105114
106- def is_testnet (local ):
107- testnet_zero_state_root_hash = "gj+B8wb/AmlPk1z1AhVI484rhrUpgSr2oSFIh56VoSg="
108- with open (local .buffer .global_config_path ) as f :
109- config = json .load (f )
110- if config ['validator' ]['zero_state' ]['root_hash' ] == testnet_zero_state_root_hash :
111- return True
112- return False
113-
114115def download_blocks (local , bag : dict ):
115116 local .add_log (f"Downloading blocks from { bag ['from' ]} to { bag ['to' ]} " , "info" )
116117 if not download_bag (local , bag ['bag' ]):
@@ -143,28 +144,36 @@ def download_bag(local, bag_id: str):
143144
144145def update_init_block (local , seqno : int ):
145146 local .add_log (f"Editing init block in { local .buffer .global_config_path } " , "info" )
146- url = f'https://toncenter.com/api/v2/lookupBlock?workchain=-1&shard=-9223372036854775808&seqno={ seqno } '
147- if is_testnet (local ):
148- url = url .replace ('toncenter.com' , 'testnet.toncenter.com' )
149- resp = requests .get (url ).json ()
150- if not resp ['ok' ]:
151- local .add_log ("Error getting init block from toncenter" , "error" )
152- return False
147+ data = get_block_from_toncenter (local , workchain = - 1 , seqno = seqno )
153148 with open (local .buffer .global_config_path , 'r' ) as f :
154149 config = json .load (f )
155150 config ['validator' ]['init_block' ]['seqno' ] = seqno
156- config ['validator' ]['init_block' ]['file_hash' ] = resp [ 'result' ] ['file_hash' ]
157- config ['validator' ]['init_block' ]['root_hash' ] = resp [ 'result' ] ['root_hash' ]
151+ config ['validator' ]['init_block' ]['file_hash' ] = data ['file_hash' ]
152+ config ['validator' ]['init_block' ]['root_hash' ] = data ['root_hash' ]
158153 with open (local .buffer .global_config_path , 'w' ) as f :
159154 f .write (json .dumps (config , indent = 4 ))
160155 return True
161156
162157
158+ def parse_block_value (local , block : str ):
159+ if block is None :
160+ return None
161+ if block .isdigit ():
162+ return int (block )
163+ dt = datetime .datetime .strptime (block , "%Y-%m-%d" )
164+ ts = int (dt .timestamp ())
165+ data = get_block_from_toncenter (local , workchain = - 1 , utime = ts )
166+ return int (data ['seqno' ])
167+
168+
163169def download_archive_from_ts (local ):
164- archive_block = os .getenv ('ARCHIVE_BLOCKS' )
165- if archive_block is None :
170+ archive_blocks = os .getenv ('ARCHIVE_BLOCKS' )
171+ if archive_blocks is None :
166172 return
167- archive_block = int (archive_block )
173+ block_from , block_to = archive_blocks , None
174+ if len (archive_blocks .split ()) > 1 :
175+ block_from , block_to = archive_blocks .split ()
176+ block_from , block_to = parse_block_value (local , block_from ), parse_block_value (local , block_to )
168177
169178 enable_ton_storage (local )
170179 url = 'https://archival-dump.ton.org/index/mainnet.json'
@@ -175,13 +184,17 @@ def download_archive_from_ts(local):
175184 block_bags = []
176185
177186 blocks_config = requests .get (url ).json ()
178- for block in blocks_config ['blocks' ]:
179- if block ['to' ] >= archive_block :
180- block_bags .append (block )
181187 for state in blocks_config ['states' ]:
182- if state ['at_block' ] > archive_block :
188+ if state ['at_block' ] > block_from :
183189 break
184190 state_bag = state
191+ block_from = state_bag ['at_block' ]
192+ for block in blocks_config ['blocks' ]:
193+ if block ['to' ] >= block_from :
194+ block_bags .append (block )
195+ if block_to is not None and block ['from' ] > block_to :
196+ break
197+
185198 if not state_bag or not block_bags :
186199 local .add_log ("Skip downloading archive blocks: No bags found for the specified block" , "error" )
187200 return
@@ -226,6 +239,8 @@ def download_archive_from_ts(local):
226239 from mytoninstaller .mytoninstaller import set_node_argument
227240
228241 set_node_argument (local , ['--skip-key-sync' ])
242+ if block_to is not None :
243+ set_node_argument (local , ['--sync-shards-upto' , str (block_to )])
229244
230245
231246def DownloadDump (local ):
0 commit comments