Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

[DEVOPS-985] add useStackBinaries parameter to default.nix #3342

Merged
merged 3 commits into from
Aug 3, 2018
Merged
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
12 changes: 7 additions & 5 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ in
, enableDebugging ? false
, enableBenchmarks ? true
, allowCustomConfig ? true
, useStackBinaries ? false
}:

with pkgs.lib;
Expand Down Expand Up @@ -117,13 +118,14 @@ let
walletConfigFile = ./custom-wallet-config.nix;
walletConfig = if allowCustomConfig then (if builtins.pathExists walletConfigFile then import walletConfigFile else {}) else {};
in
args: pkgs.callPackage ./scripts/launch/connect-to-cluster (args // { inherit gitrev; } // walletConfig );
args: pkgs.callPackage ./scripts/launch/connect-to-cluster (args // { inherit gitrev useStackBinaries; } // walletConfig );
other = rec {
walletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration { inherit gitrev; };
walletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration { inherit gitrev useStackBinaries; };
validateJson = pkgs.callPackage ./tools/src/validate-json {};
demoCluster = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev; };
demoCluster = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev useStackBinaries; };
demoClusterDaedalusDev = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev useStackBinaries; disableClientAuth = true; numImportedWallets = 0; };
demoClusterLaunchGenesis = pkgs.callPackage ./scripts/launch/demo-cluster {
inherit gitrev;
inherit gitrev useStackBinaries;
launchGenesis = true;
configurationKey = "testnet_full";
runWallet = false;
Expand Down Expand Up @@ -156,7 +158,7 @@ let
inherit (pkgs) purescript;
connectScripts = {
mainnet = {
wallet = connect {};
wallet = connect { };
explorer = connect { executable = "explorer"; };
};
staging = {
Expand Down
12 changes: 12 additions & 0 deletions docs/how-to/demo-cluster.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# How to launch a local demo cluster with nix

1. Make sure nix is installed and IOHK binary cache is configured [nix setup] (https://github.com/input-output-hk/cardano-sl/blob/develop/docs/how-to/build-cardano-sl-and-daedalus-from-source-code.md#nix-build-mode-recommended)
2. To generate a script that will launch the demo cluster run `nix-build -A demoCluster -o launch_demo_cluster`
3. To generate a script that will launch demo cluster suitable for Daedalus development, run `nix-build -A demoClusterDaedalusDev -o launch_demo_cluster`
4. To launch cluster, run `./launch_demo_cluster`
5. To stop, hit `ctrl-c` and it will terminate all the nodes.
6. A `state-demo` state folder will be automatically created relative to your current
working directory.
* Logs will be found in `state-demo/logs`
* TLS certs/keys will be found in `state-demo/tls`
* 11 genesis wallets will be pre-loaded with 37 million Ada each
1 change: 1 addition & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mode, it will run in `dev` mode as well, and if you built it in `prod` mode, it
## Launch

* `launch/demo.sh` - run nodes in `tmux`-session (3 nodes by default).
* `launch/demo-nix.sh` - run demo cluster using nix with 4 core nodes, 1 relay, 1 wallet in background
* `launch/demo-with-wallet-api.sh` - run nodes in `tmux`-session, with enabled wallet web API (3 nodes by default).
* `launch/kill-demo.sh` - kill `tmux`-session with running nodes.
* `launch/testnet-{public,staging}.sh` - connect one node to the cluster (testnet or testnet staging
Expand Down
10 changes: 6 additions & 4 deletions scripts/launch/connect-to-cluster/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
, debug ? false
, disableClientAuth ? false
, extraParams ? ""
, useStackBinaries ? false
}:

with localLib;
Expand Down Expand Up @@ -51,8 +52,9 @@ let
};
};
executables = {
wallet = "${iohkPkgs.cardano-sl-wallet-new}/bin/cardano-node";
explorer = "${iohkPkgs.cardano-sl-explorer-static}/bin/cardano-explorer";
wallet = if useStackBinaries then "stack exec -- cardano-node" else "${iohkPkgs.cardano-sl-wallet-new}/bin/cardano-node";
explorer = if useStackBinaries then "stack exec -- cardano-explorer" else "${iohkPkgs.cardano-sl-explorer-static}/bin/cardano-explorer";
x509gen = if useStackBinaries then "stack exec -- cardano-x509-certificates" else "${iohkPkgs.cardano-sl-tools}/bin/cardano-x509-certificates";
};
ifWallet = localLib.optionalString (executable == "wallet");
iohkPkgs = import ./../../../default.nix { inherit config system pkgs gitrev; };
Expand Down Expand Up @@ -92,14 +94,14 @@ in pkgs.writeScript "${executable}-connect-to-${environment}" ''
${utf8LocaleSetting}
if [ ! -d ${stateDir}/tls ]; then
mkdir -p ${stateDir}/tls/server && mkdir -p ${stateDir}/tls/client
${iohkPkgs.cardano-sl-tools}/bin/cardano-x509-certificates \
${executables.x509gen} \
--server-out-dir ${stateDir}/tls/server \
--clients-out-dir ${stateDir}/tls/client \
${configurationArgs}
fi
''}

${executables.${executable}} \
exec ${executables.${executable}} \
${configurationArgs} \
${ ifWallet "--tlscert ${stateDir}/tls/server/server.crt"} \
${ ifWallet "--tlskey ${stateDir}/tls/server/server.key"} \
Expand Down
67 changes: 33 additions & 34 deletions scripts/launch/demo-cluster/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
, runExplorer ? false
, numCoreNodes ? 4
, numRelayNodes ? 1
, numImportedWallets ? 11
, assetLockAddresses ? []
, system ? builtins.currentSystem
, pkgs ? import localLib.fetchNixPkgs { inherit system config; }
Expand All @@ -14,22 +15,21 @@
, keepAlive ? true
, launchGenesis ? false
, configurationKey ? "default"
, useStackBinaries ? false
, disableClientAuth ? false
}:

