vacuum before setting inputs

This commit is contained in:
Lex Berezhny 2020-06-30 19:37:00 -04:00
parent 39d8a20fd5
commit 4b50d1e329
2 changed files with 27 additions and 14 deletions

View file

@ -150,20 +150,22 @@ def process_inputs_outputs(initial_sync=False, p=None):
step = 1 step = 1
if initial_sync and p.ctx.is_postgres: if initial_sync and p.ctx.is_postgres:
p.start(4) p.start(6)
else: else:
p.start(2) p.start(2)
# 1. Update TXIs to have the address of TXO they are spending. # 0. Vacuum
set_input_addresses(p.ctx)
p.step(step)
step += 1
if initial_sync and p.ctx.is_postgres: if initial_sync and p.ctx.is_postgres:
p.ctx.execute(text("ALTER TABLE txi ADD PRIMARY KEY (txo_hash);")) with p.ctx.engine.connect() as c:
p.step(step) c.execute(text("COMMIT;"))
step += 1 c.execute(text("VACUUM FULL ANALYZE txo;"))
p.step(step)
step += 1
c.execute(text("VACUUM FULL ANALYZE txi;"))
p.step(step)
step += 1
# 2. Update spent TXOs setting is_spent = True # 1. Update spent TXOs setting is_spent = True
update_spent_outputs(p.ctx) update_spent_outputs(p.ctx)
p.step(step) p.step(step)
step += 1 step += 1
@ -172,6 +174,15 @@ def process_inputs_outputs(initial_sync=False, p=None):
p.step(step) p.step(step)
step += 1 step += 1
# 2. Update TXIs to have the address of TXO they are spending.
set_input_addresses(p.ctx)
p.step(step)
step += 1
if initial_sync and p.ctx.is_postgres:
p.ctx.execute(text("ALTER TABLE txi ADD PRIMARY KEY (txo_hash);"))
p.step(step)
step += 1
@sync_step(Event.BLOCK_FILTER, initial_sync=True, ongoing_sync=True) @sync_step(Event.BLOCK_FILTER, initial_sync=True, ongoing_sync=True)
def process_block_filters(p=None): def process_block_filters(p=None):

View file

@ -535,11 +535,13 @@ class TestMultiBlockFileSyncing(BasicBlockchainTestCase):
# 3 - db.sync.input # 3 - db.sync.input
self.assertEventsAlmostEqual( self.assertEventsAlmostEqual(
self.extract_events('db.sync.input', events), [ self.extract_events('db.sync.input', events), [
[0, 4], [0, 6],
[1, 4], [1, 6],
[2, 4], [2, 6],
[3, 4], [3, 6],
[4, 4], [4, 6],
[5, 6],
[6, 6],
] if self.db_driver == 'postgresql' else [ ] if self.db_driver == 'postgresql' else [
[0, 2], [0, 2],
[1, 2], [1, 2],