forked from LBRYCommunity/lbry-sdk
fix applying expiration fork
This commit is contained in:
parent
c59d08080e
commit
c42ee926da
3 changed files with 30 additions and 3 deletions
|
@ -311,6 +311,11 @@ class BlockProcessor:
|
||||||
await self.run_in_thread(self.advance_block, block)
|
await self.run_in_thread(self.advance_block, block)
|
||||||
await self.flush()
|
await self.flush()
|
||||||
self.logger.info("advanced to %i in %0.3fs", self.height, time.perf_counter() - start)
|
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
|
# TODO: we shouldnt wait on the search index updating before advancing to the next block
|
||||||
if not self.db.first_sync:
|
if not self.db.first_sync:
|
||||||
await self.db.search_index.claim_consumer(self.claim_producer())
|
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)
|
reposted_claim_hash = self.db.get_repost(claim_hash)
|
||||||
return StagedClaimtrieItem(
|
return StagedClaimtrieItem(
|
||||||
claim.name, claim_hash, claim.amount,
|
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.tx_num, claim.position, claim.root_tx_num, claim.root_position,
|
||||||
claim.channel_signature_is_valid, signing_hash, reposted_claim_hash
|
claim.channel_signature_is_valid, signing_hash, reposted_claim_hash
|
||||||
)
|
)
|
||||||
|
|
|
@ -351,7 +351,9 @@ class LBC(Coin):
|
||||||
return sha256(script).digest()[:HASHX_LEN]
|
return sha256(script).digest()[:HASHX_LEN]
|
||||||
|
|
||||||
@classmethod
|
@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:
|
if last_updated_height < cls.nExtendedClaimExpirationForkHeight:
|
||||||
return last_updated_height + cls.nOriginalClaimExpirationTime
|
return last_updated_height + cls.nOriginalClaimExpirationTime
|
||||||
return last_updated_height + cls.nExtendedClaimExpirationTime
|
return last_updated_height + cls.nExtendedClaimExpirationTime
|
||||||
|
|
|
@ -1079,7 +1079,24 @@ class LevelDB:
|
||||||
def read_undo_info(self, height: int):
|
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))
|
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):
|
def write_db_state(self, batch):
|
||||||
"""Write (UTXO) state to the batch."""
|
"""Write (UTXO) state to the batch."""
|
||||||
|
|
Loading…
Reference in a new issue