with localLib;

let
executables = {
corenode = "${iohkPkgs.cardano-sl-node-static}/bin/cardano-node-simple";
wallet = "${iohkPkgs.cardano-sl-wallet-new}/bin/cardano-node";
integration-test = "${iohkPkgs.cardano-sl-wallet-new}/bin/wal-integr-test";
keygen = "${iohkPkgs.cardano-sl-tools}/bin/cardano-keygen";
explorer = "${iohkPkgs.cardano-sl-explorer-static}/bin/cardano-explorer";
};
demoClusterDeps = with pkgs; (with iohkPkgs; [ jq coreutils pkgs.curl gnused openssl cardano-sl-tools cardano-sl-wallet-new cardano-sl-node-static ]);
stackExec = optionalString useStackBinaries "stack exec -- ";
cardanoDeps = with iohkPkgs; [ cardano-sl-tools cardano-sl-wallet-new cardano-sl-node-static ];
demoClusterDeps = with pkgs; [ jq coreutils curl gnused openssl ];
allDeps = demoClusterDeps ++ (optionals (!useStackBinaries ) cardanoDeps);
walletConfig = {
inherit stateDir;
inherit stateDir disableClientAuth;
topologyFile = walletTopologyFile;
environment = "demo";
};
walletEnvironment = if launchGenesis then {
environment = "override";
Expand All @@ -39,9 +39,9 @@ let
} else {
environment = "demo";
};
demoWallet = pkgs.callPackage ./../connect-to-cluster ({ inherit gitrev; debug = false; } // walletEnvironment // walletConfig);
ifWallet = localLib.optionalString (runWallet);
ifKeepAlive = localLib.optionalString (keepAlive);
demoWallet = pkgs.callPackage ./../connect-to-cluster ({ inherit gitrev useStackBinaries; debug = false; } // walletEnvironment // walletConfig);
ifWallet = optionalString (runWallet);
ifKeepAlive = optionalString (keepAlive);
iohkPkgs = import ./../../.. { inherit config system pkgs gitrev; };
src = ./../../..;
topologyFile = import ./make-topology.nix { inherit (pkgs) lib; cores = numCoreNodes; relays = numRelayNodes; };
Expand All @@ -52,8 +52,8 @@ let
fallbacks = 1;
};
});
assetLockFile = pkgs.writeText "asset-lock-file" (localLib.intersperse "\n" assetLockAddresses);
ifAssetLock = localLib.optionalString (assetLockAddresses != []);
assetLockFile = pkgs.writeText "asset-lock-file" (intersperse "\n" assetLockAddresses);
ifAssetLock = optionalString (assetLockAddresses != []);
configFiles = pkgs.runCommand "cardano-config" {} ''
mkdir -pv $out
cd $out
Expand All @@ -69,7 +69,7 @@ let

