-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scripts update to support private voting plan
- Loading branch information
1 parent
a42c067
commit 97dfc38
Showing
4 changed files
with
197 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -exuo pipefail | ||
|
||
rm -f ./*.{sk,pk} | ||
|
||
export TZ="UTC" | ||
|
||
format="+%Y-%m-%dT%H:%M:%SZ" | ||
now="$(date --date '15 minutes' "$format")" | ||
fund_start_time="$(date --date "$now" "$format")" | ||
fund_end_time="$(date --date "$now 4 days" "$format")" | ||
voting_power_info="$(date --date "$now -1 day" "$format")" | ||
rewards_info="$(date --date "$now -1 day" "$format")" | ||
next_fund_start_time="$(date --date "$now 1 month" "$format")" | ||
voteplan="$(< voteplan-template.json)" | ||
block0_time="$(date "$format")" | ||
block0_date="$(date --date "$block0_time" +%s)" | ||
|
||
keysArgs=() | ||
voteKeys=() | ||
comKeys=() | ||
|
||
textql -output-file sql_funds_out.csv -output-header -header -sql " | ||
update sql_funds set fund_start_time = '$fund_start_time'; | ||
update sql_funds set fund_end_time = '$fund_end_time'; | ||
update sql_funds set voting_power_info = '$voting_power_info'; | ||
update sql_funds set rewards_info = '$rewards_info'; | ||
update sql_funds set next_fund_start_time = '$next_fund_start_time'; | ||
select * from sql_funds | ||
" sql_funds.csv | ||
sed -i -r '/^\s*$/d' sql_funds_out.csv | ||
|
||
genesis="$( | ||
jq --argjson d "$block0_date" \ | ||
'.blockchain_configuration.block0_date = $d' \ | ||
< genesis-template.json | ||
)" | ||
|
||
qrCodes="$(< qr_codes.json)" | ||
crs=$(jcli votes crs generate) | ||
|
||
for i in $(seq 0 2); do | ||
jcli key generate --type=ed25519 > "committee$i.sk" | ||
jcli key to-public < "committee$i.sk" > "./committee$i.pk" | ||
|
||
commAccount="$(jcli address account "$(< ./committee$i.pk)")" | ||
qrCodes="$(echo "$qrCodes" | jq --arg k "$commAccount" '.[$k] = 10000000001')" | ||
|
||
jcli key generate --type=ed25519 > "bft$i.sk" | ||
jcli key to-public < "bft$i.sk" > "./bft$i.pk" | ||
|
||
bftAccount="$(jcli address account "$(< ./bft$i.pk)")" | ||
qrCodes="$(echo "$qrCodes" | jq --arg k "$bftAccount" '.[$k] = 10000000002')" | ||
genesis="$(echo "$genesis" | jq --arg k "$(< "bft$i.pk")" '.blockchain_configuration.consensus_leader_ids += [ $k ]')" | ||
|
||
bytes="$(jcli key to-bytes < "committee$i.pk")" | ||
genesis="$(echo "$genesis" | jq --arg k "$bytes" '.blockchain_configuration.committees += [ $k ]')" | ||
|
||
comKeys+=("-committee-auth-public-key" "$(< "committee$i.sk")") | ||
jcli votes committee communication-key generate > "comm$i.sk" | ||
jcli votes committee communication-key to-public --input "comm$i.sk" > "comm$i.pk" | ||
keysArgs+=("--keys" "$(< "comm$i.pk")") | ||
done | ||
|
||
for i in $(seq 0 2); do | ||
jcli votes committee member-key generate --threshold 3 --crs "$crs" --index "$i" "${keysArgs[@]}" > "./member$i.sk" | ||
jcli votes committee member-key to-public --input "./member$i.sk" > "./member$i.pk" | ||
voteKeys+=("--keys" "$(< "./member$i.pk")") | ||
voteplan="$(echo "$voteplan" | jq --arg k "$(< "member$i.pk")" '.committee_member_public_keys += [ $k ]')" | ||
done | ||
|
||
set +x | ||
for addr in $(echo "$qrCodes" | jq '. | keys | .[]' -r); do | ||
genesis="$(echo "$genesis" | jq --arg k "$addr" '.initial[0].fund += [{"address":$k,"value":10000000002}]')" | ||
done | ||
set -x | ||
|
||
echo "$genesis" > genesis.json | ||
jcli genesis encode --input genesis.json --output block0.bin | ||
|
||
jcli votes encrypting-key "${voteKeys[@]}" > "./vote.pk" | ||
|
||
echo "$voteplan" > voteplan.json | ||
jcli certificate new vote-plan voteplan.json --output voteplan.certificate | ||
rm -rf jnode_VIT_* | ||
vitconfig \ | ||
-fund sql_funds_out.csv \ | ||
-proposals fund2-proposals.csv \ | ||
-vote-start "$fund_start_time" \ | ||
-vote-end "$fund_end_time" \ | ||
-genesis-time "$block0_time" \ | ||
"${comKeys[@]}" \ | ||
|| true # this command has to fail for some reason | ||
|
||
|
||
cp jnode_VIT_*/vote_plans/public_voteplan_*.json catalyst_dryrun.json | ||
|
||
rm -f database.sqlite3 | ||
vit-servicing-station-cli db init --db-url ./database.sqlite3 | ||
vit-servicing-station-cli csv-data load \ | ||
--db-url database.sqlite3 \ | ||
--funds sql_funds_out.csv \ | ||
--proposals jnode_VIT_*/vit_station/sql_proposals.csv \ | ||
--voteplans jnode_VIT_*/vit_station/sql_voteplans.csv | ||
|
||
artifacts="$(cat artifacts.json || echo '{}')" | ||
|
||
artifacts="$( | ||
echo "$artifacts" \ | ||
| jq --arg h "sha256:$( | ||
sha256sum block0.bin | awk '{ print $1 }' | ||
)" '."catalyst-dryrun".block0.checksum = $h' | ||
)" | ||
|
||
artifacts="$( | ||
echo "$artifacts" \ | ||
| jq --arg h "sha256:$( | ||
sha256sum database.sqlite3 | awk '{ print $1 }' | ||
)" '."catalyst-dryrun".database.checksum = $h' | ||
)" | ||
|
||
echo "$artifacts" > artifacts.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
[ -n "${1:-}" ] || (echo "Please give the namespace as argument" && exit 1) | ||
|
||
namespace="$1" | ||
|
||
dir="./work/scripts/tmp2" | ||
|
||
export NOMAD_TOKEN="$(vault read -field secret_id nomad/creds/admin)" | ||
export CONSUL_HTTP_TOKEN="$(vault read -field token consul/creds/admin)"; | ||
export JORMUNGANDR_RESTAPI_URL=https://dryrun-servicing-station.vit.iohk.io/api | ||
export VOTE_PLAN="$dir/catalyst_dryrun.json" | ||
|
||
cp $dir/{artifacts.json,database.sqlite3,block0.bin} . | ||
|
||
if ! git diff --exit-code ./artifacts.json; then | ||
git add ./artifacts.json | ||
git commit -m "update artifacts for $namespace" | ||
git push origin nix-jobs | ||
fi | ||
|
||
echo "Resetting $namespace in 5 seconds..." | ||
sleep 5 | ||
|
||
for i in $(seq 0 2); do | ||
vault kv put "kv/nomad-cluster/bft/$namespace/$i" value="@$dir/bft$i.sk" | ||
vault kv put "kv/nomad-cluster/committee/$namespace/$i" value="@$dir/committee$i.sk" | ||
done | ||
|
||
aws s3 cp ./block0.bin "s3://iohk-vit-artifacts/$namespace/block0.bin" --acl public-read | ||
aws s3 cp ./database.sqlite3 "s3://iohk-vit-artifacts/$namespace/database.sqlite3" --acl public-read | ||
vault kv put "kv/nomad-cluster/$namespace/reset" value=true | ||
nomad job stop -namespace "$namespace" -purge vit || true | ||
nomad job stop -namespace "$namespace" -purge servicing-station || true | ||
# nomad job stop -namespace "$namespace" backup | ||
sleep 5 | ||
nix run ".#nomadJobs.$namespace.run" | ||
nomad job run -var "namespace=$namespace" -var rev=a1b113f60d72bd273946e2caef6a0706874c04cc ./jobs/servicing-station.hcl | ||
# nix run ".#nomadJobs.$namespace-backup.run" | ||
echo "Please verify that everything started correctly, then hit return" | ||
read -r | ||
vault kv put "kv/nomad-cluster/$namespace/reset" value=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -exuo pipefail | ||
|
||
VOTE_PLAN="work/scripts/tmp2/catalyst_dryrun.json" | ||
export JORMUNGANDR_RESTAPI_URL=https://dryrun-servicing-station.vit.iohk.io/api | ||
COMMITTEE_KEY=work/scripts/tmp2/committee0.sk | ||
COMMITTEE_ADDR="$(jcli address account "$(jcli key to-public < "$COMMITTEE_KEY")")" | ||
COMMITTEE_ADDR_COUNTER="$(jcli rest v0 account get "$COMMITTEE_ADDR" --output-format json|jq .counter)" | ||
jcli certificate new vote-plan "$VOTE_PLAN" --output vote_plan.certificate | ||
jcli transaction new --staging vote_plan.staging | ||
jcli transaction add-account "$COMMITTEE_ADDR" 0 --staging vote_plan.staging | ||
jcli transaction add-certificate "$(< vote_plan.certificate)" --staging vote_plan.staging | ||
jcli transaction finalize --staging vote_plan.staging | ||
jcli transaction data-for-witness --staging vote_plan.staging > vote_plan.witness_data | ||
jcli transaction make-witness --genesis-block-hash "$(jcli genesis hash < block0.bin)" --type account --account-spending-counter "$COMMITTEE_ADDR_COUNTER" "$(< vote_plan.witness_data)" vote_plan.witness "$COMMITTEE_KEY" | ||
jcli transaction add-witness --staging vote_plan.staging vote_plan.witness | ||
jcli transaction seal --staging vote_plan.staging | ||
jcli transaction auth --staging vote_plan.staging --key "$COMMITTEE_KEY" | ||
jcli transaction to-message --staging vote_plan.staging > vote_plan.fragment | ||
jcli rest v0 message post --file vote_plan.fragment | ||
jcli rest v0 vote active plans get |