Skip to content

Commit fadd3cc

Browse files
committed
history db: change schema, and rm compaction
1 parent 10f0faa commit fadd3cc

6 files changed

Lines changed: 153 additions & 469 deletions

File tree

electrumx/server/db.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def __init__(self, env: 'Env'):
107107
# "undo data: list of UTXOs spent at block height"
108108
self.utxo_db = None
109109

110-
self.utxo_flush_count = 0
111110
self.fs_height = -1
112111
self.fs_tx_count = 0
113112
self.db_height = -1
@@ -169,9 +168,11 @@ async def _open_dbs(self, for_sync: bool, compacting: bool):
169168
self.read_utxo_state()
170169

171170
# Then history DB
172-
self.utxo_flush_count = self.history.open_db(self.db_class, for_sync,
173-
self.utxo_flush_count,
174-
compacting)
171+
self.history.open_db(
172+
db_class=self.db_class,
173+
for_sync=for_sync,
174+
utxo_db_tx_count=self.db_tx_count,
175+
)
175176
self.clear_excess_undo_info()
176177

177178
# Read TX counts (requires meta directory)
@@ -254,7 +255,7 @@ def flush_dbs(self, flush_data, flush_utxos, estimate_txs_remaining):
254255
self.flush_state(self.utxo_db)
255256

256257
elapsed = self.last_flush - start_time
257-
self.logger.info(f'flush #{self.history.flush_count:,d} took '
258+
self.logger.info(f'flush took '
258259
f'{elapsed:.1f}s. Height {flush_data.height:,d} '
259260
f'txs: {flush_data.tx_count:,d} ({tx_delta:+,d})')
260261

@@ -353,7 +354,6 @@ def flush_utxo_db(self, batch, flush_data: FlushData):
353354
f'{spend_count:,d} spends in '
354355
f'{elapsed:.1f}s, committing...')
355356

356-
self.utxo_flush_count = self.history.flush_count
357357
self.db_height = flush_data.height
358358
self.db_tx_count = flush_data.tx_count
359359
self.db_tip = flush_data.tip
@@ -384,7 +384,7 @@ def flush_backup(self, flush_data, touched):
384384
self.flush_state(batch)
385385

386386
elapsed = self.last_flush - start_time
387-
self.logger.info(f'backup flush #{self.history.flush_count:,d} took '
387+
self.logger.info(f'backup flush took '
388388
f'{elapsed:.1f}s. Height {flush_data.height:,d} '
389389
f'txs: {flush_data.tx_count:,d} ({tx_delta:+,d})')
390390

@@ -595,7 +595,6 @@ def read_utxo_state(self):
595595
self.db_tx_count = 0
596596
self.db_tip = b'\0' * 32
597597
self.db_version = max(self.DB_VERSIONS)
598-
self.utxo_flush_count = 0
599598
self.wall_time = 0
600599
self.first_sync = True
601600
else:
@@ -617,7 +616,6 @@ def read_utxo_state(self):
617616
self.db_height = state['height']
618617
self.db_tx_count = state['tx_count']
619618
self.db_tip = state['tip']
620-
self.utxo_flush_count = state['utxo_flush_count']
621619
self.wall_time = state['wall_time']
622620
self.first_sync = state['first_sync']
623621

@@ -735,18 +733,12 @@ def write_utxo_state(self, batch):
735733
'height': self.db_height,
736734
'tx_count': self.db_tx_count,
737735
'tip': self.db_tip,
738-
'utxo_flush_count': self.utxo_flush_count,
739736
'wall_time': self.wall_time,
740737
'first_sync': self.first_sync,
741738
'db_version': self.db_version,
742739
}
743740
batch.put(b'state', repr(state).encode())
744741

745-
def set_flush_count(self, count):
746-
self.utxo_flush_count = count
747-
with self.utxo_db.write_batch() as batch:
748-
self.write_utxo_state(batch)
749-
750742
async def all_utxos(self, hashX):
751743
'''Return all UTXOs for an address sorted in no particular order.'''
752744
def read_utxos():

0 commit comments

Comments
 (0)