9
9
import os
10
10
import os .path
11
11
from pathlib import Path
12
- import shutil
13
12
import snappy
14
13
import struct
15
14
import time
@@ -130,7 +129,7 @@ def get(self, number: int) -> bytes:
130
129
131
130
# What happens if we're trying to read the last item? Won't this fail?
132
131
# Is there always one extra entry in the index file?
133
- self .index_file .seek ((number + 1 ) * 6 )
132
+ self .index_file .seek ((number + 1 ) * 6 )
134
133
entry_bytes = self .index_file .read (6 )
135
134
end_entry = GethFreezerIndexEntry .from_bytes (entry_bytes )
136
135
@@ -165,7 +164,6 @@ def first_index(self):
165
164
return GethFreezerIndexEntry .from_bytes (first_index_bytes )
166
165
167
166
168
-
169
167
class BlockBody (rlp .Serializable ):
170
168
"This is how geth stores block bodies"
171
169
fields = [
@@ -276,7 +274,9 @@ def open_gethdb(location):
276
274
277
275
last_block = gethdb .last_block_hash
278
276
last_block_num = gethdb .block_num_for_hash (last_block )
279
- logger .info (f'found geth chain tip: header_hash={ humanize_hash (last_block )} block_number={ last_block_num } ' )
277
+
278
+ context = f'header_hash={ humanize_hash (last_block )} block_number={ last_block_num } '
279
+ logger .info (f'found geth chain tip: { context } ' )
280
280
281
281
genesis_hash = gethdb .header_hash_for_block_number (0 )
282
282
genesis_header = gethdb .block_header (0 , genesis_hash )
@@ -352,8 +352,8 @@ def sweep_state(gethdb: GethDatabase, trinitydb: LevelDB):
352
352
logger .debug ('sweep_state: bulk-importing state entries' )
353
353
354
354
iterator = gethdb .db .iterator (
355
- start = b'\x00 ' * 32 ,
356
- stop = b'\xff ' * 32 ,
355
+ start = b'\x00 ' * 32 ,
356
+ stop = b'\xff ' * 32 ,
357
357
include_start = True ,
358
358
include_stop = True ,
359
359
)
@@ -385,14 +385,16 @@ def import_state(gethdb: GethDatabase, chain):
385
385
f'state_root={ humanize_hash (state_root )} '
386
386
)
387
387
388
+ leveldb = headerdb .db
388
389
imported_leaf_count = 0
389
390
importdb = ImportDatabase (gethdb = gethdb .db , trinitydb = leveldb .db )
390
391
for path , leaf_data in iterate_leaves (importdb , state_root ):
391
392
account = rlp .decode (leaf_data , sedes = Account )
392
393
addr_hash = nibbles_to_bytes (path )
393
394
394
395
if account .code_hash != EMPTY_SHA3 :
395
- bytecode = importdb .get (account .code_hash )
396
+ # by fetching it, we're copying it into the trinity database
397
+ importdb .get (account .code_hash )
396
398
397
399
if account .storage_root == BLANK_ROOT_HASH :
398
400
imported_leaf_count += 1
@@ -401,14 +403,14 @@ def import_state(gethdb: GethDatabase, chain):
401
403
logger .debug (f'progress sha(addr)={ addr_hash .hex ()} ' )
402
404
continue
403
405
404
- for path , leaf_data in iterate_leaves (importdb , account .storage_root ):
406
+ for path , _leaf_data in iterate_leaves (importdb , account .storage_root ):
405
407
item_addr = nibbles_to_bytes (path )
406
408
imported_leaf_count += 1
407
409
408
410
if imported_leaf_count % 1000 == 0 :
409
411
logger .debug (f'progress sha(addr)={ addr_hash .hex ()} sha(item)={ item_addr .hex ()} ' )
410
412
411
- loger .info ('successfully imported state trie and all storage tries' )
413
+ logger .info ('successfully imported state trie and all storage tries' )
412
414
413
415
414
416
def import_block_body (gethdb , chain , block_number : int ):
@@ -461,7 +463,7 @@ def process_blocks(gethdb, chain, end_block):
461
463
transaction_class .from_base_transaction (txn ) for txn in body .transactions
462
464
]
463
465
block = block_class (header , transactions , body .uncles )
464
- imported_block , _ , _ = chain .import_block (block , perform_validation = True )
466
+ imported_block , _ , _ = chain .import_block (block , perform_validation = True )
465
467
logger .debug (f'imported block: { imported_block } ' )
466
468
467
469
@@ -478,7 +480,12 @@ def read_receipts(gethdb, block_number):
478
480
if len (raw_gas_used ) < 8 :
479
481
padded = (b'\x00 ' * (8 - len (raw_gas_used ))) + raw_gas_used
480
482
gas_used = struct .unpack ('>Q' , padded )[0 ]
481
- logger .info (f'- post_state_or_status={ post_state } gas_used={ gas_used } len(logs)={ len (logs )} ' )
483
+ context = ' ' .join ([
484
+ f'post_state_or_status={ post_state } ' ,
485
+ f'gas_used={ gas_used } ' ,
486
+ f'len(logs)={ len (logs )} '
487
+ ])
488
+ logger .info (f'- { context } ' )
482
489
483
490
484
491
def read_geth (gethdb ):
0 commit comments