faster get_future_activated

This commit is contained in:
Jack Robison 2021-06-06 13:01:06 -04:00 committed by Victor Shyba
parent 6330424bcd
commit b0cf25bf5c

View file

@ -436,12 +436,13 @@ class LevelDB:
def get_future_activated(self, height: int) -> DefaultDict[PendingActivationValue, List[PendingActivationKey]]: def get_future_activated(self, height: int) -> DefaultDict[PendingActivationValue, List[PendingActivationKey]]:
activated = defaultdict(list) activated = defaultdict(list)
for i in range(self.coin.maxTakeoverDelay): start_prefix = Prefixes.pending_activation.pack_partial_key(height + 1)
prefix = Prefixes.pending_activation.pack_partial_key(height+1+i) stop_prefix = Prefixes.pending_activation.pack_partial_key(height + 1 + self.coin.maxTakeoverDelay)
for _k, _v in self.db.iterator(prefix=prefix): for _k, _v in self.db.iterator(start=start_prefix, stop=stop_prefix):
k = Prefixes.pending_activation.unpack_key(_k) k = Prefixes.pending_activation.unpack_key(_k)
v = Prefixes.pending_activation.unpack_value(_v) v = Prefixes.pending_activation.unpack_value(_v)
activated[v].append(k) activated[v].append(k)
return activated return activated
async def _read_tx_counts(self): async def _read_tx_counts(self):