Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next 2024 11 06 #36

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 1 addition & 180 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import? 'scripts/recipes-aws.just'
import? 'scripts/recipes-custom.just'
import? 'scripts/recipes-governance.just'

set shell := ["bash", "-uc"]
set positional-arguments
Expand Down Expand Up @@ -1382,183 +1383,3 @@ update-ips-example:
};
}
EOF

# Generate and submit an SPO vote on a gov action
vote-with-pool ENV POOL ACTION_ID ACTION_IDX VOTE:
#!/usr/bin/env bash
set -euo pipefail
{{checkEnvWithoutOverride}}

if ! [[ "$ENV" =~ ^mainnet$|^preprod$|^preview$|^private$|^sanchonet$|^shelley-qa$|^demo$ ]]; then
echo "Error: only node environments for mainnet, preprod, preview, private, sanchonet, shelley-qa and demo are supported"
exit 1
fi

just set-default-cardano-env {{ENV}} "$MAGIC" "$PPID"

if [ "$(jq -re .syncProgress <<< "$(just query-tip {{ENV}})")" != "100.00" ]; then
echo "Please wait until the local tip of environment {{ENV}} is 100.00 before voting"
exit 1
fi

if ! [[ "{{VOTE}}" =~ ^yes$|^no$|^abstain$ ]]; then
echo "Error: VOTE arg must be one of \"yes\", \"no\" or \"abstain\""
exit 1
fi

if [ "${USE_SHELL_BINS:-}" = "true" ]; then
CARDANO_CLI="cardano-cli"
elif [ -n "${UNSTABLE:-}" ] && [ "${UNSTABLE:-}" != "true" ]; then
CARDANO_CLI="cardano-cli"
elif [ "${UNSTABLE:-}" = "true" ]; then
CARDANO_CLI="cardano-cli-ng"
elif [[ "$ENV" =~ ^mainnet$|^preprod$|^preview$|^shelley-qa$ ]]; then
CARDANO_CLI="cardano-cli"
elif [[ "$ENV" =~ ^private$|^sanchonet$ ]]; then
CARDANO_CLI="cardano-cli-ng"
fi

STATE_BEFORE=$(eval "$CARDANO_CLI" latest query gov-state)
ACTION_BEFORE=$(
jq -r \
--arg actionId {{ACTION_ID}} \
--arg actionIdx {{ACTION_IDX}} \
'.proposals | map(
select(
.actionId.txId == $actionId
and
.actionId.govActionIx == ($actionIdx | tonumber)
)
)' \
<<< "$STATE_BEFORE"
)

echo
echo "Governance action {{ACTION_ID}}#{{ACTION_IDX}} has the following associated gov state:"
echo
echo "$ACTION_BEFORE"
echo
read -p "Do you wish pool \"{{POOL}}\" in environment \"{{ENV}}\" to vote \"{{VOTE}}\" on this governance action [yY]? " -n 1 -r
echo
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Aborting the vote."
exit 1
fi

FILE="{{POOL}}-{{ACTION_ID}}#{{ACTION_IDX}}"

# An assumption is made here that users have their secret cold as $POOL-cold.skey.
# The vkey may be listed in both the deploy and no-deploy poolgroup directories,
# so limit the output to the first match.
COLD_SKEY=$(fd --max-results 1 {{POOL}}-cold.skey secrets)
COLD_VKEY=$(fd --max-results 1 {{POOL}}-cold.vkey secrets)

# Assume secrets are properly encrypted
eval "$CARDANO_CLI" latest governance vote create \
--{{VOTE}} \
--governance-action-tx-id {{ACTION_ID}} \
--governance-action-index {{ACTION_IDX}} \
--cold-verification-key-file <(just sops-decrypt-binary "$COLD_VKEY") \
--out-file "$FILE.vote"

echo
echo "The created vote to be submitted is the following:"
echo
eval "$CARDANO_CLI" latest governance vote view \
--vote-file "$FILE.vote"
echo
echo
read -p "Do you wish to proceed with this vote [yY]? " -n 1 -r
echo
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Aborting the vote."
exit 1
fi

