Skip to content

Commit 0da637b

Browse files
committed
Bound CKB epoch advancement by consensus
1 parent a3c1c74 commit 0da637b

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎scripts/ckb_cellscript_acceptance.sh‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3740,10 +3740,17 @@ def get_block_by_number(number, attempts=20, delay_seconds=0.05):
37403740
def epoch_number_from_header(header):
37413741
return int(header["epoch"], 16) & ((1 << 24) - 1)
37423742
3743-
def wait_header_epoch_at_least(min_epoch, max_blocks=1200):
3744-
last_header = None
3743+
CKB_CONSENSUS_MAX_EPOCH_LENGTH = 1800
3744+
3745+
def wait_header_epoch_at_least(min_epoch, max_blocks=None):
3746+
last_header = rpc("get_tip_header")
3747+
initial_epoch = epoch_number_from_header(last_header)
3748+
if max_blocks is None:
3749+
remaining_epochs = max(0, min_epoch - initial_epoch)
3750+
max_blocks = (remaining_epochs + 1) * CKB_CONSENSUS_MAX_EPOCH_LENGTH
37453751
for generated in range(max_blocks + 1):
3746-
last_header = rpc("get_tip_header")
3752+
if generated > 0:
3753+
last_header = rpc("get_tip_header")
37473754
epoch_number = epoch_number_from_header(last_header)
37483755
if epoch_number >= min_epoch:
37493756
return {
@@ -6776,7 +6783,7 @@ def run_stateful_timelock_release(always_success_dep):
67766783
actions["request_release"]["cell_deps"],
67776784
)
67786785
request_input = request_initial["cells"][0]
6779-
release_timepoint = wait_header_epoch_at_least(unlock_height, max_blocks=15000)
6786+
release_timepoint = wait_header_epoch_at_least(unlock_height)
67806787
release_height = release_timepoint["epoch_number"]
67816788
tx3 = transaction(
67826789
request_input,

0 commit comments

Comments
 (0)