Skip to content

Commit cb3f9be

Browse files
committed
fix demo script
1 parent 92a12c2 commit cb3f9be

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

deployments/rollup-bsn-demo/demo.sh

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,78 @@ echo " → Verification result: $VERIFY_OUTPUT"
426426
echo " ✅ Public randomness committed successfully for $num_pub_rand blocks!"
427427

428428
echo ""
429-
echo "✍️ Step 7b: Generating and submitting finality signatures..."
429+
echo "⏳ Step 7b: Waiting for BTC timestamping..."
430+
echo " ℹ️ The finality contract requires public randomness commitments to be BTC-timestamped"
431+
echo " ℹ️ before accepting finality signatures. This ensures cryptographic security."
432+
433+
# Query the last public randomness commitment to get its babylon_epoch
434+
echo " → Querying last public randomness commitment..."
435+
query_msg=$(jq -n --arg btc_pk_hex "$fp_pubkey_hex" '{last_pub_rand_commit: {btc_pk_hex: $btc_pk_hex}}')
436+
LAST_COMMIT_OUTPUT=$(docker exec babylondnode0 /bin/sh -c "/bin/babylond --home /babylondhome q wasm contract-state smart $finalityContractAddr '$query_msg' --output json" 2>&1)
437+
if [ $? -ne 0 ]; then
438+
echo " ❌ Failed to query last public randomness commitment"
439+
echo " Error: $LAST_COMMIT_OUTPUT"
440+
exit 1
441+
fi
442+
echo " → Last commit query result: $LAST_COMMIT_OUTPUT"
443+
444+
# Extract the babylon_epoch from the commitment
445+
committed_epoch=$(echo "$LAST_COMMIT_OUTPUT" | jq -r '.data.babylon_epoch')
446+
if [ "$committed_epoch" = "null" ] || [ -z "$committed_epoch" ]; then
447+
echo " ❌ Failed to get committed epoch from contract"
448+
echo " Query output: $LAST_COMMIT_OUTPUT"
449+
exit 1
450+
fi
451+
452+
echo " → Committed randomness epoch: $committed_epoch"
453+
454+
# Wait for this epoch to be finalized by BTC timestamping
455+
echo " → Waiting for epoch $committed_epoch to be finalized by BTC timestamping..."
456+
echo " → This ensures the cryptographic security of finality signatures"
457+
max_wait_attempts=60 # Wait up to 10 minutes (60 * 10 seconds)
458+
wait_attempt=0
459+
460+
while [ $wait_attempt -lt $max_wait_attempts ]; do
461+
wait_attempt=$((wait_attempt + 1))
462+
463+
# Query Babylon's last finalized epoch using raw-checkpoint-list
464+
FINALIZED_EPOCH_OUTPUT=$(docker exec babylondnode0 /bin/sh -c "/bin/babylond --home /babylondhome q checkpointing raw-checkpoint-list CKPT_STATUS_FINALIZED --reverse --limit 1 --output json" 2>&1)
465+
if [ $? -ne 0 ]; then
466+
echo " → Attempt $wait_attempt/$max_wait_attempts: Failed to query finalized epoch, retrying..."
467+
echo " Error: $FINALIZED_EPOCH_OUTPUT"
468+
sleep 10
469+
continue
470+
fi
471+
472+
# Extract the epoch number from the most recent finalized checkpoint
473+
last_finalized_epoch=$(echo "$FINALIZED_EPOCH_OUTPUT" | jq -r '.raw_checkpoints[0].ckpt.epoch_num // 0')
474+
if [ "$last_finalized_epoch" = "null" ] || [ -z "$last_finalized_epoch" ]; then
475+
echo " → Attempt $wait_attempt/$max_wait_attempts: Failed to parse finalized epoch, retrying..."
476+
echo " Query output: $FINALIZED_EPOCH_OUTPUT"
477+
sleep 10
478+
continue
479+
fi
480+
481+
echo " → Attempt $wait_attempt/$max_wait_attempts: Committed epoch=$committed_epoch, Finalized epoch=$last_finalized_epoch"
482+
483+
# Check if the committed epoch is now finalized
484+
if [ "$last_finalized_epoch" -ge "$committed_epoch" ]; then
485+
echo " ✅ Epoch $committed_epoch has been finalized! (Last finalized: $last_finalized_epoch)"
486+
break
487+
fi
488+
489+
echo " → Waiting... (need epoch $committed_epoch to be finalized, currently $last_finalized_epoch)"
490+
sleep 10
491+
done
492+
493+
if [ "$last_finalized_epoch" -lt "$committed_epoch" ]; then
494+
echo " ⚠️ Warning: Epoch $committed_epoch not finalized after $((max_wait_attempts * 10)) seconds"
495+
echo " ⚠️ Committed epoch: $committed_epoch, Last finalized: $last_finalized_epoch"
496+
echo " ⚠️ Proceeding anyway - finality signatures may fail..."
497+
fi
498+
499+
echo ""
500+
echo "✍️ Step 7c: Generating and submitting finality signatures..."
430501

431502
# Step 7b: Generate and submit finality signatures for multiple blocks
432503
echo " → Processing $num_finality_sigs blocks using crypto-only approach..."

0 commit comments

Comments
 (0)