forked from LBRYCommunity/lbry-sdk
sort touched or deleted claim hashes
This commit is contained in:
parent
c2a5ff0ae3
commit
ccc9a900ef
3 changed files with 17 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
|||
import struct
|
||||
from typing import Optional
|
||||
from lbry.wallet.server.db import DB_PREFIXES
|
||||
from lbry.wallet.server.db.revertable import RevertableOpStack
|
||||
from lbry.wallet.server.db.revertable import RevertableOpStack, RevertablePut, RevertableDelete
|
||||
|
||||
|
||||
class KeyValueStorage:
|
||||
|
@ -101,3 +101,9 @@ class PrefixDB:
|
|||
@property
|
||||
def closed(self):
|
||||
return self._db.closed
|
||||
|
||||
def stage_raw_put(self, key: bytes, value: bytes):
|
||||
self._op_stack.append_op(RevertablePut(key, value))
|
||||
|
||||
def stage_raw_delete(self, key: bytes, value: bytes):
|
||||
self._op_stack.append_op(RevertableDelete(key, value))
|
||||
|
|
|
@ -866,6 +866,11 @@ class ClaimTakeoverPrefixRow(PrefixRow):
|
|||
prefix = DB_PREFIXES.claim_takeover.value
|
||||
value_struct = struct.Struct(b'>20sL')
|
||||
|
||||
key_part_lambdas = [
|
||||
lambda: b'',
|
||||
length_encoded_name
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def pack_key(cls, name: str):
|
||||
return cls.prefix + length_encoded_name(name)
|
||||
|
@ -1412,10 +1417,10 @@ class TouchedOrDeletedPrefixRow(PrefixRow):
|
|||
return TouchedOrDeletedClaimKey(*super().unpack_key(key))
|
||||
|
||||
@classmethod
|
||||
def pack_value(cls, touched, deleted) -> bytes:
|
||||
def pack_value(cls, touched: typing.Set[bytes], deleted: typing.Set[bytes]) -> bytes:
|
||||
assert True if not touched else all(len(item) == 20 for item in touched)
|
||||
assert True if not deleted else all(len(item) == 20 for item in deleted)
|
||||
return cls.value_struct.pack(len(touched), len(deleted)) + b''.join(touched) + b''.join(deleted)
|
||||
return cls.value_struct.pack(len(touched), len(deleted)) + b''.join(sorted(touched)) + b''.join(sorted(deleted))
|
||||
|
||||
@classmethod
|
||||
def unpack_value(cls, data: bytes) -> TouchedOrDeletedClaimValue:
|
||||
|
@ -1565,9 +1570,10 @@ class LevelDBStore(KeyValueStorage):
|
|||
|
||||
|
||||
class HubDB(PrefixDB):
|
||||
def __init__(self, path: str, cache_mb: int, max_open_files: int = 512):
|
||||
def __init__(self, path: str, cache_mb: int, max_open_files: int = 512,
|
||||
unsafe_prefixes: Optional[typing.Set[bytes]] = None):
|
||||
db = LevelDBStore(path, cache_mb, max_open_files)
|
||||
super().__init__(db, unsafe_prefixes={DB_PREFIXES.db_state.value})
|
||||
super().__init__(db, unsafe_prefixes=unsafe_prefixes)
|
||||
self.claim_to_support = ClaimToSupportPrefixRow(db, self._op_stack)
|
||||
self.support_to_claim = SupportToClaimPrefixRow(db, self._op_stack)
|
||||
self.claim_to_txo = ClaimToTXOPrefixRow(db, self._op_stack)
|
||||
|
|
|
@ -996,9 +996,6 @@ class LevelDB:
|
|||
"""Returns a height from which we should store undo info."""
|
||||
return max_height - self.env.reorg_limit + 1
|
||||
|
||||
def read_undo_info(self, height: int):
|
||||
return self.prefix_db.undo.get(height), self.prefix_db.touched_or_deleted.get(height)
|
||||
|
||||
def apply_expiration_extension_fork(self):
|
||||
# TODO: this can't be reorged
|
||||
for k, v in self.prefix_db.claim_expiration.iterate():
|
||||
|
|
Loading…
Reference in a new issue