Skip to content

Commit

Permalink
[pipelines] making fund settlement a separate action
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaloup committed Jul 2, 2024
1 parent a692eb0 commit 53faff2
Show file tree
Hide file tree
Showing 12 changed files with 1,040 additions and 779 deletions.
45 changes: 28 additions & 17 deletions .buildkite/claim-settlements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ agents:
queue: "snapshots"

steps:
- command: echo "--> Start of concurrency gate"
- 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"
- label: ":hammer_and_wrench: :rust: Build claim-settlement"
commands:
- '. "$HOME/.cargo/env"'
- 'cargo build --release --bin list-claimable-epoch'
Expand Down Expand Up @@ -55,7 +56,15 @@ steps:

- wait: ~

- label: ":campfire: Claim settlements"
# 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
Expand All @@ -68,11 +77,11 @@ steps:
exit 0
fi
- 'prior_build_number=$(($$BUILDKITE_RETRY_COUNT - 1))'
- 'buildkite-agent artifact download --include-retried-jobs build-report.$$prior_build_number . || true'
- 'buildkite-agent artifact download --include-retried-jobs claim-execution-report.$$prior_build_number . || true'
- |
cp "build-report.$$prior_build_number" "build-report.$$BUILDKITE_RETRY_COUNT" || true
rm -f "build-report.$$prior_build_number"
echo "#ATTEMPT $$BUILDKITE_RETRY_COUNT" | tee -a "./build-report.$$BUILDKITE_RETRY_COUNT"
cp "claim-execution-report.$$prior_build_number" "claim-execution-report.$$BUILDKITE_RETRY_COUNT" || true
rm -f "claim-execution-report.$$prior_build_number"
echo "#ATTEMPT $$BUILDKITE_RETRY_COUNT" | tee -a "./claim-execution-report.$$BUILDKITE_RETRY_COUNT"
- 'buildkite-agent artifact download --include-retried-jobs "merkle-trees/*" .'
- 'buildkite-agent artifact download --include-retried-jobs target/release/claim-settlement .'
- 'chmod +x target/release/claim-settlement'
Expand All @@ -84,16 +93,16 @@ steps:
--operator-authority "$$VALIDATOR_BONDS_OPERATOR_AUTHORITY" \
--fee-payer "$$VALIDATOR_BONDS_CLAIMING_WALLET" \
--rent-payer "$$VALIDATOR_BONDS_CLAIMING_WALLET" \
| tee -a "./build-report.$$BUILDKITE_RETRY_COUNT"
| tee -a "./claim-execution-report.$$BUILDKITE_RETRY_COUNT"
key: 'claim-settlement'
artifact_paths:
- "./build-report.*"
- "./claim-execution-report.*"
retry:
automatic:
- exit_status: 100
limit: 5

- label: "Notification setup"
- label: ":memo: Notification setup: Claim Settlements"
env:
gs_bucket: gs://marinade-validator-bonds-mainnet
commands:
Expand All @@ -110,7 +119,7 @@ steps:
- 'buildkite-agent meta-data set notification_result "$$notification_result"'
- 'echo "Notification result: $$notification_result, color: $$notification_color"'
- 'mkdir ./reports'
- 'buildkite-agent artifact download --include-retried-jobs "build-report.*" ./reports/ || echo "No report ERROR" > ./reports/build-report.error'
- 'buildkite-agent artifact download --include-retried-jobs "claim-execution-report.*" ./reports/ || echo "No report ERROR" > ./reports/claim-execution-report.error'
- 'report_path="./reports/$(ls -v1 reports/ | tail -n 1)"'
- 'cp "$$report_path" ./claiming-report.txt'
- 'claimable_epochs_json=$(buildkite-agent meta-data get claimable_epochs_json)'
Expand All @@ -119,13 +128,13 @@ steps:
- 'buildkite-agent meta-data set attempts_count "$(grep -c ATTEMPT ./claiming-report.txt)"'
artifact_paths:
- "./claiming-report.txt"
key: 'notification'
key: 'notification-setup-claim'
depends_on: "claim-settlement"
allow_dependency_failure: true

- wait: ~

