From 1790ee301880ad52b223454016b314ef7421c3e1 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Sun, 12 Jul 2020 16:27:51 -0400 Subject: [PATCH] bug fixes and performance improvements --- lbry/blockchain/sync/blocks.py | 8 ++++---- lbry/db/queries/txio.py | 2 +- lbry/db/sync.py | 2 +- lbry/db/tables.py | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lbry/blockchain/sync/blocks.py b/lbry/blockchain/sync/blocks.py index 778979cac..405b4ed62 100644 --- a/lbry/blockchain/sync/blocks.py +++ b/lbry/blockchain/sync/blocks.py @@ -126,12 +126,12 @@ def sync_txoi(initial_sync: bool, p: ProgressContext): p.step() else: p.start(2) - # 1. Update TXIs to have the address of TXO they are spending. - set_input_addresses(p.ctx) - p.step() - # 2. Update spent TXOs setting spent_height + # 1. Update spent TXOs setting spent_height update_spent_outputs(p.ctx) p.step() + # 2. Update TXIs to have the address of TXO they are spending. + set_input_addresses(p.ctx) + p.step() @event_emitter("blockchain.sync.filter.generate", "blocks") diff --git a/lbry/db/queries/txio.py b/lbry/db/queries/txio.py index aba8320ef..7cb23ba2d 100644 --- a/lbry/db/queries/txio.py +++ b/lbry/db/queries/txio.py @@ -134,12 +134,12 @@ def distribute_unspent_txos( total = 0 buckets = [] for bucket in context().fetchall(sql): + total += bucket['items'] if len(buckets) > 0: if buckets[-1][-1] == bucket['start_height']: if bucket['start_height'] == bucket['end_height']: continue bucket['start_height'] += 1 - total += bucket['items'] buckets.append((bucket['start_height'], bucket['end_height'])) return total, buckets diff --git a/lbry/db/sync.py b/lbry/db/sync.py index b0423f6f2..19ac91a9f 100644 --- a/lbry/db/sync.py +++ b/lbry/db/sync.py @@ -67,7 +67,7 @@ def update_spent_outputs(ctx): ) }).where( (TXO.c.spent_height == 0) & - (TXO.c.txo_hash.in_(select(TXI.c.txo_hash))) + (TXO.c.txo_hash.in_(select(TXI.c.txo_hash).where(TXI.c.address.is_(None)))) ) ) ctx.execute(set_spent_height) diff --git a/lbry/db/tables.py b/lbry/db/tables.py index d0e5c6769..21545681b 100644 --- a/lbry/db/tables.py +++ b/lbry/db/tables.py @@ -200,6 +200,7 @@ Support = Table( Column('address', Text), Column('amount', BigInteger), Column('height', Integer), + Column('timestamp', Integer), # support metadata Column('emoji', Text),