forked from spesmilo/electrumx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
electrumz_compact_history
51 lines (38 loc) · 1.25 KB
/
electrumz_compact_history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import asyncio
import logging
import sys
import traceback
from os import environ
from electrumz import Env
from electrumz.server.db import DB
async def compact_history():
if sys.version_info < (3, 8):
raise RuntimeError('Python >= 3.8 is required to run ElectrumZ')
environ['DAEMON_URL'] = '' # Avoid Env erroring out
env = Env()
db = DB(env)
await db.open_for_compacting()
assert not db.first_sync
history = db.history
# Continue where we left off, if interrupted
if history.comp_cursor == -1:
history.comp_cursor = 0
history.comp_flush_count = max(history.comp_flush_count, 1)
limit = 8 * 1000 * 1000
while history.comp_cursor != -1:
history._compact_history(limit)
# When completed also update the UTXO flush count
db.set_flush_count(history.flush_count)
def main():
logging.basicConfig(level=logging.INFO)
logging.info('Starting history compaction...')
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(compact_history())
except Exception:
traceback.print_exc()
logging.critical('History compaction terminated abnormally')
else:
logging.info('History compaction complete')
if __name__ == '__main__':
main()