@@ -89,9 +89,8 @@ def FirstNodeSettings(local):
8989 args = [validatorAppPath , "--global-config" , globalConfigPath , "--db" , ton_db_dir , "--ip" , addr , "--logname" , tonLogPath ]
9090 subprocess .run (args )
9191
92- # Download dumps from TON Storage
92+ DownloadDump ( local )
9393 download_archive_from_ts (local )
94- # DownloadDump(local)
9594
9695 # chown 1
9796 local .add_log ("Chown ton-work dir" , "debug" )
@@ -130,14 +129,34 @@ def download_bag(local, bag_id: str):
130129 time .sleep (20 )
131130 resp = requests .get (local_ts_url + f'/api/v1/details?bag_id={ bag_id } ' ).json ()
132131 local .add_log (f"DOWNLOADED { bag_id } " , "debug" )
132+ requests .post (local_ts_url + '/api/v1/remove' , json = {'bag_id' : bag_id , 'with_files' : False })
133+ return True
134+
135+
136+ def update_init_block (local , seqno : int ):
137+ local .add_log (f"Editing init block in { local .buffer .global_config_path } " , "info" )
138+ url = f'https://toncenter.com/api/v2/lookupBlock?workchain=-1&shard=-9223372036854775808&seqno={ seqno } '
139+ if is_testnet (local ):
140+ url .replace ('toncenter.com' , 'testnet.toncenter.com' )
141+ resp = requests .get (url ).json ()
142+ if not resp ['ok' ]:
143+ local .add_log ("Error getting init block from toncenter" , "error" )
144+ return False
145+ with open (local .buffer .global_config_path , 'r' ) as f :
146+ config = json .load (f )
147+ config ['validator' ]['init_block' ]['seqno' ] = seqno
148+ config ['validator' ]['init_block' ]['file_hash' ] = resp ['result' ]['file_hash' ]
149+ config ['validator' ]['init_block' ]['root_hash' ] = resp ['result' ]['root_hash' ]
150+ with open (local .buffer .global_config_path , 'w' ) as f :
151+ f .write (json .dumps (config , indent = 4 ))
133152 return True
134153
135154
136155def download_archive_from_ts (local ):
137156 archive_block = os .getenv ('ARCHIVE_BLOCKS' )
138- dump = local .buffer .dump
139- if not archive_block and not dump :
157+ if archive_block is None :
140158 return
159+ archive_block = int (archive_block )
141160
142161 enable_ton_storage (local )
143162 url = 'https://archival-dump.ton.org/index/mainnet.json'
@@ -148,24 +167,24 @@ def download_archive_from_ts(local):
148167 block_bags = []
149168
150169 blocks_config = requests .get (url ).json ()
151- if dump :
152- state_bag = blocks_config ['states' ][- 1 ]
153- else :
154- for block in blocks_config ['blocks' ]:
155- if block ['to' ] >= archive_block :
156- block_bags .append (block )
157- for state in blocks_config ['states' ]:
158- state_bag = state
159- if state ['at_block' ] > archive_block :
160- break
161- if not state_bag or not block_bags :
162- local .add_log ("Skip downloading archive blocks: No bags found for the specified block" , "error" )
163- return
170+ for block in blocks_config ['blocks' ]:
171+ if block ['to' ] >= archive_block :
172+ block_bags .append (block )
173+ for state in blocks_config ['states' ]:
174+ if state ['at_block' ] > archive_block :
175+ break
176+ state_bag = state
177+ if not state_bag or not block_bags :
178+ local .add_log ("Skip downloading archive blocks: No bags found for the specified block" , "error" )
179+ return
164180
165181 local .add_log (f"Downloading blockchain state for block { state_bag ['at_block' ]} " , "info" )
166182 if not download_bag (local , state_bag ['bag' ]):
167183 local .add_log ("Error downloading state bag" , "error" )
168184 return
185+
186+ update_init_block (local , state_bag ['at_block' ])
187+
169188 local .add_log ("Downloading archive blocks" , "info" )
170189 for bag in block_bags :
171190 local .add_log (f"Downloading blocks from { bag ['from' ]} to { bag ['to' ]} " , "info" )
@@ -174,24 +193,28 @@ def download_archive_from_ts(local):
174193 return
175194 local .add_log (f"Downloading blocks is completed" , "info" )
176195
177- states_dir = local .buffer .ton_db_dir + 'archive/states'
178- blocks_dir = local .buffer .ton_db_dir + 'archive/packages'
196+ archive_dir = local .buffer .ton_db_dir + 'archive/'
197+ import_dir = local .buffer .ton_db_dir + 'import/'
198+ states_dir = archive_dir + '/states'
179199 downloads_path = '/tmp/ts-downloads/'
180200
181201 os .makedirs (states_dir , exist_ok = True )
182- os .makedirs (blocks_dir , exist_ok = True )
183202
184- subprocess .run (f'mv { downloads_path } /{ state_bag ["bag" ]} /state-*/* { states_dir } ' , shell = True )
203+ local .add_log ("Copying data to node db" , "info" )
204+ subprocess .run (f'cp -a { downloads_path } /{ state_bag ["bag" ]} /state-*/* { states_dir } ' , shell = True )
185205 # subprocess.run(['rm', '-rf', f"{downloads_path}/{state_bag['bag']}"])
186-
187206 for bag in block_bags :
188- subprocess .run (f'mv { downloads_path } /{ bag ["bag" ]} /packages/* { blocks_dir } ' , shell = True )
207+ subprocess .run (f'cp -a { downloads_path } /{ bag ["bag" ]} /packages { import_dir } ' , shell = True )
189208 # subprocess.run(['rm', '-rf', f"{downloads_path}/{bag['bag']}"])
190209 subprocess .run (['rm' , '-rf' , downloads_path ])
191210
192211 stop_service (local , "ton_storage" ) # stop TS
193212 disable_service (local , "ton_storage" )
194213
214+ from mytoninstaller .mytoninstaller import set_node_argument
215+
216+ set_node_argument (local , ['--skip-key-sync' ])
217+
195218
196219def DownloadDump (local ):
197220 dump = local .buffer .dump
0 commit comments