rename effective_amount prefix -> bid_order

This commit is contained in:
Jack Robison 2022-07-19 14:22:39 -04:00
parent 2627f02a55
commit 292ad2b9b6
4 changed files with 19 additions and 18 deletions

View file

@ -16,7 +16,7 @@ class DB_PREFIXES(enum.Enum):
channel_to_claim = b'J'
claim_short_id_prefix = b'F'
effective_amount = b'D'
bid_order = b'D'
claim_expiration = b'O'
claim_takeover = b'P'

View file

@ -22,7 +22,7 @@ from hub.common import hash_to_hex_str, LRUCacheWithMetrics, LFUCacheWithMetrics
from hub.db.merkle import Merkle, MerkleCache, FastMerkleCacheItem
from hub.db.common import ResolveResult, ExpandedResolveResult, DBError, UTXO
from hub.db.prefixes import PendingActivationValue, ClaimTakeoverValue, ClaimToTXOValue, PrefixDB
from hub.db.prefixes import ACTIVATED_CLAIM_TXO_TYPE, ACTIVATED_SUPPORT_TXO_TYPE, EffectiveAmountKey
from hub.db.prefixes import ACTIVATED_CLAIM_TXO_TYPE, ACTIVATED_SUPPORT_TXO_TYPE, BidOrderKey
from hub.db.prefixes import PendingActivationKey, TXOToClaimValue, DBStatePrefixRow, MempoolTXPrefixRow
from hub.db.prefixes import HashXMempoolStatusPrefixRow
@ -235,7 +235,7 @@ class SecondaryDB:
def get_claim_by_amount(normalized: str, order: int):
order = max(int(order or 1), 1)
for _idx, (key, claim_val) in enumerate(self.prefix_db.effective_amount.iterate(prefix=(normalized,))):
for _idx, (key, claim_val) in enumerate(self.prefix_db.bid_order.iterate(prefix=(normalized,))):
if order > _idx + 1:
continue
return claim_val.claim_hash
@ -512,8 +512,8 @@ class SecondaryDB:
claim_hash, ACTIVATED_SUPPORT_TXO_TYPE, self.db_height + 1
) + self._get_active_amount(claim_hash, ACTIVATED_CLAIM_TXO_TYPE, self.db_height + 1)
def get_url_effective_amount(self, name: str, claim_hash: bytes) -> Optional['EffectiveAmountKey']:
for k, v in self.prefix_db.effective_amount.iterate(prefix=(name,)):
def get_url_effective_amount(self, name: str, claim_hash: bytes) -> Optional['BidOrderKey']:
for k, v in self.prefix_db.bid_order.iterate(prefix=(name,)):
if v.claim_hash == claim_hash:
return k

View file

@ -354,14 +354,14 @@ class ActiveAmountValue(typing.NamedTuple):
amount: int
class EffectiveAmountKey(typing.NamedTuple):
class BidOrderKey(typing.NamedTuple):
normalized_name: str
effective_amount: int
tx_num: int
position: int
class EffectiveAmountValue(typing.NamedTuple):
class BidOrderValue(typing.NamedTuple):
claim_hash: bytes
def __str__(self):
@ -923,8 +923,8 @@ def effective_amount_helper(struct_fmt):
return wrapper
class EffectiveAmountPrefixRow(PrefixRow):
prefix = DB_PREFIXES.effective_amount.value
class BidOrderPrefixRow(PrefixRow):
prefix = DB_PREFIXES.bid_order.value
key_struct = struct.Struct(b'>QLH')
value_struct = struct.Struct(b'>20s')
key_part_lambdas = [
@ -943,16 +943,16 @@ class EffectiveAmountPrefixRow(PrefixRow):
)
@classmethod
def unpack_key(cls, key: bytes) -> EffectiveAmountKey:
def unpack_key(cls, key: bytes) -> BidOrderKey:
assert key[:1] == cls.prefix
name_len = int.from_bytes(key[1:3], byteorder='big')
name = key[3:3 + name_len].decode()
ones_comp_effective_amount, tx_num, position = cls.key_struct.unpack(key[3 + name_len:])
return EffectiveAmountKey(name, 0xffffffffffffffff - ones_comp_effective_amount, tx_num, position)
return BidOrderKey(name, 0xffffffffffffffff - ones_comp_effective_amount, tx_num, position)
@classmethod
def unpack_value(cls, data: bytes) -> EffectiveAmountValue:
return EffectiveAmountValue(*super().unpack_value(data))
def unpack_value(cls, data: bytes) -> BidOrderValue:
return BidOrderValue(*super().unpack_value(data))
@classmethod
def pack_value(cls, claim_hash: bytes) -> bytes:
@ -1788,7 +1788,7 @@ class PrefixDB(BasePrefixDB):
self.pending_activation = PendingActivationPrefixRow(db, self._op_stack)
self.activated = ActivatedPrefixRow(db, self._op_stack)
self.active_amount = ActiveAmountPrefixRow(db, self._op_stack)
self.effective_amount = EffectiveAmountPrefixRow(db, self._op_stack)
self.bid_order = BidOrderPrefixRow(db, self._op_stack)
self.repost = RepostPrefixRow(db, self._op_stack)
self.reposted_claim = RepostedPrefixRow(db, self._op_stack)
self.reposted_count = RepostedCountPrefixRow(db, self._op_stack)

View file

@ -1230,9 +1230,10 @@ class BlockchainProcessorService(BlockchainService):
removed_claim.normalized_name, removed
)
if amt:
self.db.prefix_db.effective_amount.stage_delete(
self.db.prefix_db.bid_order.stage_delete(
(removed_claim.normalized_name, amt.effective_amount, amt.tx_num, amt.position), (removed,)
)
for touched in self.touched_claim_hashes:
prev_effective_amount = 0
@ -1244,7 +1245,7 @@ class BlockchainProcessorService(BlockchainService):
claim_amount_info = self.db.get_url_effective_amount(name, touched)
if claim_amount_info:
prev_effective_amount = claim_amount_info.effective_amount
self.db.prefix_db.effective_amount.stage_delete(
self.db.prefix_db.bid_order.stage_delete(
(name, claim_amount_info.effective_amount, claim_amount_info.tx_num,
claim_amount_info.position), (touched,)
)
@ -1256,12 +1257,12 @@ class BlockchainProcessorService(BlockchainService):
amt = self.db.get_url_effective_amount(name, touched)
if amt:
prev_effective_amount = amt.effective_amount
self.db.prefix_db.effective_amount.stage_delete(
self.db.prefix_db.bid_order.stage_delete(
(name, prev_effective_amount, amt.tx_num, amt.position), (touched,)
)
new_effective_amount = self._get_pending_effective_amount(name, touched)
self.db.prefix_db.effective_amount.stage_put(
self.db.prefix_db.bid_order.stage_put(
(name, new_effective_amount, tx_num, position), (touched,)
)
if touched in self.claim_hash_to_txo or touched in self.removed_claim_hashes \