Skip to content

Commit 43696dc

Browse files
committed
🔥 Avoid concurrent modification
1 parent e95f45c commit 43696dc

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

‎electrumx/server/block_processor.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,10 +1826,11 @@ def create_or_delete_pow_records(self, tx_hash, tx_num, height, operations_found
18261826
# Exclude candidates that are earlier than MINT_SUBNAME_COMMIT_PAYMENT_DELAY_BLOCKS blocks
18271827
# of the current batch of candidates. For example: [808202, 808203, 808254, 808255] will return [808254, 808255]
18281828
# This will only affect session queries, regardless of indexing.
1829-
def exclude_outdated_candidates(self, all_entries):
1829+
def exclude_outdated_candidates(self, all_entries: List[dict]):
1830+
entries = all_entries.copy()
18301831
potential_exclude_entries = []
18311832
earliest_height = 0
1832-
for entry in all_entries:
1833+
for entry in entries:
18331834
_, height_info = self.build_candidate_heights_info(entry)
18341835
commit_height = height_info['commit_height']
18351836
if earliest_height == 0:
@@ -1838,10 +1839,11 @@ def exclude_outdated_candidates(self, all_entries):
18381839
continue
18391840
if commit_height - earliest_height > MINT_SUBNAME_COMMIT_PAYMENT_DELAY_BLOCKS:
18401841
for old_entry in potential_exclude_entries:
1841-
all_entries.remove(old_entry)
1842+
entries.remove(old_entry)
18421843
potential_exclude_entries.clear()
18431844
earliest_height = commit_height
18441845
potential_exclude_entries.append(entry)
1846+
return entries
18451847

18461848
# Get the effective realm considering cache and database
18471849
def get_effective_realm(self, realm_name, height):
@@ -1876,7 +1878,7 @@ def get_effective_subrealm(self, parent_realm_id, subrealm_name, height):
18761878
if len(all_entries) == 0:
18771879
return None, None, []
18781880
all_entries.sort(key=lambda x: x['tx_num'])
1879-
self.exclude_outdated_candidates(all_entries)
1881+
all_entries = self.exclude_outdated_candidates(all_entries)
18801882
for index, entry in enumerate(all_entries):
18811883
atomical_id = entry['value']
18821884
mint_info = self.get_atomicals_id_mint_info(atomical_id, False)
@@ -1964,7 +1966,7 @@ def get_effective_dmitem(self, parent_container_id, dmitem_name, current_height)
19641966
if len(all_entries) == 0:
19651967
return None, None, []
19661968
all_entries.sort(key=lambda x: x['tx_num'])
1967-
self.exclude_outdated_candidates(all_entries)
1969+
all_entries = self.exclude_outdated_candidates(all_entries)
19681970
for index, entry in enumerate(all_entries):
19691971
atomical_id = entry['value']
19701972
mint_info = self.get_atomicals_id_mint_info(atomical_id, False)
@@ -2038,7 +2040,7 @@ def get_effective_name_template(self, db_prefix, subject, height, name_data_cach
20382040
all_entries.extend(db_entries)
20392041
# sort by the earliest tx number because it was the first one committed
20402042
all_entries.sort(key=lambda x: x['tx_num'])
2041-
self.exclude_outdated_candidates(all_entries)
2043+
all_entries = self.exclude_outdated_candidates(all_entries)
20422044
if len(all_entries) > 0:
20432045
candidate_entry = all_entries[0]
20442046
atomical_id = candidate_entry['value']
@@ -2389,7 +2391,7 @@ def get_container_dmint_status_for_atomical_id(self, atomical_id, latest_state):
23892391
return dmint_format_status
23902392

23912393
# Convert candidates to heights info.
2392-
def build_candidate_heights_info(self, raw_candidate_entry):
2394+
def build_candidate_heights_info(self, raw_candidate_entry: dict):
23932395
candidate_atomical_id = raw_candidate_entry['value']
23942396
raw_mint_info_for_candidate_id = self.get_atomicals_id_mint_info(candidate_atomical_id, True)
23952397
return candidate_atomical_id, {

0 commit comments

Comments
 (0)