in pkgs.writeScript "demo-cluster" ''
#!${pkgs.stdenv.shell}
export PATH=${pkgs.lib.makeBinPath demoClusterDeps}
export PATH=${pkgs.lib.makeBinPath allDeps}:$PATH
# Set to 0 (passing) by default. Tests using this cluster can set this variable
# to force the `stop_cardano` function to exit with a different code.
EXIT_STATUS=0
Expand Down Expand Up @@ -111,7 +111,7 @@ in pkgs.writeScript "demo-cluster" ''
'' else ''
echo "Creating genesis keys..."
config_files=${configFiles}
cardano-keygen --system-start 0 generate-keys-by-spec --genesis-out-dir ${stateDir}/genesis-keys --configuration-file $config_files/configuration.yaml --configuration-key ${configurationKey}
${stackExec}cardano-keygen --system-start 0 generate-keys-by-spec --genesis-out-dir ${stateDir}/genesis-keys --configuration-file $config_files/configuration.yaml --configuration-key ${configurationKey}
''}

trap "stop_cardano" INT TERM
Expand All @@ -120,15 +120,15 @@ in pkgs.writeScript "demo-cluster" ''
do
node_args="--db-path ${stateDir}/core-db$i --rebuild-db ${if launchGenesis then "--keyfile ${stateDir}/genesis-keys/generated-keys/rich/key$((i - 1)).sk" else "--genesis-secret $i"} --listen 127.0.0.1:$((3000 + i)) --json-log ${stateDir}/logs/core$i.json --logs-prefix ${stateDir}/logs --system-start $system_start --metrics +RTS -N2 -qg -A1m -I0 -T -RTS --node-id core$i --topology ${topologyFile} --configuration-file $config_files/configuration.yaml --configuration-key ${configurationKey} ${ifAssetLock "--asset-lock-file ${assetLockFile}"}"
echo Launching core node $i: cardano-node-simple $node_args
cardano-node-simple $node_args &> ${stateDir}/logs/core$i.log &
${stackExec}cardano-node-simple $node_args &> ${stateDir}/logs/core$i.log &
core_pid[$i]=$!

done
for i in {1..${builtins.toString numRelayNodes}}
do
node_args="--db-path ${stateDir}/relay-db$i --rebuild-db --listen 127.0.0.1:$((3100 + i)) --json-log ${stateDir}/logs/relay$i.json --logs-prefix ${stateDir}/logs --system-start $system_start --metrics +RTS -N2 -qg -A1m -I0 -T -RTS --node-id relay$i --topology ${topologyFile} --configuration-file $config_files/configuration.yaml --configuration-key ${configurationKey}"
echo Launching relay node $i: cardano-node-simple $node_args
cardano-node-simple $node_args &> ${stateDir}/logs/relay$i.log &
${stackExec}cardano-node-simple $node_args &> ${stateDir}/logs/relay$i.log &
relay_pid[$i]=$!

done
Expand Down Expand Up @@ -161,23 +161,22 @@ in pkgs.writeScript "demo-cluster" ''
fi
done
echo Blockchain Synced: $PERC%
# import keys
echo "Importing poor HD keys/wallet..."

