forked from LBRYCommunity/lbry-sdk
update undo key to include the block hash
This commit is contained in:
parent
358fa21eaf
commit
d3da442727
2 changed files with 16 additions and 12 deletions
|
@ -341,7 +341,7 @@ class BlockProcessor:
|
||||||
def flush():
|
def flush():
|
||||||
self.db.write_db_state()
|
self.db.write_db_state()
|
||||||
if save_undo:
|
if save_undo:
|
||||||
self.db.prefix_db.commit(self.height)
|
self.db.prefix_db.commit(self.height, self.tip)
|
||||||
else:
|
else:
|
||||||
self.db.prefix_db.unsafe_commit()
|
self.db.prefix_db.unsafe_commit()
|
||||||
self.clear_after_advance_or_reorg()
|
self.clear_after_advance_or_reorg()
|
||||||
|
@ -1559,7 +1559,7 @@ class BlockProcessor:
|
||||||
self.db.last_flush_tx_count = self.db.fs_tx_count
|
self.db.last_flush_tx_count = self.db.fs_tx_count
|
||||||
|
|
||||||
def rollback():
|
def rollback():
|
||||||
self.db.prefix_db.rollback(self.height + 1)
|
self.db.prefix_db.rollback(self.height + 1, reverted_block_hash)
|
||||||
self.db.es_sync_height = self.height
|
self.db.es_sync_height = self.height
|
||||||
self.db.write_db_state()
|
self.db.write_db_state()
|
||||||
self.db.prefix_db.unsafe_commit()
|
self.db.prefix_db.unsafe_commit()
|
||||||
|
|
|
@ -1104,24 +1104,28 @@ class RepostedPrefixRow(PrefixRow):
|
||||||
return cls.pack_key(reposted_claim_hash, tx_num, position), cls.pack_value(claim_hash)
|
return cls.pack_key(reposted_claim_hash, tx_num, position), cls.pack_value(claim_hash)
|
||||||
|
|
||||||
|
|
||||||
|
class UndoKey(NamedTuple):
|
||||||
|
height: int
|
||||||
|
block_hash: bytes
|
||||||
|
|
||||||
|
|
||||||
class UndoPrefixRow(PrefixRow):
|
class UndoPrefixRow(PrefixRow):
|
||||||
prefix = DB_PREFIXES.undo.value
|
prefix = DB_PREFIXES.undo.value
|
||||||
key_struct = struct.Struct(b'>Q')
|
key_struct = struct.Struct(b'>Q32s')
|
||||||
|
|
||||||
key_part_lambdas = [
|
key_part_lambdas = [
|
||||||
lambda: b'',
|
lambda: b'',
|
||||||
struct.Struct(b'>Q').pack
|
struct.Struct(b'>Q').pack,
|
||||||
|
struct.Struct(b'>Q32s').pack
|
||||||
]
|
]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pack_key(cls, height: int):
|
def pack_key(cls, height: int, block_hash: bytes):
|
||||||
return super().pack_key(height)
|
return super().pack_key(height, block_hash)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def unpack_key(cls, key: bytes) -> int:
|
def unpack_key(cls, key: bytes) -> UndoKey:
|
||||||
assert key[:1] == cls.prefix
|
return UndoKey(*super().unpack_key(key))
|
||||||
height, = cls.key_struct.unpack(key[1:])
|
|
||||||
return height
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pack_value(cls, undo_ops: bytes) -> bytes:
|
def pack_value(cls, undo_ops: bytes) -> bytes:
|
||||||
|
@ -1132,8 +1136,8 @@ class UndoPrefixRow(PrefixRow):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pack_item(cls, height: int, undo_ops: bytes):
|
def pack_item(cls, height: int, block_hash: bytes, undo_ops: bytes):
|
||||||
return cls.pack_key(height), cls.pack_value(undo_ops)
|
return cls.pack_key(height, block_hash), cls.pack_value(undo_ops)
|
||||||
|
|
||||||
|
|
||||||
class BlockHashPrefixRow(PrefixRow):
|
class BlockHashPrefixRow(PrefixRow):
|
||||||
|
|
Loading…
Reference in a new issue