Skip to content

Commit

Permalink
support replay by check_db
Browse files Browse the repository at this point in the history
  • Loading branch information
Qi Zhou committed Jan 22, 2025
1 parent 54fe99f commit 39eee0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
30 changes: 16 additions & 14 deletions quarkchain/cluster/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,9 @@ def log_error_and_exit(msg):

start_time = time.monotonic()
# Start with root db
rb = self.root_state.get_tip_block()
check_db_rblock_from = self.env.arguments.check_db_rblock_from
check_db_rblock_to = self.env.arguments.check_db_rblock_to
if check_db_rblock_from >= 0 and check_db_rblock_from < rb.header.height:
rb = self.root_state.get_root_block_by_height(check_db_rblock_from)
check_db_rblock_from = self.env.arguments.check_db_rblock_from # highest height
check_db_rblock_to = self.env.arguments.check_db_rblock_to # lowest height
rb = self.root_state.get_root_block_by_height(check_db_rblock_to)
Logger.info(
"Starting from root block height: {0}, batch size: {1}".format(
rb.header.height, self.env.arguments.check_db_rblock_batch
Expand All @@ -965,27 +963,31 @@ def log_error_and_exit(msg):
)
)
count = 0
while rb.header.height >= max(check_db_rblock_to, 1):
while rb.header.height <= check_db_rblock_from:
if count % 100 == 0:
Logger.info("Checking root block height: {}".format(rb.header.height))
rb_list = []
for i in range(self.env.arguments.check_db_rblock_batch):
count += 1
if rb.header.height < max(check_db_rblock_to, 1):
if rb.header.height > check_db_rblock_from:
break
rb_list.append(rb)
# Make sure the rblock matches the db one
prev_rb = self.root_state.db.get_root_block_by_hash(
rb.header.hash_prev_block
# Check the following invariants
# - next_rb.prev_hash == rb
# - can get next_rb by height
# - can get next_rb by hash

next_rb = self.root_state.db.get_root_block_by_height(
rb.header.height + 1
)
if prev_rb.header.get_hash() != rb.header.hash_prev_block:
if rb.header.get_hash() != next_rb.header.hash_prev_block:
log_error_and_exit(
"Root block height {} mismatches previous block hash".format(
rb.header.height
next_rb.header.height
)
)
rb = prev_rb
if self.root_state.get_root_block_by_height(rb.header.height) != rb:
rb = next_rb
if self.root_state.get_root_block_by_hash(rb.header.get_hash()) != rb:
log_error_and_exit(
"Root block height {} mismatches canonical chain".format(
rb.header.height
Expand Down
2 changes: 1 addition & 1 deletion quarkchain/tools/db_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def handle_root_print_tip(env, args):
def handle_root_set_tip(env, args):
root_state = RootState(env)
root_state.db.update_tip_hash(bytes.fromhex(args.hash))
print("root tip reset to: 0x{}". args.hash)
print("root tip reset to: 0x{}".format(args.hash))
return 0


Expand Down

0 comments on commit 39eee0d

Please sign in to comment.