|
| 1 | +{ pkgs |
| 2 | +, profile |
| 3 | +, nodeSpecs |
| 4 | +, workload |
| 5 | +}: |
| 6 | + |
| 7 | +let |
| 8 | + |
| 9 | + # Packages |
| 10 | + ########## |
| 11 | + |
| 12 | + bashInteractive = pkgs.bashInteractive; |
| 13 | + coreutils = pkgs.coreutils; |
| 14 | + jq = pkgs.jq; |
| 15 | + # Avoid rebuilding on every commit because of `set-git-rev`. |
| 16 | + cardano-cli = pkgs.cardanoNodePackages.cardano-cli.passthru.noGitRev; |
| 17 | + # Hyra (Release 1.0.0). |
| 18 | + commit = "b5e33b55e9fba442c562f82cec6c36b1716d9847"; |
| 19 | + flake = (__getFlake "github:cardano-scaling/hydra/${commit}"); |
| 20 | + hydra = flake.packages.${builtins.currentSystem}.hydra-node; |
| 21 | + |
| 22 | + # Parameters |
| 23 | + ############ |
| 24 | + |
| 25 | + testnet_magic = 42; |
| 26 | + baseport = workload.parameters.baseport or 31000; |
| 27 | + # Filter producers from "node-specs.json". |
| 28 | + producers = |
| 29 | + builtins.filter |
| 30 | + (nodeSpec: nodeSpec.isProducer) |
| 31 | + (builtins.attrValues nodeSpecs) |
| 32 | + ; |
| 33 | + # Construct an "array" with node producers to use in BASH `for` loops. |
| 34 | + producers_bash_array = |
| 35 | + "(" |
| 36 | + + (builtins.concatStringsSep |
| 37 | + " " |
| 38 | + (builtins.map |
| 39 | + (x: "\"" + x.name + "\"") |
| 40 | + producers |
| 41 | + ) |
| 42 | + ) |
| 43 | + + ")" |
| 44 | + ; |
| 45 | + |
| 46 | +in '' |
| 47 | +###################################################################### |
| 48 | +# Entrypoint ######################################################### |
| 49 | +###################################################################### |
| 50 | +
|
| 51 | +function hydra { |
| 52 | + # Run the producer workflow for each deployed producer. |
| 53 | + local producers=${toString producers_bash_array} |
| 54 | + for producer_name in ''${producers[*]} |
| 55 | + do |
| 56 | + if test -d "../../''${producer_name}" |
| 57 | + then |
| 58 | + hydra_deployed "''${producer_name}" |
| 59 | + fi |
| 60 | + done |
| 61 | +} |
| 62 | +
|
| 63 | +function hydra_deployed { |
| 64 | + # Function arguments. |
| 65 | + local producer_name=$1 # node name / folder to find the socket to use. |
| 66 | +
|
| 67 | + local producer_i |
| 68 | + producer_i="$( \ |
| 69 | + ${jq}/bin/jq --raw-output \ |
| 70 | + --arg keyName "''${producer_name}" \ |
| 71 | + '.[$keyName].i' \ |
| 72 | + ../../node-specs.json \ |
| 73 | + )" |
| 74 | +
|
| 75 | + msg "Starting: \"''${producer_name}\" (''${producer_i})" |
| 76 | +
|
| 77 | + # Parameters for this node: |
| 78 | + # - Where to obtain the genesis funds from. |
| 79 | + genesis_funds_vkey="../../genesis/cache-entry/utxo-keys/utxo$((producer_i + 1)).vkey" |
| 80 | + genesis_funds_skey="../../genesis/cache-entry/utxo-keys/utxo$((producer_i + 1)).skey" |
| 81 | + # - IP address and port. |
| 82 | + producer_port="$((${toString baseport} + producer_i))" |
| 83 | +
|
| 84 | + msg "Params: ''${genesis_funds_vkey} - ''${genesis_funds_skey} - ''${baseport}" |
| 85 | +
|
| 86 | + ${hydra}/bin/hydra-node \ |
| 87 | + --node-id "''${producer_i}" \ |
| 88 | + --listen "127.0.0.1:''${producer_port}" \ |
| 89 | + --advertise "127.0.0.1:''${producer_port}" \ |
| 90 | + --cardano-verification-key "''${genesis_funds_vkey}" \ |
| 91 | + --cardano-signing-key "''${genesis_funds_skey}" \ |
| 92 | + --testnet-magic ${toString testnet_magic} \ |
| 93 | + --node-socket "../../''${node-str}/node.socket" \ |
| 94 | + --config ./config.yaml |
| 95 | +} |
| 96 | +
|
| 97 | +###################################################################### |
| 98 | +# Utils ############################################################## |
| 99 | +###################################################################### |
| 100 | +
|
| 101 | +function msg { |
| 102 | + # Outputs to stdout, unbuffered if not the message may be lost! |
| 103 | + ${coreutils}/bin/stdbuf -o0 \ |
| 104 | + ${bashInteractive}/bin/sh -c \ |
| 105 | + "${coreutils}/bin/echo -e \"$(${coreutils}/bin/date --rfc-3339=seconds): $1\"" |
| 106 | +} |
| 107 | +'' |
0 commit comments