- label: ":mega: Notification settlements claiming"
- label: ":mega: Notification Claiming"
commands:
- 'notification_result=$(buildkite-agent meta-data get notification_result || echo "UNKNOWN")'
- 'notification_color=$(buildkite-agent meta-data get notification_color || echo "15158332")'
Expand All @@ -134,7 +143,8 @@ steps:
- 'claimable_epochs_json=$(buildkite-agent meta-data get claimable_epochs_json)'
- |
claimable_epochs=$(echo "$$claimable_epochs_json" | jq ". | join(\",\")" | tr -d '"')
curl "$$DISCORD_WEBHOOK_VALIDATOR_BONDS" \
# curl "$$DISCORD_WEBHOOK_VALIDATOR_BONDS" \
curl https://discord.com/api/webhooks/1237762124114296923/O-Gv1aBiB4LZy87ppR-87LPVDCBz7591Kcse52GyRUmrU-Y8IVpAjnSuP-ZwpGDLLb88 \
-F 'payload_json={
"embeds":[{
"title": "Claim Settlements '"$$notification_result"' for epochs: '"$$claimable_epochs"' after '"$$attempts_count"' attempts",
Expand All @@ -145,11 +155,12 @@ steps:
-F "file1=@./claiming-report.txt"
- |
build_result=$(buildkite-agent step get "outcome" --step "claim-settlement")
depends_on: "notification"
depends_on: "notification-setup-claim"
allow_dependency_failure: true

- wait: ~

- command: echo "End of concurrency gate <--"
- label: ":unlock: Concurrency gate unlock"
command: echo "End of concurrency gate <--"
concurrency_group: 'validator-bonds/claim-settlements'
concurrency: 1
24 changes: 13 additions & 11 deletions .buildkite/close-settlements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ agents:
queue: "snapshots"

steps:
- command: echo "--> Start of concurrency gate"
- label: ":closed_lock_with_key: Concurrency gate lock"
command: echo "--> Start of concurrency gate"
concurrency_group: 'validator-bonds/close-settlements'
concurrency: 1

Expand Down Expand Up @@ -58,18 +59,18 @@ steps:

- wait: ~

- label: ":campfire: Close settlements"
- label: ":campfire::arrow_right: Close settlements"
env:
RUST_LOG: info,solana_transaction_builder_executor=debug,solana_transaction_builder=debug,solana_transaction_executor=debug,close_settlement=debug
# RUST_BACKTRACE: full
commands:
- '. "$HOME/.cargo/env"'
- 'prior_build_number=$(($$BUILDKITE_RETRY_COUNT - 1))'
- 'buildkite-agent artifact download --include-retried-jobs build-report.$$prior_build_number . || true'
- 'buildkite-agent artifact download --include-retried-jobs close-execution-report.$$prior_build_number . || true'
- |
cp "build-report.$$prior_build_number" "build-report.$$BUILDKITE_RETRY_COUNT" || true
rm -f "build-report.$$prior_build_number"
echo "#ATTEMPT $$BUILDKITE_RETRY_COUNT" | tee -a "./build-report.$$BUILDKITE_RETRY_COUNT"
cp "close-execution-report.$$prior_build_number" "close-execution-report.$$BUILDKITE_RETRY_COUNT" || true
rm -f "close-execution-report.$$prior_build_number"
echo "#ATTEMPT $$BUILDKITE_RETRY_COUNT" | tee -a "./close-execution-report.$$BUILDKITE_RETRY_COUNT"
- 'buildkite-agent artifact download --include-retried-jobs target/release/close-settlement .'
- 'buildkite-agent artifact download --include-retried-jobs past-settlements.json .'
- 'chmod +x target/release/close-settlement'
Expand All @@ -80,21 +81,21 @@ steps:
--operator-authority "$$VALIDATOR_BONDS_OPERATOR_AUTHORITY" \
--fee-payer "$$VALIDATOR_BONDS_SETTLEMENTS_WALLET" \
--marinade-wallet "$$VALIDATOR_BONDS_FUNDING_WALLET" \
--past-settlements ./past-settlements.json | tee -a "./build-report.$$BUILDKITE_RETRY_COUNT"
--past-settlements ./past-settlements.json | tee -a "./close-execution-report.$$BUILDKITE_RETRY_COUNT"
key: 'close-settlement'
artifact_paths:
- "./build-report.*"
- "./close-execution-report.*"
retry:
automatic:
- exit_status: 100
limit: 5

- label: "Notification setup"
- label: ":memo: Notification setup: Close Settlements"
env:
gs_bucket: gs://marinade-validator-bonds-mainnet
commands:
- 'mkdir ./reports'
- 'buildkite-agent artifact download --include-retried-jobs "build-report.*" ./reports/ || echo "No report ERROR" > ./reports/build-report.error'
- 'buildkite-agent artifact download --include-retried-jobs "close-execution-report.*" ./reports/ || echo "No report ERROR" > ./reports/close-execution-report.error'
- 'report_path="./reports/$(ls -v1 reports/ | tail -n 1)"'
- 'cp "$$report_path" ./close-report.txt'
- 'buildkite-agent meta-data set attempts_count "$(grep -c ATTEMPT ./close-report.txt)"'
Expand Down Expand Up @@ -134,6 +135,7 @@ steps:

- wait: ~

- command: echo "End of concurrency gate <--"
- label: ":unlock: Concurrency gate unlock"
command: echo "End of concurrency gate <--"
concurrency_group: 'validator-bonds/close-settlements'
concurrency: 1
127 changes: 127 additions & 0 deletions .buildkite/fund-settlements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
agents:
queue: "snapshots"

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: ":hammer_and_wrench: :rust: Build fund-settlement"
commands:
- '. "$HOME/.cargo/env"'
- 'cargo build --release --bin fund-settlement'
artifact_paths:
- target/release/fund-settlement

- label: " Loading json settlements data"
env:
gs_bucket: gs://marinade-validator-bonds-mainnet
past_epochs_to_load: 4
commands:
- |
set -x
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
- |
set -x
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))
- 'mkdir ./merkle-trees/'
- |
set -x
for epoch in $(seq $$epochs_start_index $$current_epoch); do
gcloud storage cp "$$gs_bucket/$$epoch/settlement-merkle-trees.json" "./merkle-trees/$${epoch}_settlement-merkle-trees.json" || true
gcloud storage cp "$$gs_bucket/$$epoch/settlements.json" "./merkle-trees/$${epoch}_settlements.json" || true
done
artifact_paths:
- "./merkle-trees/*"

