-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfund-settlements.yml
205 lines (189 loc) · 8.38 KB
/
fund-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
202
203
204
205
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/fund-settlements'
concurrency: 1
- wait: ~
- label: ":black_nib: Env variables setup: Fund Settlements"
commands:
- |
claim_type=${CLAIM_TYPE:-"$($(buildkite-agent meta-data get claim_type) || true)"}
if [[ -n "$$claim_type" ]]; then
buildkite-agent meta-data set claim_type "$$claim_type"
fi
- |
epoch=${EPOCH:-"$($(buildkite-agent meta-data get epoch) || true)"}
if [[ -n "$$epoch" ]]; then
buildkite-agent meta-data set epoch "$$epoch"
fi
- wait: ~
- label: ":hammer_and_wrench: :rust: Build fund-settlement"
commands:
- '. "$HOME/.cargo/env"'
- 'cargo build --release --bin fund-settlement'
artifact_paths:
- target/release/fund-settlement
- label: ":surfer: Loading JSON settlements data"
env:
past_epochs_to_load: 3
# epoch when the contract v2 was deployed, using different structure of merkle tree than v1
starting_epoch_contract_v2: 640
commands:
- claim_type=$(buildkite-agent meta-data get claim_type) || true
- epoch=$(buildkite-agent meta-data get epoch) || true
- |
if [[ -z "$$epoch" ]]; then
current_epoch=$(curl --silent "$$RPC_URL" -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getEpochInfo"}' | jq '.result.epoch')
epochs_start_index=$((current_epoch - past_epochs_to_load))
latest_funded_epoch=$((current_epoch - 1))
else
current_epoch=$$epoch
epochs_start_index=$$epoch
latest_funded_epoch=$$epoch
fi
- buildkite-agent meta-data set latest_funded_epoch "$$latest_funded_epoch"
- |
merkle_trees=$(buildkite-agent artifact search "merkle-trees/*" || echo "")
if [[ "x$$merkle_trees" != "x" && ! "$$merkle_trees" =~ 'fatal' ]]; then
echo "Merkle trees already downloaded"
exit 0
fi
- 'mkdir ./merkle-trees/'
- |
for epoch in $(seq $$epochs_start_index $$current_epoch); 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
if [[ -z "$$claim_type" ]]; then
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
else
target_dir="./merkle-trees/$${epoch}_$${claim_type}/"
mkdir -p "$$target_dir"
gcloud storage cp "$gs_bucket/$$epoch/$${claim_type}-settlement-merkle-trees.json" "$$target_dir"
gcloud storage cp "$gs_bucket/$$epoch/$${claim_type}-settlements.json" "$$target_dir"
fi
done
artifact_paths:
- "./merkle-trees/**/*"
- 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::arrow_right: Fund settlements"
env:
RUST_LOG: info,solana_transaction_builder_executor=debug,solana_transaction_builder=debug,solana_transaction_executor=debug,fund_settlement=debug
commands:
- . "$HOME/.cargo/env"
- prior_build_number=$(($$BUILDKITE_RETRY_COUNT - 1))
- command_name='fund-settlement'
- buildkite-agent artifact download --include-retried-jobs execution-report.$$command_name.$$prior_build_number . || true
- |
cp "execution-report.$$command_name.$$prior_build_number" "execution-report.$$command_name.$$BUILDKITE_RETRY_COUNT" || true
rm -f "fund-execution-report.$$command_name.$$prior_build_number"
echo "#ATTEMPT FUND SETTLEMENT $$BUILDKITE_RETRY_COUNT" | tee -a "./execution-report.$$command_name.$$BUILDKITE_RETRY_COUNT"
- |
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
- buildkite-agent artifact download --include-retried-jobs target/release/fund-settlement .
- chmod +x target/release/fund-settlement
- source ./scripts/execute-handlers.sh
- |
handle_command_execution "$$command_name" \
./target/release/fund-settlement \
--rpc-url $$RPC_URL \
--operator-authority "$$VALIDATOR_BONDS_OPERATOR_AUTHORITY" \
--fee-payer "$$PSR_TX_FEE_WALLET" \
--marinade-wallet "$$PSR_MARINADE_DAO_FUNDER_WALLET" \
--rent-payer "$$PSR_RENT_PAYER_WALLET" \
$$files
key: 'fund-settlement'
artifact_paths:
- "./execution-report.*"
retry:
automatic:
- exit_status: 100
limit: 5
- label: ":memo: Notification setup: Fund Settlements"
commands:
- mkdir ./reports
- command_name='fund-settlement'
- buildkite-agent artifact download --include-retried-jobs "execution-report.$$command_name.*" ./reports/ || echo "No report ERROR" > ./reports/execution-report.$$command_name.error
- report_path="./reports/$(ls -v1 reports/ | tail -n 1)"
- cp "$$report_path" ./fund-report.txt
- buildkite-agent meta-data set attempts_count "$(grep -c ATTEMPT ./fund-report.txt)"
artifact_paths:
- "./fund-report.txt"
key: 'notification-setup-funding'
depends_on: "fund-settlement"
allow_dependency_failure: true
- wait: ~
- label: ":floppy_disk: :arrow_right: :cloud: Upload artifacts Fund Settlements"
commands:
- latest_funded_epoch=$(buildkite-agent meta-data get latest_funded_epoch) || true
- claim_type=$(buildkite-agent meta-data get claim_type) || true
- claim_type_prefix=$([[ -z "$$claim_type" ]] && echo "" || echo "$${claim_type}-")
- buildkite-agent artifact download --include-retried-jobs fund-report.txt . || echo "UNKNOWN ERROR" > fund-report.txt
- |
if [[ -n "$$latest_funded_epoch" && $(gcloud storage ls "$gs_bucket/$$latest_funded_epoch" 2> /dev/null) ]]; then
gcloud storage cp ./fund-report.txt "$gs_bucket/$$latest_funded_epoch/buildkite/$${claim_type_prefix}fund-settlement-report.$(date +%s).txt"
fi
depends_on: "notification-setup-funding"
allow_dependency_failure: true
- label: ":mega: Notification Funding"
commands:
- source ./scripts/execute-handlers.sh
- check_command_execution_status "fund-settlement" || true
- |
attempts_count=$(buildkite-agent meta-data get attempts_count || echo "UNKNOWN")
claim_type=$(buildkite-agent meta-data get claim_type) || true
if [[ -n "$$claim_type" ]]; then
claim_type=" [$$claim_type]"
fi
buildkite-agent artifact download --include-retried-jobs fund-report.txt . || echo 'UNKNOWN ERROR' > './fund-report.txt'
curl "$(buildkite-agent meta-data get discord_webhook)" \
-F 'payload_json={
"embeds":[{
"title": "Fund Settlements '"$${notification_result}$${claim_type}"', '"$$attempts_count"' attempts",
"url": "'"$$BUILDKITE_BUILD_URL"'",
"color": "'"$$notification_color"'"
}]
}' \
-F "file1=@./fund-report.txt"
depends_on: "notification-setup-funding"
allow_dependency_failure: true
- wait: ~
- label: ":unlock: Concurrency gate unlock"
command: echo "End of concurrency gate <--"
concurrency_group: 'validator-bonds/fund-settlements'
concurrency: 1