forked from LBRYCommunity/lbry-sdk
delete claims and re-calculate winner when claim is expired
This commit is contained in:
parent
6651111522
commit
6965971613
3 changed files with 38 additions and 3 deletions
|
@ -622,6 +622,11 @@ class SQLDB:
|
||||||
r(self._update_effective_amount, height)
|
r(self._update_effective_amount, height)
|
||||||
r(self._perform_overtake, height, [], [])
|
r(self._perform_overtake, height, [], [])
|
||||||
|
|
||||||
|
def get_expiring(self, height):
|
||||||
|
return self.execute(
|
||||||
|
f"SELECT claim_hash, normalized FROM claim WHERE expiration_height = {height}"
|
||||||
|
)
|
||||||
|
|
||||||
def advance_txs(self, height, all_txs, header, daemon_height, timer):
|
def advance_txs(self, height, all_txs, header, daemon_height, timer):
|
||||||
insert_claims = []
|
insert_claims = []
|
||||||
update_claims = []
|
update_claims = []
|
||||||
|
@ -642,8 +647,8 @@ class SQLDB:
|
||||||
)
|
)
|
||||||
body_timer.start()
|
body_timer.start()
|
||||||
delete_claim_hashes.update({r['claim_hash'] for r in spent_claims})
|
delete_claim_hashes.update({r['claim_hash'] for r in spent_claims})
|
||||||
delete_support_txo_hashes.update({r['txo_hash'] for r in spent_supports})
|
|
||||||
deleted_claim_names.update({r['normalized'] for r in spent_claims})
|
deleted_claim_names.update({r['normalized'] for r in spent_claims})
|
||||||
|
delete_support_txo_hashes.update({r['txo_hash'] for r in spent_supports})
|
||||||
recalculate_claim_hashes.update({r['claim_hash'] for r in spent_supports})
|
recalculate_claim_hashes.update({r['claim_hash'] for r in spent_supports})
|
||||||
delete_others.update(spent_others)
|
delete_others.update(spent_others)
|
||||||
# Outputs
|
# Outputs
|
||||||
|
@ -661,12 +666,21 @@ class SQLDB:
|
||||||
delete_claim_hashes.discard(claim_hash)
|
delete_claim_hashes.discard(claim_hash)
|
||||||
delete_others.discard(output.ref.hash) # claim insertion and update occurring in the same block
|
delete_others.discard(output.ref.hash) # claim insertion and update occurring in the same block
|
||||||
body_timer.stop()
|
body_timer.stop()
|
||||||
|
|
||||||
skip_claim_timer = timer.add_timer('skip insertion of abandoned claims')
|
skip_claim_timer = timer.add_timer('skip insertion of abandoned claims')
|
||||||
skip_claim_timer.start()
|
skip_claim_timer.start()
|
||||||
for new_claim in list(insert_claims):
|
for new_claim in list(insert_claims):
|
||||||
if new_claim.ref.hash in delete_others:
|
if new_claim.ref.hash in delete_others:
|
||||||
insert_claims.remove(new_claim)
|
insert_claims.remove(new_claim)
|
||||||
skip_claim_timer.stop()
|
skip_claim_timer.stop()
|
||||||
|
|
||||||
|
expire_timer = timer.add_timer('recording expired claims')
|
||||||
|
expire_timer.start()
|
||||||
|
for expired in self.get_expiring(height):
|
||||||
|
delete_claim_hashes.add(expired['claim_hash'])
|
||||||
|
deleted_claim_names.add(expired['normalized'])
|
||||||
|
expire_timer.stop()
|
||||||
|
|
||||||
r = timer.run
|
r = timer.run
|
||||||
r(self.delete_claims, delete_claim_hashes)
|
r(self.delete_claims, delete_claim_hashes)
|
||||||
r(self.delete_supports, delete_support_txo_hashes)
|
r(self.delete_supports, delete_support_txo_hashes)
|
||||||
|
|
|
@ -134,7 +134,6 @@ class ResolveCommand(CommandTestCase):
|
||||||
channel_id = self.get_claim_id(
|
channel_id = self.get_claim_id(
|
||||||
await self.channel_create('@abc', '1.1', allow_duplicate_name=True))
|
await self.channel_create('@abc', '1.1', allow_duplicate_name=True))
|
||||||
await self.assertResolvesToClaimId(f'@abc', channel_id)
|
await self.assertResolvesToClaimId(f'@abc', channel_id)
|
||||||
await self.assertResolvesToClaimId(f'@abc#{channel_id[0]}', channel_id)
|
|
||||||
await self.assertResolvesToClaimId(f'@abc#{channel_id[:10]}', channel_id)
|
await self.assertResolvesToClaimId(f'@abc#{channel_id[:10]}', channel_id)
|
||||||
await self.assertResolvesToClaimId(f'@abc#{channel_id}', channel_id)
|
await self.assertResolvesToClaimId(f'@abc#{channel_id}', channel_id)
|
||||||
channel = (await self.claim_search(claim_id=channel_id))[0]
|
channel = (await self.claim_search(claim_id=channel_id))[0]
|
||||||
|
|
|
@ -140,7 +140,7 @@ class TestSQLDB(unittest.TestCase):
|
||||||
return [otx[0].tx.outputs[0] for otx in txs]
|
return [otx[0].tx.outputs[0] for otx in txs]
|
||||||
|
|
||||||
def state(self, controlling=None, active=None, accepted=None):
|
def state(self, controlling=None, active=None, accepted=None):
|
||||||
self.assertEqual(controlling or [], self.get_controlling())
|
self.assertEqual(controlling, self.get_controlling())
|
||||||
self.assertEqual(active or [], self.get_active())
|
self.assertEqual(active or [], self.get_active())
|
||||||
self.assertEqual(accepted or [], self.get_accepted())
|
self.assertEqual(accepted or [], self.get_accepted())
|
||||||
|
|
||||||
|
@ -288,6 +288,28 @@ class TestSQLDB(unittest.TestCase):
|
||||||
accepted=[]
|
accepted=[]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_winning_claim_expires_and_another_takes_over(self):
|
||||||
|
advance, state = self.advance, self.state
|
||||||
|
advance(10, [self.get_stream('Claim A', 11*COIN)])
|
||||||
|
advance(20, [self.get_stream('Claim B', 10*COIN)])
|
||||||
|
state(
|
||||||
|
controlling=('Claim A', 11*COIN, 11*COIN, 10),
|
||||||
|
active=[('Claim B', 10*COIN, 10*COIN, 20)],
|
||||||
|
accepted=[]
|
||||||
|
)
|
||||||
|
advance(262984, [])
|
||||||
|
state(
|
||||||
|
controlling=('Claim B', 10*COIN, 10*COIN, 20),
|
||||||
|
active=[],
|
||||||
|
accepted=[]
|
||||||
|
)
|
||||||
|
advance(262994, [])
|
||||||
|
state(
|
||||||
|
controlling=None,
|
||||||
|
active=[],
|
||||||
|
accepted=[]
|
||||||
|
)
|
||||||
|
|
||||||
def test_trending(self):
|
def test_trending(self):
|
||||||
advance, state = self.advance, self.state
|
advance, state = self.advance, self.state
|
||||||
no_trend = self.get_stream('Claim A', COIN)
|
no_trend = self.get_stream('Claim A', COIN)
|
||||||
|
|
Loading…
Reference in a new issue