faster get_future_activated
This commit is contained in:
parent
813e506b68
commit
1a5912877e
2 changed files with 11 additions and 9 deletions
|
@ -895,16 +895,16 @@ class BlockProcessor:
|
|||
# upon the delayed activation of B, we need to detect to activate C and make it take over early instead
|
||||
|
||||
claim_exists = {}
|
||||
for activated, activated_txos in self.db.get_future_activated(height).items():
|
||||
for activated, activated_claim_txo in self.db.get_future_activated(height):
|
||||
# uses the pending effective amount for the future activation height, not the current height
|
||||
future_amount = self._get_pending_claim_amount(
|
||||
activated.name, activated.claim_hash, activated_txos[-1].height + 1
|
||||
activated.name, activated.claim_hash, activated_claim_txo.height + 1
|
||||
)
|
||||
if activated.claim_hash not in claim_exists:
|
||||
claim_exists[activated.claim_hash] = activated.claim_hash in self.claim_hash_to_txo or (
|
||||
self.db.get_claim_txo(activated.claim_hash) is not None)
|
||||
if claim_exists[activated.claim_hash] and activated.claim_hash not in self.abandoned_claims:
|
||||
v = future_amount, activated, activated_txos[-1]
|
||||
v = future_amount, activated, activated_claim_txo
|
||||
future_activations[activated.name][activated.claim_hash] = v
|
||||
|
||||
for name, future_activated in activate_in_future.items():
|
||||
|
|
|
@ -652,15 +652,17 @@ class LevelDB:
|
|||
activated[v].append(k)
|
||||
return activated
|
||||
|
||||
def get_future_activated(self, height: int) -> DefaultDict[PendingActivationValue, List[PendingActivationKey]]:
|
||||
activated = defaultdict(list)
|
||||
def get_future_activated(self, height: int) -> typing.Generator[
|
||||
Tuple[PendingActivationValue, PendingActivationKey], None, None]:
|
||||
yielded = set()
|
||||
start_prefix = Prefixes.pending_activation.pack_partial_key(height + 1)
|
||||
stop_prefix = Prefixes.pending_activation.pack_partial_key(height + 1 + self.coin.maxTakeoverDelay)
|
||||
for _k, _v in self.db.iterator(start=start_prefix, stop=stop_prefix):
|
||||
k = Prefixes.pending_activation.unpack_key(_k)
|
||||
for _k, _v in self.db.iterator(start=start_prefix, stop=stop_prefix, reverse=True):
|
||||
v = Prefixes.pending_activation.unpack_value(_v)
|
||||
activated[v].append(k)
|
||||
return activated
|
||||
if v not in yielded:
|
||||
yielded.add(v)
|
||||
k = Prefixes.pending_activation.unpack_key(_k)
|
||||
yield v, k
|
||||
|
||||
async def _read_tx_counts(self):
|
||||
if self.tx_counts is not None:
|
||||
|
|
Loading…
Reference in a new issue