-
Notifications
You must be signed in to change notification settings - Fork 1
91 lines (89 loc) · 3.51 KB
/
regtest-mine.yml
File metadata and controls
91 lines (89 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Regtest Mine Blocks
on:
schedule:
- cron: '0 2 * * *' # 2 AM UTC daily
workflow_dispatch:
inputs:
blocktank_server:
description: Blocktank base URL
required: true
default: 'https://api.stag0.blocktank.to/blocktank/api/v2'
mempool_server:
description: Mempool API base URL
required: true
default: 'https://mempool.bitkit.stag0.blocktank.to'
block_count:
description: Number of regtest blocks to mine
required: true
default: '1'
jobs:
mine:
runs-on: ubuntu-latest
env:
BLOCK_COUNT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.block_count || '1' }}
BLOCKTANK_SERVER: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.blocktank_server || 'https://api.stag0.blocktank.to/blocktank/api/v2' }}
MEMPOOL_SERVER: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.mempool_server || 'https://mempool.bitkit.stag0.blocktank.to' }}
steps:
- name: Validate params
run: |
if [[ -z "${BLOCK_COUNT}" ]]; then
echo "BLOCK_COUNT is empty" >&2
exit 1
fi
if ! [[ "${BLOCK_COUNT}" =~ ^[0-9]+$ ]]; then
echo "BLOCK_COUNT must be a positive integer: ${BLOCK_COUNT}" >&2
exit 1
fi
if [[ "${BLOCK_COUNT}" -eq 0 ]]; then
echo "BLOCK_COUNT must be greater than zero" >&2
exit 1
fi
if [[ -z "${BLOCKTANK_SERVER}" ]]; then
echo "BLOCKTANK_SERVER is empty" >&2
exit 1
fi
if [[ -z "${MEMPOOL_SERVER}" ]]; then
echo "MEMPOOL_SERVER is empty" >&2
exit 1
fi
- name: Capture initial tip height
run: |
MEMPOOL_API="${MEMPOOL_SERVER%/}/api/blocks/tip/height"
TIP_BEFORE=$(curl -sSf "${MEMPOOL_API}")
if [[ -z "${TIP_BEFORE}" ]] || ! [[ "${TIP_BEFORE}" =~ ^[0-9]+$ ]]; then
echo "Failed to obtain initial block height (got: ${TIP_BEFORE})" >&2
exit 1
fi
echo "Initial tip height: ${TIP_BEFORE}"
echo "TIP_BEFORE=${TIP_BEFORE}" >> "${GITHUB_ENV}"
- name: Mine regtest blocks
run: |
echo "Mining ${BLOCK_COUNT} block(s) on regtest..."
curl --fail --silent --show-error \
-X POST \
"${BLOCKTANK_SERVER}/regtest/chain/mine" \
-H 'Content-Type: application/json' \
-d "{\"count\": ${BLOCK_COUNT}}"
- name: Verify new tip height
run: |
MEMPOOL_API="${MEMPOOL_SERVER%/}/api/blocks/tip/height"
EXPECTED=$((TIP_BEFORE + BLOCK_COUNT))
echo "Waiting up to 10 seconds for tip height to reach ${EXPECTED}..."
END=$((SECONDS + 10))
LAST_TIP=""
while (( SECONDS < END )); do
TIP_AFTER=$(curl -sSf "${MEMPOOL_API}" 2>/dev/null)
if [[ "${TIP_AFTER}" =~ ^[0-9]+$ ]]; then
LAST_TIP="${TIP_AFTER}"
if (( TIP_AFTER >= EXPECTED )); then
echo "New tip height: ${TIP_AFTER}"
echo "Regtest height increased as expected"
exit 0
fi
else
echo "Failed to read tip height (got: ${TIP_AFTER:-empty}), retrying..."
fi
sleep 1
done
echo "Tip height did not reach expected value ${EXPECTED} (started at ${TIP_BEFORE}) within 10 seconds (last observed: ${LAST_TIP:-unknown})" >&2
exit 1