fixes for various edge cases where claim creation, updating and abandoning is occuring in the same block

This commit is contained in:
Lex Berezhny 2019-12-14 17:30:42 -05:00
parent 74469829e5
commit 7fa26d59da
2 changed files with 43 additions and 5 deletions

View file

@ -684,6 +684,7 @@ class SQLDB:
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 = []
update_claim_hashes = set()
delete_claim_hashes = set() delete_claim_hashes = set()
insert_supports = [] insert_supports = []
delete_support_txo_hashes = set() delete_support_txo_hashes = set()
@ -718,15 +719,25 @@ class SQLDB:
update_claims.append(output) update_claims.append(output)
recalculate_claim_hashes.add(claim_hash) recalculate_claim_hashes.add(claim_hash)
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 update_claim_hashes.add(claim_hash)
body_timer.stop() body_timer.stop()
skip_claim_timer = timer.add_timer('skip insertion of abandoned claims') skip_update_claim_timer = timer.add_timer('skip update of abandoned claims')
skip_claim_timer.start() skip_update_claim_timer.start()
for updated_claim in list(update_claims):
if updated_claim.ref.hash in delete_others:
update_claims.remove(updated_claim)
delete_claim_hashes.add(updated_claim.claim_hash)
update_claim_hashes.discard(updated_claim.claim_hash)
skip_update_claim_timer.stop()
skip_insert_claim_timer = timer.add_timer('skip insertion of abandoned claims')
skip_insert_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:
if new_claim.claim_hash not in update_claim_hashes:
insert_claims.remove(new_claim) insert_claims.remove(new_claim)
skip_claim_timer.stop() skip_insert_claim_timer.stop()
expire_timer = timer.add_timer('recording expired claims') expire_timer = timer.add_timer('recording expired claims')
expire_timer.start() expire_timer.start()

View file

@ -315,6 +315,33 @@ class TestClaimtrie(TestSQLDB):
accepted=[] accepted=[]
) )
def test_create_and_update_in_same_block(self):
advance, state = self.advance, self.state
stream = self.get_stream('Claim A', 10*COIN)
advance(10, [stream, self.get_stream_update(stream, 11*COIN)])
self.assertTrue(reader._search())
def test_create_and_abandon_in_same_block(self):
advance, state = self.advance, self.state
stream = self.get_stream('Claim A', 10*COIN)
advance(10, [stream, self.get_abandon(stream)])
self.assertFalse(reader._search())
def test_update_and_abandon_in_same_block(self):
advance, state = self.advance, self.state
stream = self.get_stream('Claim A', 10*COIN)
advance(10, [stream])
update = self.get_stream_update(stream, 11*COIN)
advance(20, [update, self.get_abandon(update)])
self.assertFalse(reader._search())
def test_create_update_and_delete_in_same_block(self):
advance, state = self.advance, self.state
stream = self.get_stream('Claim A', 10*COIN)
update = self.get_stream_update(stream, 11*COIN)
advance(10, [stream, update, self.get_abandon(update)])
self.assertFalse(reader._search())
@staticmethod @staticmethod
def _get_x_with_claim_id_prefix(getter, prefix, cached_iteration=None, **kwargs): def _get_x_with_claim_id_prefix(getter, prefix, cached_iteration=None, **kwargs):
iterations = cached_iteration+1 if cached_iteration else 100 iterations = cached_iteration+1 if cached_iteration else 100