faster _cached_get_active_amount for claims

-remove dead code
This commit is contained in:
Jack Robison 2021-07-26 13:25:50 -04:00
parent 0273a4e839
commit def2903f7d
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 16 additions and 11 deletions

View file

@ -673,19 +673,16 @@ class BlockProcessor:
def _cached_get_active_amount(self, claim_hash: bytes, txo_type: int, height: int) -> int: def _cached_get_active_amount(self, claim_hash: bytes, txo_type: int, height: int) -> int:
if (claim_hash, txo_type, height) in self.amount_cache: if (claim_hash, txo_type, height) in self.amount_cache:
return self.amount_cache[(claim_hash, txo_type, height)] return self.amount_cache[(claim_hash, txo_type, height)]
self.amount_cache[(claim_hash, txo_type, height)] = amount = self.db._get_active_amount( if txo_type == ACTIVATED_CLAIM_TXO_TYPE:
claim_hash, txo_type, height self.amount_cache[(claim_hash, txo_type, height)] = amount = self.db.get_active_amount_as_of_height(
) claim_hash, height
)
else:
self.amount_cache[(claim_hash, txo_type, height)] = amount = self.db._get_active_amount(
claim_hash, txo_type, height
)
return amount return amount
def _cached_get_effective_amount(self, claim_hash: bytes, support_only=False) -> int:
support_amount = self._cached_get_active_amount(claim_hash, ACTIVATED_SUPPORT_TXO_TYPE, self.db.db_height + 1)
if support_only:
return support_only
return support_amount + self._cached_get_active_amount(
claim_hash, ACTIVATED_CLAIM_TXO_TYPE, self.db.db_height + 1
)
def _get_pending_claim_amount(self, name: str, claim_hash: bytes, height=None) -> int: def _get_pending_claim_amount(self, name: str, claim_hash: bytes, height=None) -> int:
if (name, claim_hash) in self.activated_claim_amount_by_name_and_hash: if (name, claim_hash) in self.activated_claim_amount_by_name_and_hash:
return self.activated_claim_amount_by_name_and_hash[(name, claim_hash)] return self.activated_claim_amount_by_name_and_hash[(name, claim_hash)]

View file

@ -402,6 +402,14 @@ class LevelDB:
claim_hash, txo_type, height), include_key=False) claim_hash, txo_type, height), include_key=False)
) )
def get_active_amount_as_of_height(self, claim_hash: bytes, height: int) -> int:
for v in self.db.iterator(
start=Prefixes.active_amount.pack_partial_key(claim_hash, ACTIVATED_CLAIM_TXO_TYPE, 0),
stop=Prefixes.active_amount.pack_partial_key(claim_hash, ACTIVATED_CLAIM_TXO_TYPE, height),
include_key=False, reverse=True):
return Prefixes.active_amount.unpack_value(v).amount
return 0
def get_effective_amount(self, claim_hash: bytes, support_only=False) -> int: def get_effective_amount(self, claim_hash: bytes, support_only=False) -> int:
support_amount = self._get_active_amount(claim_hash, ACTIVATED_SUPPORT_TXO_TYPE, self.db_height + 1) support_amount = self._get_active_amount(claim_hash, ACTIVATED_SUPPORT_TXO_TYPE, self.db_height + 1)
if support_only: if support_only: