From c42ee926dae5d28267a2205a78bc6dc40e1f4201 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Thu, 29 Jul 2021 14:15:56 -0400 Subject: [PATCH] fix applying expiration fork --- lbry/wallet/server/block_processor.py | 10 +++++++++- lbry/wallet/server/coin.py | 4 +++- lbry/wallet/server/leveldb.py | 19 ++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lbry/wallet/server/block_processor.py b/lbry/wallet/server/block_processor.py index e3f548bbb..57585cd22 100644 --- a/lbry/wallet/server/block_processor.py +++ b/lbry/wallet/server/block_processor.py @@ -311,6 +311,11 @@ class BlockProcessor: await self.run_in_thread(self.advance_block, block) await self.flush() self.logger.info("advanced to %i in %0.3fs", self.height, time.perf_counter() - start) + if self.height == self.coin.nExtendedClaimExpirationForkHeight: + self.logger.warning( + "applying extended claim expiration fork on claims accepted by, %i", self.height + ) + await self.run_in_thread(self.db.apply_expiration_extension_fork) # TODO: we shouldnt wait on the search index updating before advancing to the next block if not self.db.first_sync: await self.db.search_index.claim_consumer(self.claim_producer()) @@ -646,7 +651,10 @@ class BlockProcessor: reposted_claim_hash = self.db.get_repost(claim_hash) return StagedClaimtrieItem( claim.name, claim_hash, claim.amount, - self.coin.get_expiration_height(bisect_right(self.db.tx_counts, claim.tx_num)), + self.coin.get_expiration_height( + bisect_right(self.db.tx_counts, claim.tx_num), + extended=self.height >= self.coin.nExtendedClaimExpirationForkHeight + ), claim.tx_num, claim.position, claim.root_tx_num, claim.root_position, claim.channel_signature_is_valid, signing_hash, reposted_claim_hash ) diff --git a/lbry/wallet/server/coin.py b/lbry/wallet/server/coin.py index deef80450..bd379f112 100644 --- a/lbry/wallet/server/coin.py +++ b/lbry/wallet/server/coin.py @@ -351,7 +351,9 @@ class LBC(Coin): return sha256(script).digest()[:HASHX_LEN] @classmethod - def get_expiration_height(cls, last_updated_height: int) -> int: + def get_expiration_height(cls, last_updated_height: int, extended: bool = False) -> int: + if extended: + return last_updated_height + cls.nExtendedClaimExpirationTime if last_updated_height < cls.nExtendedClaimExpirationForkHeight: return last_updated_height + cls.nOriginalClaimExpirationTime return last_updated_height + cls.nExtendedClaimExpirationTime diff --git a/lbry/wallet/server/leveldb.py b/lbry/wallet/server/leveldb.py index 82b5e4d4a..2e2ee023d 100644 --- a/lbry/wallet/server/leveldb.py +++ b/lbry/wallet/server/leveldb.py @@ -1079,7 +1079,24 @@ class LevelDB: def read_undo_info(self, height: int): return self.db.get(Prefixes.undo.pack_key(height)), self.db.get(Prefixes.touched_or_deleted.pack_key(height)) - # -- UTXO database + def apply_expiration_extension_fork(self): + # TODO: this can't be reorged + deletes = [] + adds = [] + + for k, v in self.db.iterator(prefix=Prefixes.claim_expiration.prefix): + old_key = Prefixes.claim_expiration.unpack_key(k) + new_key = Prefixes.claim_expiration.pack_key( + bisect_right(self.tx_counts, old_key.tx_num) + self.coin.nExtendedClaimExpirationTime, + old_key.tx_num, old_key.position + ) + deletes.append(k) + adds.append((new_key, v)) + with self.db.write_batch(transaction=True) as batch: + for k in deletes: + batch.delete(k) + for k, v in adds: + batch.put(k, v) def write_db_state(self, batch): """Write (UTXO) state to the batch."""