cleanup
This commit is contained in:
parent
02d479b92d
commit
ce09f2eb0f
1 changed files with 7 additions and 19 deletions
|
@ -634,7 +634,7 @@ class BlockProcessor:
|
||||||
return spend_claim_ops
|
return spend_claim_ops
|
||||||
return self._spend_support_txo(txin)
|
return self._spend_support_txo(txin)
|
||||||
|
|
||||||
def _abandon_claim(self, claim_hash, tx_num, nout, name) -> List['RevertableOp']:
|
def _abandon_claim(self, claim_hash, tx_num, nout, name):
|
||||||
claim_from_db = False
|
claim_from_db = False
|
||||||
if (tx_num, nout) in self.txo_to_claim:
|
if (tx_num, nout) in self.txo_to_claim:
|
||||||
pending = self.txo_to_claim.pop((tx_num, nout))
|
pending = self.txo_to_claim.pop((tx_num, nout))
|
||||||
|
@ -666,8 +666,6 @@ class BlockProcessor:
|
||||||
self.support_txos_by_claim[claim_hash].clear()
|
self.support_txos_by_claim[claim_hash].clear()
|
||||||
self.support_txos_by_claim.pop(claim_hash)
|
self.support_txos_by_claim.pop(claim_hash)
|
||||||
|
|
||||||
ops = []
|
|
||||||
|
|
||||||
if staged.name.startswith('@'): # abandon a channel, invalidate signatures
|
if staged.name.startswith('@'): # abandon a channel, invalidate signatures
|
||||||
for k, claim_hash in self.db.db.iterator(prefix=Prefixes.channel_to_claim.pack_partial_key(staged.claim_hash)):
|
for k, claim_hash in self.db.db.iterator(prefix=Prefixes.channel_to_claim.pack_partial_key(staged.claim_hash)):
|
||||||
if claim_hash in self.abandoned_claims or claim_hash in self.expired_claim_hashes:
|
if claim_hash in self.abandoned_claims or claim_hash in self.expired_claim_hashes:
|
||||||
|
@ -678,7 +676,7 @@ class BlockProcessor:
|
||||||
else:
|
else:
|
||||||
claim = self.db.get_claim_txo(claim_hash)
|
claim = self.db.get_claim_txo(claim_hash)
|
||||||
assert claim is not None
|
assert claim is not None
|
||||||
ops.extend([
|
self.db_op_stack.extend([
|
||||||
RevertableDelete(k, claim_hash),
|
RevertableDelete(k, claim_hash),
|
||||||
RevertableDelete(
|
RevertableDelete(
|
||||||
*Prefixes.claim_to_txo.pack_item(
|
*Prefixes.claim_to_txo.pack_item(
|
||||||
|
@ -694,29 +692,24 @@ class BlockProcessor:
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
if staged.signing_hash and claim_from_db:
|
if staged.signing_hash and claim_from_db:
|
||||||
ops.append(RevertableDelete(
|
self.db_op_stack.append(RevertableDelete(
|
||||||
*Prefixes.claim_to_channel.pack_item(
|
*Prefixes.claim_to_channel.pack_item(
|
||||||
staged.claim_hash, staged.tx_num, staged.position, staged.signing_hash
|
staged.claim_hash, staged.tx_num, staged.position, staged.signing_hash
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
return ops
|
|
||||||
|
|
||||||
def _expire_claims(self, height: int):
|
def _expire_claims(self, height: int):
|
||||||
expired = self.db.get_expired_by_height(height)
|
expired = self.db.get_expired_by_height(height)
|
||||||
self.expired_claim_hashes.update(set(expired.keys()))
|
self.expired_claim_hashes.update(set(expired.keys()))
|
||||||
spent_claims = {}
|
spent_claims = {}
|
||||||
ops = []
|
|
||||||
for expired_claim_hash, (tx_num, position, name, txi) in expired.items():
|
for expired_claim_hash, (tx_num, position, name, txi) in expired.items():
|
||||||
if (tx_num, position) not in self.txo_to_claim:
|
if (tx_num, position) not in self.txo_to_claim:
|
||||||
ops.extend(self._spend_claim_txo(txi, spent_claims))
|
self.db_op_stack.extend(self._spend_claim_txo(txi, spent_claims))
|
||||||
if expired:
|
if expired:
|
||||||
# do this to follow the same content claim removing pathway as if a claim (possible channel) was abandoned
|
# do this to follow the same content claim removing pathway as if a claim (possible channel) was abandoned
|
||||||
for abandoned_claim_hash, (tx_num, nout, name) in spent_claims.items():
|
for abandoned_claim_hash, (tx_num, nout, name) in spent_claims.items():
|
||||||
# print(f"\texpire {abandoned_claim_hash.hex()} {tx_num} {nout}")
|
# print(f"\texpire {abandoned_claim_hash.hex()} {tx_num} {nout}")
|
||||||
abandon_ops = self._abandon_claim(abandoned_claim_hash, tx_num, nout, name)
|
self._abandon_claim(abandoned_claim_hash, tx_num, nout, name)
|
||||||
if abandon_ops:
|
|
||||||
ops.extend(abandon_ops)
|
|
||||||
return ops
|
|
||||||
|
|
||||||
def _cached_get_active_amount(self, claim_hash: bytes, txo_type: int, height: int) -> int:
|
def _cached_get_active_amount(self, claim_hash: bytes, txo_type: int, height: int) -> int:
|
||||||
if (claim_hash, txo_type, height) in self.amount_cache:
|
if (claim_hash, txo_type, height) in self.amount_cache:
|
||||||
|
@ -1232,9 +1225,7 @@ class BlockProcessor:
|
||||||
# Handle abandoned claims
|
# Handle abandoned claims
|
||||||
for abandoned_claim_hash, (tx_num, nout, name) in spent_claims.items():
|
for abandoned_claim_hash, (tx_num, nout, name) in spent_claims.items():
|
||||||
# print(f"\tabandon {abandoned_claim_hash.hex()} {tx_num} {nout}")
|
# print(f"\tabandon {abandoned_claim_hash.hex()} {tx_num} {nout}")
|
||||||
abandon_ops = self._abandon_claim(abandoned_claim_hash, tx_num, nout, name)
|
self._abandon_claim(abandoned_claim_hash, tx_num, nout, name)
|
||||||
if abandon_ops:
|
|
||||||
claimtrie_stash_extend(abandon_ops)
|
|
||||||
|
|
||||||
append_hashX_by_tx(hashXs)
|
append_hashX_by_tx(hashXs)
|
||||||
update_touched(hashXs)
|
update_touched(hashXs)
|
||||||
|
@ -1243,10 +1234,7 @@ class BlockProcessor:
|
||||||
tx_count += 1
|
tx_count += 1
|
||||||
|
|
||||||
# handle expired claims
|
# handle expired claims
|
||||||
expired_ops = self._expire_claims(height)
|
self._expire_claims(height)
|
||||||
if expired_ops:
|
|
||||||
# print(f"************\nexpire claims at block {height}\n************")
|
|
||||||
claimtrie_stash_extend(expired_ops)
|
|
||||||
|
|
||||||
# activate claims and process takeovers
|
# activate claims and process takeovers
|
||||||
self._get_takeover_ops(height)
|
self._get_takeover_ops(height)
|
||||||
|
|
Loading…
Reference in a new issue