@@ -507,6 +507,12 @@ def read_trinity(location):
507
507
logger .info (f'canonical_head={ canonical_head } ' )
508
508
509
509
510
+ def compact (chain ):
511
+ logger .info ('this might take a while' )
512
+ leveldb = chain .headerdb .db .db # what law of demeter?
513
+ leveldb .compact_range ()
514
+
515
+
510
516
if __name__ == "__main__" :
511
517
logging .basicConfig (
512
518
level = logging .DEBUG ,
@@ -594,6 +600,16 @@ def read_trinity(location):
594
600
)
595
601
read_geth_parser .add_argument ('-gethdb' , type = str , required = True )
596
602
603
+ compact_parser = subparsers .add_parser (
604
+ "compact" ,
605
+ help = "Runs a compaction over the database, do this after importing state!" ,
606
+ description = """
607
+ If the database is not compacted it will compact itself at an
608
+ unconvenient time, freezing your process for uncomfortably long.
609
+ """
610
+ )
611
+ compact_parser .add_argument ('-destdb' , type = str , required = True )
612
+
597
613
args = parser .parse_args ()
598
614
599
615
if args .command == 'import_body_range' :
@@ -620,5 +636,8 @@ def read_trinity(location):
620
636
gethdb = open_gethdb (args .gethdb )
621
637
chain = open_trinitydb (args .destdb )
622
638
sweep_state (gethdb , chain .headerdb .db )
639
+ elif args .command == 'compact' :
640
+ chain = open_trinitydb (args .destdb )
641
+ compact (chain )
623
642
else :
624
643
logger .error (f'unrecognized command. command={ args .command } ' )
0 commit comments