diff --git a/lbry/wallet/server/block_processor.py b/lbry/wallet/server/block_processor.py index 6615e7b0a..637a4a0f7 100644 --- a/lbry/wallet/server/block_processor.py +++ b/lbry/wallet/server/block_processor.py @@ -430,7 +430,7 @@ class BlockProcessor: if signing_channel: raw_channel_tx = self.db.db.get( - DB_PREFIXES.TX_PREFIX.value + self.db.total_transactions[signing_channel.tx_num] + DB_PREFIXES.tx.value + self.db.total_transactions[signing_channel.tx_num] ) channel_pub_key_bytes = None try: diff --git a/lbry/wallet/server/db/__init__.py b/lbry/wallet/server/db/__init__.py index a56958c29..c6723afbf 100644 --- a/lbry/wallet/server/db/__init__.py +++ b/lbry/wallet/server/db/__init__.py @@ -24,18 +24,15 @@ class DB_PREFIXES(enum.Enum): repost = b'V' reposted_claim = b'W' - undo_claimtrie = b'M' + undo = b'M' - HISTORY_PREFIX = b'A' - TX_PREFIX = b'B' - BLOCK_HASH_PREFIX = b'C' - HEADER_PREFIX = b'H' - TX_NUM_PREFIX = b'N' - TX_COUNT_PREFIX = b'T' - UNDO_PREFIX = b'U' - TX_HASH_PREFIX = b'X' - - HASHX_UTXO_PREFIX = b'h' + tx = b'B' + block_hash = b'C' + header = b'H' + tx_num = b'N' + tx_count = b'T' + tx_hash = b'X' + utxo = b'u' + hashx_utxo = b'h' + hashx_history = b'x' db_state = b's' - UTXO_PREFIX = b'u' - HASHX_HISTORY_PREFIX = b'x' diff --git a/lbry/wallet/server/db/prefixes.py b/lbry/wallet/server/db/prefixes.py index 74c2b2984..d1cc21b99 100644 --- a/lbry/wallet/server/db/prefixes.py +++ b/lbry/wallet/server/db/prefixes.py @@ -938,7 +938,7 @@ class RepostedPrefixRow(PrefixRow): class UndoPrefixRow(PrefixRow): - prefix = DB_PREFIXES.undo_claimtrie.value + prefix = DB_PREFIXES.undo.value key_struct = struct.Struct(b'>Q') @classmethod @@ -965,7 +965,7 @@ class UndoPrefixRow(PrefixRow): class BlockHashPrefixRow(PrefixRow): - prefix = DB_PREFIXES.BLOCK_HASH_PREFIX.value + prefix = DB_PREFIXES.block_hash.value key_struct = struct.Struct(b'>L') value_struct = struct.Struct(b'>32s') @@ -991,7 +991,7 @@ class BlockHashPrefixRow(PrefixRow): class BlockHeaderPrefixRow(PrefixRow): - prefix = DB_PREFIXES.HEADER_PREFIX.value + prefix = DB_PREFIXES.header.value key_struct = struct.Struct(b'>L') value_struct = struct.Struct(b'>112s') @@ -1017,7 +1017,7 @@ class BlockHeaderPrefixRow(PrefixRow): class TXNumPrefixRow(PrefixRow): - prefix = DB_PREFIXES.TX_NUM_PREFIX.value + prefix = DB_PREFIXES.tx_num.value key_struct = struct.Struct(b'>32s') value_struct = struct.Struct(b'>L') @@ -1043,7 +1043,7 @@ class TXNumPrefixRow(PrefixRow): class TxCountPrefixRow(PrefixRow): - prefix = DB_PREFIXES.TX_COUNT_PREFIX.value + prefix = DB_PREFIXES.tx_count.value key_struct = struct.Struct(b'>L') value_struct = struct.Struct(b'>L') @@ -1069,7 +1069,7 @@ class TxCountPrefixRow(PrefixRow): class TXHashPrefixRow(PrefixRow): - prefix = DB_PREFIXES.TX_HASH_PREFIX.value + prefix = DB_PREFIXES.tx_hash.value key_struct = struct.Struct(b'>L') value_struct = struct.Struct(b'>32s') @@ -1095,7 +1095,7 @@ class TXHashPrefixRow(PrefixRow): class TXPrefixRow(PrefixRow): - prefix = DB_PREFIXES.TX_PREFIX.value + prefix = DB_PREFIXES.tx.value key_struct = struct.Struct(b'>32s') @classmethod @@ -1120,7 +1120,7 @@ class TXPrefixRow(PrefixRow): class UTXOPrefixRow(PrefixRow): - prefix = DB_PREFIXES.UTXO_PREFIX.value + prefix = DB_PREFIXES.utxo.value key_struct = struct.Struct(b'>11sLH') value_struct = struct.Struct(b'>Q') @@ -1153,7 +1153,7 @@ class UTXOPrefixRow(PrefixRow): class HashXUTXOPrefixRow(PrefixRow): - prefix = DB_PREFIXES.HASHX_UTXO_PREFIX.value + prefix = DB_PREFIXES.hashx_utxo.value key_struct = struct.Struct(b'>4sLH') value_struct = struct.Struct(b'>11s') @@ -1186,7 +1186,7 @@ class HashXUTXOPrefixRow(PrefixRow): class HashXHistoryPrefixRow(PrefixRow): - prefix = DB_PREFIXES.HASHX_HISTORY_PREFIX.value + prefix = DB_PREFIXES.hashx_history.value key_struct = struct.Struct(b'>11sL') key_part_lambdas = [ diff --git a/lbry/wallet/server/leveldb.py b/lbry/wallet/server/leveldb.py index 4441e7c4f..d31e81eea 100644 --- a/lbry/wallet/server/leveldb.py +++ b/lbry/wallet/server/leveldb.py @@ -417,7 +417,7 @@ class LevelDB: for _k, _v in self.db.iterator(prefix=Prefixes.claim_expiration.pack_partial_key(height)): k, v = Prefixes.claim_expiration.unpack_item(_k, _v) tx_hash = self.total_transactions[k.tx_num] - tx = self.coin.transaction(self.db.get(DB_PREFIXES.TX_PREFIX.value + tx_hash)) + tx = self.coin.transaction(self.db.get(DB_PREFIXES.tx.value + tx_hash)) # treat it like a claim spend so it will delete/abandon properly # the _spend_claim function this result is fed to expects a txi, so make a mock one # print(f"\texpired lbry://{v.name} {v.claim_hash.hex()}") @@ -443,7 +443,7 @@ class LevelDB: def get_claim_metadata(self, tx_hash, nout): raw = self.db.get( - DB_PREFIXES.TX_PREFIX.value + tx_hash + DB_PREFIXES.tx.value + tx_hash ) try: output = self.coin.transaction(raw).outputs[nout] @@ -493,7 +493,7 @@ class LevelDB: if reposted_claim: reposted_tx_hash = self.total_transactions[reposted_claim.tx_num] raw_reposted_claim_tx = self.db.get( - DB_PREFIXES.TX_PREFIX.value + reposted_tx_hash + DB_PREFIXES.tx.value + reposted_tx_hash ) try: reposted_claim_txo = self.coin.transaction( @@ -659,8 +659,8 @@ class LevelDB: def get_counts(): return tuple( - util.unpack_be_uint64(tx_count) - for tx_count in self.db.iterator(prefix=DB_PREFIXES.TX_COUNT_PREFIX.value, include_key=False) + Prefixes.tx_count.unpack_value(packed_tx_count).tx_count + for packed_tx_count in self.db.iterator(prefix=Prefixes.tx_count.value, include_key=False) ) tx_counts = await asyncio.get_event_loop().run_in_executor(self.executor, get_counts) @@ -675,7 +675,7 @@ class LevelDB: async def _read_txids(self): def get_txids(): - return list(self.db.iterator(prefix=DB_PREFIXES.TX_HASH_PREFIX.value, include_key=False)) + return list(self.db.iterator(prefix=Prefixes.tx_hash.prefix, include_key=False)) start = time.perf_counter() self.logger.info("loading txids") @@ -694,7 +694,7 @@ class LevelDB: def get_headers(): return [ - header for header in self.db.iterator(prefix=DB_PREFIXES.HEADER_PREFIX.value, include_key=False) + header for header in self.db.iterator(prefix=Prefixes.header.prefix, include_key=False) ] headers = await asyncio.get_event_loop().run_in_executor(self.executor, get_headers)