-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprepare-bid-psr-distribution.yml
209 lines (185 loc) · 8.61 KB
/
prepare-bid-psr-distribution.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
206
207
208
209
agents:
queue: "snapshots"
env:
gs_bucket: gs://marinade-validator-bonds-mainnet
CLAIM_TYPE: "bid-psr-distribution"
ds_sam_auction_github_api_link: "https://api.github.com/repos/marinade-finance/ds-sam-pipeline/contents/auctions/"
ds_sam_auction_download_link: "https://raw.githubusercontent.com/marinade-finance/ds-sam-pipeline/main/auctions/"
steps:
- label: ":hammer_and_wrench: :rust: Build"
commands:
- '. "$HOME/.cargo/env"'
- 'cargo build --release --bin bid-psr-distribution-cli'
artifact_paths:
- target/release/bid-psr-distribution-cli
- input: "What is the epoch to generate settlements for?"
fields:
- text: "Epoch"
key: "epoch"
format: "[0-9]+"
if: "build.env('EPOCH') == null"
- command: "echo 'Epoch is: $EPOCH'"
if: "build.env('EPOCH') != null"
- wait: ~
- label: ":closed_lock_with_key: Concurrency gate lock"
command: echo "--> Start of concurrency gate"
concurrency_group: 'validator-bonds/prepare-bid-psr-distribution'
concurrency: 1
- wait: ~
- label: ":black_nib: Env variables setup: Bid PSR Distribution"
commands:
- |
epoch=${EPOCH:-$(buildkite-agent meta-data get epoch)}
buildkite-agent meta-data set epoch "$$epoch"
- |
discord_webhook="${DISCORD_WEBHOOK:-$$DISCORD_WEBHOOK_VALIDATOR_BONDS}"
buildkite-agent meta-data set discord_webhook "$$discord_webhook"
- wait: ~
- label: ":cloud: :arrow_right: :floppy_disk: Downloading Settlements JSON data"
commands:
- epoch=$(buildkite-agent meta-data get epoch)
- |
gcloud storage cp "$gs_bucket/$$epoch/validators.json" "."
gcloud storage cp "$gs_bucket/$$epoch/stakes.json" "."
gcloud storage cp "$gs_bucket/$$epoch/past-validators.json" "." || echo "Previous validator data not available!"
artifact_paths:
- "./*.json"
- label: ":cloud: :arrow_right: :floppy_disk: Downloading DS SAM auction data"
commands:
- epoch=$(buildkite-agent meta-data get epoch)
# checking auction directory to work with
- |
epoch_auction_dirs=$(./scripts/gh_curl.bash "$$ds_sam_auction_github_api_link" |\
jq -r '.[] | .name' | grep "$${epoch}\.")
# epoch_auction_dirs list of dirs in format '<epoch>.<slot>', for example '653.12308'
epoch_auction_dir=$(echo "$$epoch_auction_dirs" | sort -t. -k2 -n -r | head -n 1)
if [[ -z "$$epoch_auction_dir" ]]; then
echo "No auction data found for epoch $$epoch, directory listing: $$auction_dirs"
exit 1
fi
# listing input and output files
- |
ds_sam_input_listing_link="$${ds_sam_auction_github_api_link}$${epoch_auction_dir}/inputs/"
input_dir_files=$(./scripts/gh_curl.bash "$$ds_sam_input_listing_link" |\
jq -r '.[] | .name')
ds_sam_output_listing_link="$${ds_sam_auction_github_api_link}$${epoch_auction_dir}/outputs/"
output_dir_files=$(./scripts/gh_curl.bash "$$ds_sam_output_listing_link" |\
jq -r '.[] | .name' | grep '.json')
# downloading files
- |
mkdir -p ./inputs
for file in $$input_dir_files; do
curl -O --output-dir './inputs' "$${ds_sam_auction_download_link}$${epoch_auction_dir}/inputs/$${file}"
done
mkdir -p ./outputs
for file in $$output_dir_files; do
curl -O --output-dir './outputs' "$${ds_sam_auction_download_link}$${epoch_auction_dir}/outputs/$${file}"
done
artifact_paths:
- "./inputs/*"
- "./outputs/*"
- wait: ~
- label: ":campfire: DS SAM generates PMPE bids data"
commands:
- 'buildkite-agent artifact download --include-retried-jobs validators.json .'
- 'buildkite-agent artifact download --include-retried-jobs past-validators.json . || echo "Previous validator data not available"'
- 'buildkite-agent artifact download --include-retried-jobs inputs/* .'
- 'buildkite-agent artifact download --include-retried-jobs outputs/* .'
- '[[ ! -f "./outputs/results.json" ]] && echo "results.json not found" && exit 2'
- 'past_validators_arg=$( [[ -f ./past-validators.json ]] && echo "--snapshot-past-validators-file-path ../past-validators.json" || echo "" )'
- 'git clone [email protected]:marinade-finance/ds-sam.git'
- |
cd ds-sam
git status
pnpm install
pnpm -r build
- |
pnpm run cli -- analyze-revenues \
$$past_validators_arg \
--cache-dir-path "../inputs" \
--sam-results-fixture-file-path "../outputs/results.json" \
--snapshot-validators-file-path "../validators.json" \
--results-file-path "../evaluation.json"
artifact_paths:
- "./evaluation.json"
- wait: ~
- label: ":scales: Evaluate Marinade Bid PSR Distribution"
env:
RUST_LOG: info,bid_psr_distribution=debug
WHITELIST_STAKE_AUTHORITY: stWirqFCf2Uts1JBL1Jsd3r6VBWhgnpdPxCTe1MFjrq,4bZ6o3eUUNXhKuqjdCnCoPAoLgWiuLYixKaxoa8PpiKk,ex9CfkBZZd6Nv9XdnoDmmB45ymbu4arXVk7g5pWnt3N
commands:
- 'buildkite-agent artifact download --include-retried-jobs validators.json .'
- 'buildkite-agent artifact download --include-retried-jobs stakes.json .'
- 'buildkite-agent artifact download --include-retried-jobs evaluation.json .'
- 'buildkite-agent artifact download --include-retried-jobs target/release/bid-psr-distribution-cli .'
- 'chmod +x target/release/bid-psr-distribution-cli'
- |
./target/release/bid-psr-distribution-cli \
--settlement-config settlement-config.yaml \
--validator-meta-collection "./validators.json" \
--stake-meta-collection "./stakes.json" \
--revenue-expectation-collection "./evaluation.json" \
--output-protected-event-collection "./${CLAIM_TYPE}.json" \
--output-settlement-collection "./${CLAIM_TYPE}-settlements.json" \
--output-merkle-tree-collection "./${CLAIM_TYPE}-settlement-merkle-trees.json"
artifact_paths:
- "./${CLAIM_TYPE}*.json"
- wait: ~
- label: "📓 Generating report"
commands:
- 'buildkite-agent artifact download --include-retried-jobs ${CLAIM_TYPE}-settlements.json .'
- './scripts/generate-discord-public-report.bash "./${CLAIM_TYPE}-settlements.json" "Protected Events" > "./discord-public-report.txt"'
artifact_paths:
- "./discord-public-report.txt"
- wait: ~
- label: ":floppy_disk: :arrow_right: :cloud: Upload artifacts Prepare Bid PSR Distribution"
commands:
- epoch=$(buildkite-agent meta-data get epoch)
- buildkite-agent artifact download --include-retried-jobs ${CLAIM_TYPE}.json .
- buildkite-agent artifact download --include-retried-jobs ${CLAIM_TYPE}-settlements.json .
- buildkite-agent artifact download --include-retried-jobs ${CLAIM_TYPE}-settlement-merkle-trees.json .
- buildkite-agent artifact download --include-retried-jobs discord-public-report.txt .
- buildkite-agent artifact download --include-retried-jobs evaluation.json .
- gcloud storage cp "./${CLAIM_TYPE}.json" "$gs_bucket/$$epoch/"
- gcloud storage cp "./${CLAIM_TYPE}-settlements.json" "$gs_bucket/$$epoch/"
- gcloud storage cp "./${CLAIM_TYPE}-settlement-merkle-trees.json" "$gs_bucket/$$epoch/"
- gcloud storage cp "./discord-public-report.txt" "$gs_bucket/$$epoch/${CLAIM_TYPE}-discord-public-report.txt"
- gcloud storage cp "./evaluation.json" "$gs_bucket/$$epoch/${CLAIM_TYPE}-evaluation.json"
- wait: ~
- label: ":mega: Notification"
commands:
- |
epoch=$(buildkite-agent meta-data get epoch)
curl "$(buildkite-agent meta-data get discord_webhook)" -H "Content-Type: application/json" -d '{
"embeds": [
{
"title": "Claims for Validator Bonds ('"${CLAIM_TYPE}"') generated ('"$$epoch"').",
"url": "'"$$BUILDKITE_BUILD_URL"'",
"color": "52224"
}
]
}'
- wait: ~
- label: ":gear: Setup init-settlements trigger"
commands:
- epoch=$(buildkite-agent meta-data get epoch)
- |
cat <<EOF | buildkite-agent pipeline upload
steps:
- trigger: "init-settlements"
label: ":rocket: Trigger: Init settlements ($$epoch)/($CLAIM_TYPE)"
async: true
build:
branch: $$BUILDKITE_BRANCH
env:
EPOCH: $$epoch
CLAIM_TYPE: $CLAIM_TYPE
DISCORD_WEBHOOK: $(buildkite-agent meta-data get discord_webhook)
NOTIFY_PSR_FEED: true
gs_bucket: $gs_bucket
EOF
- wait: ~
- label: ":unlock: Concurrency gate unlock"
command: echo "End of concurrency gate <--"
concurrency_group: 'validator-bonds/prepare-bid-psr-distribution'
concurrency: 1