RICH_ADDR=$(just sops-decrypt-binary secrets/envs/${ENV}/utxo-keys/rich-utxo.addr)

# Select the smallest available UTxO without native tokens attached and greater than 5 ADA automatically with jq:
RICH_UTXOS=$(eval "$CARDANO_CLI" latest query utxo --address "$RICH_ADDR" --out-file /dev/stdout)

TX_SELECTED=$(jq -r '.
| to_entries
| map(select((.value.value | length == 1) and .value.value.lovelace > 5000000))
| sort_by(.value.value.lovelace)[0]' <<< "$RICH_UTXOS"
)

TXIN=$(jq -r '.key' <<< "$TX_SELECTED")
TXVALUE=$(jq -r '.value.value.lovelace' <<< "$TX_SELECTED")

echo
echo "Selected rich key funding TX \"$TXIN\" with value $TXVALUE lovelace"

eval "$CARDANO_CLI" latest transaction build \
--tx-in "$TXIN" \
--change-address "$RICH_ADDR" \
--testnet-magic "$TESTNET_MAGIC" \
--vote-file "$FILE.vote" \
--witness-override 2 \
--out-file "$FILE.raw"

eval "$CARDANO_CLI" latest transaction sign \
--tx-body-file "$FILE.raw" \
--signing-key-file <(just sops-decrypt-binary secrets/envs/${ENV}/utxo-keys/rich-utxo.skey) \
--signing-key-file <(just sops-decrypt-binary "$COLD_SKEY") \
--testnet-magic "$TESTNET_MAGIC" \
--out-file "$FILE.signed"

TXID=$(eval "$CARDANO_CLI" latest transaction txid --tx-file "$FILE.signed")

echo
echo "The signed vote containing transaction with txid \"$TXID\" is the following:"
echo

eval "$CARDANO_CLI" debug transaction view --tx-file "$FILE.signed"

echo
echo
read -p "Do you wish to submit this vote to the {{ENV}} network [yY]? " -n 1 -r
echo
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Aborting the vote."
exit 1
fi

echo
echo "Submitting the vote."

eval "$CARDANO_CLI" latest transaction submit --tx-file "$FILE.signed"

EXISTS="true"

while [ "$EXISTS" = "true" ]; do
EXISTS=$(eval "$CARDANO_CLI" latest query tx-mempool tx-exists $TXID | jq -r .exists)
if [ "$EXISTS" = "true" ]; then
echo "Vote transaction still exists in the mempool, sleeping 5s: $TXID"
else
echo "Vote transaction has been removed from the mempool."
fi
sleep 5
done
echo
echo

STATE_AFTER=$(eval "$CARDANO_CLI" latest query gov-state)
ACTION_AFTER=$(
jq -r \
--arg actionId {{ACTION_ID}} \
--arg actionIdx {{ACTION_IDX}} \
'.proposals | map(
select(
.actionId.txId == $actionId
and
.actionId.govActionIx == ($actionIdx | tonumber)
)
)' \
<<< "$STATE_AFTER"
)

echo "Differences in gov action state before and after submitting the vote transaction with txid \"$TXID\" are:"
echo

icdiff -L beforeTxSubmission -L afterTxSubmission <(echo "$ACTION_BEFORE") <(echo "$ACTION_AFTER")
46 changes: 23 additions & 23 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
nixpkgs.follows = "cardano-parts/nixpkgs";
nixpkgs-unstable.follows = "cardano-parts/nixpkgs-unstable";
flake-parts.follows = "cardano-parts/flake-parts";
cardano-parts.url = "github:input-output-hk/cardano-parts/v2024-11-06";
# cardano-parts.url = "path:/home/jlotoski/work/iohk/cardano-parts-wt/v2024-11-06";
cardano-parts.url = "github:input-output-hk/cardano-parts/next-2024-11-06";
# cardano-parts.url = "path:/home/jlotoski/work/iohk/cardano-parts-wt/next-2024-11-06";

# Local pins for additional customization:
cardano-node-hd.url = "github:IntersectMBO/cardano-node/utxo-hd-9.0";
Expand Down
Loading