diff --git a/crates/rpc/src/bin/open_head.rs b/crates/rpc/src/bin/open_head.rs index 1730a4e..bef1ba6 100644 --- a/crates/rpc/src/bin/open_head.rs +++ b/crates/rpc/src/bin/open_head.rs @@ -89,7 +89,7 @@ async fn main() { .try_into() .expect("Failed to get party verification key from file"); - println!("Building init transaction..."); + debug!("Building init transaction..."); let participant_hash = match Address::from_bech32(args.participant.as_str()) .expect("Failed to parse bech32 participant address") @@ -125,7 +125,7 @@ async fn main() { )) .expect("Failed to build tx"); - println!("Tx bytes: {}", hex::encode(built_init_tx.tx_bytes.clone())); + debug!("Tx bytes: {}", hex::encode(built_init_tx.tx_bytes.clone())); let built_init_tx = built_init_tx .sign(admin_key.clone().into()) @@ -141,8 +141,8 @@ async fn main() { .await .expect("Failed to submit init tx"); - println!("Submitted init tx: {}", init_tx_id); - println!("Committing funds..."); + debug!("Submitted init tx: {}", init_tx_id); + debug!("Committing funds..."); let commit_inputs: Vec<(InputWrapper, OutputWrapper)> = join_all(args.commit_inputs.into_iter().map(|input| async { let input: InputWrapper = input.try_into().expect("Failed to parse commit input. Please make sure it uses the following format: {tx_hash}#{index}"); @@ -196,7 +196,7 @@ async fn main() { .sign(admin_key.into()) .expect("Failed to sign commit tx"); - println!( + debug!( "Signed commit tx: {}", hex::encode(built_commit_tx.tx_bytes.clone()) ); @@ -205,5 +205,5 @@ async fn main() { .submit_transaction(built_commit_tx) .await .expect("Failed to submit commit tx"); - println!("Submitted commit tx: {}", commit_tx_id); + debug!("Submitted commit tx: {}", commit_tx_id); } diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..75dc112 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,44 @@ +# Scripts + +## CRD + +The `crd.sh` is there to update the CRD of the HydraDoom resource on the +bootstrapping folder. It dumps the definition generated on the Rust code into +YAML format, that is later formatted into K8s by the `tfk8s` bin. + + +## Prepare online node + +To prepare an online node you must have: + +* Permission to list and upload into `hydradoomsnapshots` bucket. +* `cardano-cli` in your PATH. +* `hydra-node` in your PATH. +* `admin.sk` and `admin.vk` files. +* A Blockfrost API key. +* A Cardano node-socket (`dmtrctl ports tunnel`). + +To run the script: + +```sh +./prepare_online_node.sh \ + --admin-signing-key-file PATH_TO_ADMIN_SK \ + --admin-verification-key-file PATH_TO_ADMIN_VK \ + --blockfrost-key YOUR_BF_API_KEY \ + --node-id NODE_ID \ + --protocol-parameters ../playbook/doom-dev/protocol-parameters.json \ + --cardano-node-socket PATH_TO_YOUR_SOCKET +``` + +The script will: + +1. Query the network to get available UTxOs to use as seed and commit inputs. +2. Generate a hydra key pair to use. +3. Query the network to get current tip. +4. Run `open-head` binary with the corresponding parameters. +5. Start the hydra-node with persistence activated. This process will run until + it is externally killed. The user is supposed to `ctrl-c` once the node has + acknowledged the transaction and the head is open. +6. After the hydra-node process is terminated, a tar file with the keys and + persistence is uploaded to S3. You should see a `node.yml` with the + parameters needed to create this resource on K8s. diff --git a/scripts/prepare_online_node.sh b/scripts/prepare_online_node.sh new file mode 100755 index 0000000..3aac2ec --- /dev/null +++ b/scripts/prepare_online_node.sh @@ -0,0 +1,184 @@ +#!/bin/sh + +set -e +# Function to display help message +function show_help() { + echo "Usage: $0 " + echo " --admin-signing-key-file \\" + echo " --admin-verification-key-file \\" + echo " --blockfrost-key \\" + echo " --node-id \\" + echo " --protocol-parameters \\" + echo " --cardano-node-socket " + echo + echo "This expects for you to have cardano-cli and hydra-node in your PATH." + echo + echo "Arguments:" + echo " --admin-signing-key-file Path to the admin signing key file." + echo " --admin-verification-key-file Path to the admin verification key file." + echo " --blockfrost-key Blockfrost API key." + echo " --node-id ID to set to the node being prepared." + echo " --protocol-parameters Protocol parameters file." + echo " --cardano-node-socket Path to socket." + echo + echo "Options:" + echo " --help Display this help message" +} + +# If no arguments are provided, display help +if [ "$#" -eq 0 ]; then + show_help + exit 1 +fi + +# Check for --help flag +if [ "$1" == "--help" ]; then + show_help + exit 0 +fi + +# Check if exactly 12 arguments are provided +if [ "$#" -ne 12 ]; then + echo "Error: Incorrect number of arguments." + show_help + exit 1 +fi + +# Check AWS privileges to upload snapshot +if ! aws s3 ls s3://hydradoomsnapshots/ > /dev/null 2>&1; then + echo "Error: Unable to access S3 bucket. Please check your AWS permissions." + exit 1 +fi + +# Check hydra-node binary is on path +if ! hydra-node --help > /dev/null 2>&1; then + echo "Error: hydra-node not found on PATH." + exit 1 +fi + +# Check cardano-cli is on path +if ! cardano-cli --help > /dev/null 2>&1; then + echo "Error: cardano-cli not found on PATH." + exit 1 +fi + +# Parse arguments +while [ "$#" -gt 0 ]; do + case "$1" in + --admin-signing-key-file) + ADMIN_SIGNING_KEY_FILE="$2" + shift 2 + ;; + --admin-verification-key-file) + ADMIN_VERIFICATION_KEY_FILE="$2" + shift 2 + ;; + --blockfrost-key) + BLOCKFROST_KEY="$2" + shift 2 + ;; + --node-id) + NODE_ID="$2" + shift 2 + ;; + --protocol-parameters) + PROTOCOL_PARAMETERS="$2" + shift 2 + ;; + --cardano-node-socket) + CARDANO_NODE_SOCKET="$2" + shift 2 + ;; + *) + echo "Unknown option: $1" + show_help + exit 1 + ;; + esac +done + +echo "---" +echo "" +echo "Getting UTxOs to generate init and commit..." +echo "" +echo "---" +ADDRESS=$(cardano-cli address build --verification-key-file "$ADMIN_VERIFICATION_KEY_FILE" --testnet-magic 1) +SEED_INPUT=$(cardano-cli conway query utxo --address $ADDRESS --output-json --testnet-magic 1 --socket-path $CARDANO_NODE_SOCKET | jq -r 'to_entries[0].key') +COMMIT_INPUT=$(cardano-cli conway query utxo --address $ADDRESS --output-json --testnet-magic 1 --socket-path $CARDANO_NODE_SOCKET | jq -r 'to_entries[-1].key') + +echo "* Seed input: $SEED_INPUT" +echo "* Commit input: $COMMIT_INPUT" + +# Generate key pair. +mkdir keys +hydra-node gen-hydra-key --output-file keys/hydra + +# Get current SLOT.HASH +START_POINT=$(cardano-cli query tip --socket-path socket --testnet-magic 1 | jq -r '"\(.slot).\(.hash)"') + +echo "---" +echo "" +echo "Opening head..." +echo "" +echo "---" +# Open head +cargo run --bin open-head -- \ + --network-id 0 \ + --seed-input $SEED_INPUT \ + --participant $ADDRESS \ + --party-verification-file keys/hydra.vk \ + --cardano-key-file $ADMIN_SIGNING_KEY_FILE \ + --blockfrost-key $BLOCKFROST_KEY \ + --commit-inputs $COMMIT_INPUT + +# Start hydra-node in the background. +echo "---" +echo "" +echo "Running hydra-node with persistence. You should terminate this process when the head is already opened." +echo "" +echo "---" + +set +e +hydra-node \ + --node-id $NODE_ID \ + --persistence-dir persistence \ + --cardano-signing-key $ADMIN_SIGNING_KEY_FILE \ + --hydra-signing-key keys/hydra.sk \ + --hydra-scripts-tx-id 03f8deb122fbbd98af8eb58ef56feda37728ec957d39586b78198a0cf624412a \ + --ledger-protocol-parameters $PROTOCOL_PARAMETERS \ + --testnet-magic 1 \ + --node-socket $CARDANO_NODE_SOCKET \ + --api-port 4001 \ + --host 0.0.0.0 \ + --api-host 0.0.0.0 \ + --port 5001 \ + --start-chain-from $START_POINT +set -e + +echo "---" +echo "" +echo "Uploading tar..." +echo "" +echo "---" +tar -czvf "$NODE_ID.tar.gz" persistence keys +aws s3 cp "$NODE_ID.tar.gz" s3://hydradoomsnapshots/ + +echo "To run online node, apply the following:" +echo "---" +FILE=$(cat < "$NODE_ID.yml" + +rm -rf persistence keys