Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
Add warning of witness presistence race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
carver committed Nov 20, 2020
1 parent 24b1d54 commit 613711a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/core/p2p-proto/test_wit_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,10 @@ async def test_witness_union():

expected = hash1_witnesses_unique1 | hash1_witnesses_both | hash1_witnesses_unique2
assert set(stored_hashes) == expected


# Things that should be true
# - saving two hash sets should never erase the results of one of them (be sure to handle race conditions)
# - eventually: get stats like Counter of the hashes
# - history should not shorten by getting multiple results for the same blockhash
# - get the union of all received hashes for a given blockhash
4 changes: 4 additions & 0 deletions trinity/protocol/wit/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def persist_witness_hashes(
recent_blocks_with_witnesses)

try:
# Note: if this call is converted to async, watch out for the race
# condition of two persists that interleave. It would be
# possible for one to overwrite the other. For now, the synchronous
# approach means that that isn't a concern.
existing_hashes = self.get_witness_hashes(block_hash)
except WitnessHashesUnavailable:
existing_hashes = ()
Expand Down

0 comments on commit 613711a

Please sign in to comment.