-
Notifications
You must be signed in to change notification settings - Fork 3
/
claim-settlements.yml
201 lines (182 loc) · 8.58 KB
/
claim-settlements.yml
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
agents:
queue: "snapshots"
env:
gs_bucket: gs://marinade-validator-bonds-mainnet
steps:
- label: ":closed_lock_with_key: Concurrency gate lock"
command: echo "--> Start of concurrency gate"
concurrency_group: 'validator-bonds/claim-settlements'
concurrency: 1
- wait: ~
- label: ":hammer_and_wrench: :rust: Build claim-settlement"
commands:
- '. "$HOME/.cargo/env"'
- 'cargo build --release --bin list-claimable-epoch'
- 'cargo build --release --bin claim-settlement'
artifact_paths:
- target/release/list-claimable-epoch
- target/release/claim-settlement
- label: ":black_nib: Find Discord webhook"
commands:
- |
discord_webhook=$(buildkite-agent meta-data get discord_webhook) || true
if [[ -z "$$discord_webhook" ]]; then
# env defined by job definition
discord_webhook="${DISCORD_WEBHOOK}"
fi
if [[ -z "$$discord_webhook" ]]; then
# env defined by buildkite environment
discord_webhook="$${DISCORD_WEBHOOK_VALIDATOR_BONDS}"
fi
buildkite-agent meta-data set discord_webhook "$$discord_webhook"
- wait: ~
- label: ":campfire: List claimable epochs"
env:
RUST_LOG: info,solana_transaction_builder_executor=debug,solana_transaction_builder=debug,builder_executor=debug,solana_transaction_executor=debug,settlement_pipelines=debug,list_claimable_epoch=debug
commands:
- '. "$HOME/.cargo/env"'
- 'buildkite-agent artifact download --include-retried-jobs target/release/list-claimable-epoch .'
- 'chmod +x target/release/list-claimable-epoch'
- 'possible_epochs_json=$(./target/release/list-claimable-epoch --rpc-url $$RPC_URL)'
- 'buildkite-agent meta-data set possible_epochs_json "$$possible_epochs_json"'
- wait: ~
- label: ":floppy_disk: :arrow_left: :cloud: Downloading all epochs merkle trees"
env:
# epoch when the contract v2 was deployed, using different structure of merkle tree than v1
starting_epoch_contract_v2: 640
commands:
- 'mkdir ./merkle-trees/'
- 'possible_epochs_json=$(buildkite-agent meta-data get possible_epochs_json)'
- 'possible_epochs_num=$(echo "$$possible_epochs_json" | jq "length")'
- 'echo "Possible claimable epochs [$$possible_epochs_num]: $$possible_epochs_json"'
- 'claimable_epochs_num=0'
- 'claimable_epochs_json=()'
- |
for epoch in $(echo "$$possible_epochs_json" | jq ".[]"); do
if [[ $$epoch -lt $$starting_epoch_contract_v2 ]]; then
echo "Skipping epoch $$epoch, because it's before the contract v2 deployment epoch $$starting_epoch_contract_v2"
continue
fi
claimable_epochs_num=$(($$claimable_epochs_num + 1))
claimable_epochs_json+=($$epoch)
for merkle_tree_file in $(gcloud storage ls "$gs_bucket/$$epoch/*settlement-merkle-trees.json"); do
base_name=$(basename "$$merkle_tree_file")
prefix_name="$${base_name%settlement-merkle-trees.json}"
target_dir="./merkle-trees/$${epoch}_$${prefix_name%%-*}/"
mkdir -p "$$target_dir"
gcloud storage cp "$gs_bucket/$$epoch/$${prefix_name}settlement-merkle-trees.json" "$$target_dir"
gcloud storage cp "$gs_bucket/$$epoch/$${prefix_name}settlements.json" "$$target_dir"
done
done
claimable_epochs_json=$(jq --compact-output --null-input '$ARGS.positional' --args -- "$${claimable_epochs_json[@]}")
- 'buildkite-agent meta-data set claimable_epochs_json "$$claimable_epochs_json"'
- 'buildkite-agent meta-data set claimable_epochs_num "$$claimable_epochs_num"'
- 'echo "Claimable epochs [$$claimable_epochs_num]: $$claimable_epochs_json"'
artifact_paths:
- "./merkle-trees/**/*"
- wait: ~
# We need to wait for the fund-settlements trigger to get finished before we can proceed
- label: ":gear: Upload and trigger fund-settlements pipeline"
commands:
- 'buildkite-agent pipeline upload .buildkite/fund-settlements.yml'
- wait: ~
continue_on_failure: true
- label: ":campfire::arrow_right: Claim settlements"
env:
RUST_LOG: info,solana_transaction_builder_executor=debug,solana_transaction_builder=debug,builder_executor=debug,solana_transaction_executor=debug,settlement_pipelines=debug,claim_settlement=debug
# RUST_BACKTRACE: full
commands:
- '. "$HOME/.cargo/env"'
- |
claimable_epochs_num=$(buildkite-agent meta-data get claimable_epochs_num || echo "0")
if [[ $$claimable_epochs_num -eq 0 ]]; then
echo 'No claimable settlement to claim from' | tee ./claiming-report.txt
exit 0
fi
- 'prior_build_number=$(($$BUILDKITE_RETRY_COUNT - 1))'
- 'buildkite-agent artifact download --include-retried-jobs execution-report.$$prior_build_number . || true'
- |
cp "execution-report.$$prior_build_number" "execution-report.$$BUILDKITE_RETRY_COUNT" || true
rm -f "execution-report.$$prior_build_number"
echo "#ATTEMPT CLAIM SETTLEMENTS $$BUILDKITE_RETRY_COUNT" | tee -a "./execution-report.$$BUILDKITE_RETRY_COUNT"
- 'buildkite-agent artifact download --include-retried-jobs target/release/claim-settlement .'
- 'chmod +x target/release/claim-settlement'
- |
buildkite-agent artifact download --include-retried-jobs "merkle-trees/*" .
files=""
for dir in ./merkle-trees/*; do
if [ -d "$$dir" ]; then
pair_files=""
for file in "$$dir"/*; do
pair_files="$$pair_files $$file"
done
files="$$files -f $$pair_files"
fi
done
- source ./scripts/execute-handlers.sh
- |
handle_command_execution "claim-settlement" \
./target/release/claim-settlement \
--rpc-url $$RPC_URL \
--operator-authority "$$VALIDATOR_BONDS_OPERATOR_AUTHORITY" \
--fee-payer "$$PSR_TX_FEE_WALLET" \
$$files
key: 'claim-settlement'
artifact_paths:
- "./execution-report.*"
retry:
automatic:
- exit_status: 100
limit: 5
- label: ":memo: Notification setup: Claim Settlements"
commands:
- 'mkdir ./reports'
- 'buildkite-agent artifact download --include-retried-jobs "execution-report.*" ./reports/ || echo "No report ERROR" > ./reports/execution-report.error'
- 'report_path="./reports/$(ls -v1 reports/ | tail -n 1)"'
- 'cp "$$report_path" ./claiming-report.txt'
- 'buildkite-agent meta-data set attempts_count "$(grep -c ATTEMPT ./claiming-report.txt)"'
artifact_paths:
- "./claiming-report.txt"
key: 'notification-setup-claim'
depends_on: "claim-settlement"
allow_dependency_failure: true
- wait: ~
- label: ":floppy_disk: :arrow_right: :cloud: Upload artifacts Claim Settlements"
commands:
- buildkite-agent artifact download --include-retried-jobs claiming-report.txt . || echo "UNKNOWN ERROR" > claiming-report.txt
- claimable_epochs_json=$(buildkite-agent meta-data get claimable_epochs_json)
- first_epoch=$(echo "$$claimable_epochs_json" | jq ".[0]")
- |
if [[ -n "$$first_epoch" && "$$first_epoch" != "null" && $(gcloud storage ls "$gs_bucket/$$first_epoch" 2> /dev/null) ]]; then
gcloud storage cp ./claiming-report.txt "$gs_bucket/$$first_epoch/buildkite/claiming-report.$(date +%s).txt"
fi
depends_on: "notification"
allow_dependency_failure: true
- label: ":mega: Notification Claiming"
commands:
- source ./scripts/execute-handlers.sh
- check_command_execution_status "claim-settlement" || true
- attempts_count=$(buildkite-agent meta-data get attempts_count || echo "UNKNOWN")
- buildkite-agent artifact download --include-retried-jobs claiming-report.txt . || echo "UNKNOWN ERROR" > claiming-report.txt
- |
claimable_epochs_json=$(buildkite-agent meta-data get claimable_epochs_json || echo "[]")
claimable_epochs=$(echo "$$claimable_epochs_json" | jq ". | join(\",\")" | tr -d '"')
- |
curl "$(buildkite-agent meta-data get discord_webhook)" \
-F 'payload_json={
"embeds":[{
"title": "Claim Settlements '"$$notification_result"' for epochs: '"$$claimable_epochs"' after '"$$attempts_count"' attempts",
"url": "'"$$BUILDKITE_BUILD_URL"'",
"color": "'"$$notification_color"'"
}]
}' \
-F "file1=@./claiming-report.txt"
- |
build_result=$(buildkite-agent step get "outcome" --step "claim-settlement")
depends_on: "notification-setup-claim"
allow_dependency_failure: true
- wait: ~
- label: ":unlock: Concurrency gate unlock"
command: echo "End of concurrency gate <--"
concurrency_group: 'validator-bonds/claim-settlements'
concurrency: 1