for i in {0..11}
do
echo "Importing key$i.sk ..."
curl https://${demoWallet.walletListen}/api/wallets/keys \
--cacert ${stateDir}/tls/client/ca.crt \
--cert ${stateDir}/tls/client/client.pem \
-X POST \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d "\"${stateDir}/genesis-keys/generated-keys/poor/key$i.sk\"" | jq .
done

if [ ${builtins.toString numImportedWallets} -gt 0 ]
then
echo "Importing ${builtins.toString numImportedWallets} poor HD keys/wallet..."
for i in {0..${builtins.toString numImportedWallets}}
do
echo "Importing key$i.sk ..."
curl https://${demoWallet.walletListen}/api/wallets/keys \
--cacert ${stateDir}/tls/client/ca.crt \
--cert ${stateDir}/tls/client/client.pem \
-X POST \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d "\"${stateDir}/genesis-keys/generated-keys/poor/key$i.sk\"" | jq .
done
fi
''}

${ifKeepAlive ''
sleep infinity
''}
Expand Down
13 changes: 13 additions & 0 deletions scripts/launch/demo-nix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

if ! [ -x "$(command -v nix-build)" ]; then
echo 'Error: nix is not installed.' >&2
# shellcheck disable=SC2016
echo 'Run `curl https://nixos.org/nix/install | sh` and re-run this script' >&2
exit 1
fi

GITREV=$(git rev-parse HEAD)

nix-build -A demoClusterDaedalusDev --argstr gitrev "$GITREV" -o "launch_$GITREV"
exec ./launch_"$GITREV"
13 changes: 10 additions & 3 deletions scripts/test/wallet/integration/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
, gitrev ? "123456" # Dummy git revision to prevent mass rebuilds
, ghcRuntimeArgs ? "-N2 -qg -A1m -I0 -T"
, additionalNodeArgs ? ""
, useStackBinaries ? false
}:

with localLib;

let
stackExec = optionalString useStackBinaries "stack exec -- ";
cardanoDeps = with iohkPkgs; [ cardano-sl-tools ];
integrationTestDeps = with pkgs; [ gnugrep ];
allDeps = integrationTestDeps ++ (optionals (!useStackBinaries ) cardanoDeps);
demo-cluster = iohkPkgs.demoCluster.override {
inherit gitrev numCoreNodes stateDir;
inherit gitrev numCoreNodes stateDir useStackBinaries;
keepAlive = false;
assetLockAddresses = [ "DdzFFzCqrhswMWoTiWaqXUDZJuYUx63qB6Aq8rbVbhFbc8NWqhpZkC7Lhn5eVA7kWf4JwKvJ9PqQF78AewMCzDZLabkzm99rFzpNDKp5" ];
};
Expand All @@ -22,14 +27,16 @@ let
};
iohkPkgs = import ./../../../.. { inherit config system pkgs gitrev; };
in pkgs.writeScript "integration-tests" ''
#!${pkgs.stdenv.shell}
export PATH=${pkgs.lib.makeBinPath allDeps}:$PATH
set -e
source ${demo-cluster}
${executables.integration-test} --tls-ca-cert ${stateDir}/tls/client/ca.crt --tls-client-cert ${stateDir}/tls/client/client.pem --tls-key ${stateDir}/tls/client/client.key
${stackExec}wal-integr-test --tls-ca-cert ${stateDir}/tls/client/ca.crt --tls-client-cert ${stateDir}/tls/client/client.pem --tls-key ${stateDir}/tls/client/client.key
EXIT_STATUS=$?
# Verify we see "transaction list is empty after filtering out asset-locked source addresses" in at least 1 core node log file
if [[ $EXIT_STATUS -eq 0 ]]
then
${pkgs.gnugrep}/bin/grep "transaction list is empty after filtering out asset-locked source addresses" state-demo/logs/core*.json
grep "transaction list is empty after filtering out asset-locked source addresses" state-demo/logs/core*.json
EXIT_STATUS=$?
fi
stop_cardano
Expand Down