- 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))'
- 'buildkite-agent artifact download --include-retried-jobs fund-execution-report.$$prior_build_number . || true'
- |
cp "fund-execution-report.$$prior_build_number" "fund-execution-report.$$BUILDKITE_RETRY_COUNT" || true
rm -f "fund-execution-report.$$prior_build_number"
echo "#ATTEMPT $$BUILDKITE_RETRY_COUNT" | tee -a "./fund-execution-report.$$BUILDKITE_RETRY_COUNT"
- 'buildkite-agent artifact download --include-retried-jobs "merkle-trees/*" .'
- 'buildkite-agent artifact download --include-retried-jobs target/release/fund-settlement .'
- 'chmod +x target/release/fund-settlement'
- |
set -o pipefail
./target/release/fund-settlement \
--rpc-url $$RPC_URL \
--operator-authority "$$VALIDATOR_BONDS_OPERATOR_AUTHORITY" \
--fee-payer "$$VALIDATOR_BONDS_SETTLEMENTS_WALLET" \
--marinade-wallet "$$VALIDATOR_BONDS_FUNDING_WALLET" \
--rent-payer "$$VALIDATOR_BONDS_SETTLEMENTS_WALLET" \
--settlement-json-files ./merkle-trees/* | tee -a "./fund-execution-report.$$BUILDKITE_RETRY_COUNT"
key: 'fund-settlement'
artifact_paths:
- "./fund-execution-report.*"
retry:
automatic:
- exit_status: 100
limit: 5

- label: ":memo: Notification setup: Fund Settlements"
env:
gs_bucket: gs://marinade-validator-bonds-mainnet
commands:
- 'mkdir ./reports'
- 'buildkite-agent artifact download --include-retried-jobs "fund-execution-report.*" ./reports/ || echo "No report ERROR" > ./reports/fund-execution-report.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: ":mega: Notification Funding"
commands:
- 'build_result=$(buildkite-agent step get "outcome" --step "fund-settlement")'
- |
if [[ -z "$$build_result" || "$$build_result" =~ "failed" ]]; then
notification_result="finished with WARNINGS"
notification_color="16355909"
else
notification_result="SUCCEEDED"
notification_color="52224"
fi
- |
attempts_count=$(buildkite-agent meta-data get attempts_count || echo "UNKNOWN")
buildkite-agent artifact download --include-retried-jobs fund-report.txt . || echo 'UNKNOWN ERROR' > './fund-report.txt'
# curl "$$DISCORD_WEBHOOK_VALIDATOR_BONDS" \
curl https://discord.com/api/webhooks/1237762124114296923/O-Gv1aBiB4LZy87ppR-87LPVDCBz7591Kcse52GyRUmrU-Y8IVpAjnSuP-ZwpGDLLb88 \
-F 'payload_json={
"embeds":[{
"title": "Fund Settlements '"$$notification_result"', '"$$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
Loading

0 comments on commit 53faff2

Please sign in to comment.