Skip to content

Commit

Permalink
🔥 Avoid concurrent modification
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Mar 26, 2024
1 parent e95f45c commit 43696dc
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions electrumx/server/block_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1826,10 +1826,11 @@ def create_or_delete_pow_records(self, tx_hash, tx_num, height, operations_found
# Exclude candidates that are earlier than MINT_SUBNAME_COMMIT_PAYMENT_DELAY_BLOCKS blocks
# of the current batch of candidates. For example: [808202, 808203, 808254, 808255] will return [808254, 808255]
# This will only affect session queries, regardless of indexing.
def exclude_outdated_candidates(self, all_entries):
def exclude_outdated_candidates(self, all_entries: List[dict]):
entries = all_entries.copy()
potential_exclude_entries = []
earliest_height = 0
for entry in all_entries:
for entry in entries:
_, height_info = self.build_candidate_heights_info(entry)
commit_height = height_info['commit_height']
if earliest_height == 0:
Expand All @@ -1838,10 +1839,11 @@ def exclude_outdated_candidates(self, all_entries):
continue
if commit_height - earliest_height > MINT_SUBNAME_COMMIT_PAYMENT_DELAY_BLOCKS:
for old_entry in potential_exclude_entries:
all_entries.remove(old_entry)
entries.remove(old_entry)
potential_exclude_entries.clear()
earliest_height = commit_height
potential_exclude_entries.append(entry)
return entries

# Get the effective realm considering cache and database
def get_effective_realm(self, realm_name, height):
Expand Down Expand Up @@ -1876,7 +1878,7 @@ def get_effective_subrealm(self, parent_realm_id, subrealm_name, height):
if len(all_entries) == 0:
return None, None, []
all_entries.sort(key=lambda x: x['tx_num'])
self.exclude_outdated_candidates(all_entries)
all_entries = self.exclude_outdated_candidates(all_entries)
for index, entry in enumerate(all_entries):
atomical_id = entry['value']
mint_info = self.get_atomicals_id_mint_info(atomical_id, False)
Expand Down Expand Up @@ -1964,7 +1966,7 @@ def get_effective_dmitem(self, parent_container_id, dmitem_name, current_height)
if len(all_entries) == 0:
return None, None, []
all_entries.sort(key=lambda x: x['tx_num'])
self.exclude_outdated_candidates(all_entries)
all_entries = self.exclude_outdated_candidates(all_entries)
for index, entry in enumerate(all_entries):
atomical_id = entry['value']
mint_info = self.get_atomicals_id_mint_info(atomical_id, False)
Expand Down Expand Up @@ -2038,7 +2040,7 @@ def get_effective_name_template(self, db_prefix, subject, height, name_data_cach
all_entries.extend(db_entries)
# sort by the earliest tx number because it was the first one committed
all_entries.sort(key=lambda x: x['tx_num'])
self.exclude_outdated_candidates(all_entries)
all_entries = self.exclude_outdated_candidates(all_entries)
if len(all_entries) > 0:
candidate_entry = all_entries[0]
atomical_id = candidate_entry['value']
Expand Down Expand Up @@ -2389,7 +2391,7 @@ def get_container_dmint_status_for_atomical_id(self, atomical_id, latest_state):
return dmint_format_status

# Convert candidates to heights info.
def build_candidate_heights_info(self, raw_candidate_entry):
def build_candidate_heights_info(self, raw_candidate_entry: dict):
candidate_atomical_id = raw_candidate_entry['value']
raw_mint_info_for_candidate_id = self.get_atomicals_id_mint_info(candidate_atomical_id, True)
return candidate_atomical_id, {
Expand Down

0 comments on commit 43696dc

Please sign in to comment.