Skip to content

Commit

Permalink
Merge pull request #510 from serokell/rvem/chore-support-multiple-pro…
Browse files Browse the repository at this point in the history
…tocols-daemons-modules

[Chore] Support multiple protocols simultaneously in daemon modules
  • Loading branch information
pasqu4le authored Sep 19, 2022
2 parents a82695b + c4b93b3 commit 189a24e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
19 changes: 11 additions & 8 deletions nix/modules/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ rec {

daemonOptions = sharedOptions // {

baseProtocol = mkOption {
type = types.enum [ "013-PtJakart" "014-PtKathma" ];
baseProtocols = mkOption {
type = types.listOf (types.enum [ "013-PtJakart" "014-PtKathma" ]);
description = ''
Base protocol version.
List of protocols for which daemons will be run.
'';
example = "013-PtJakart";
example = ["013-PtJakart"];
};

rpcPort = mkOption {
Expand All @@ -50,10 +50,10 @@ rec {
mkIf (instancesCfg != {}) {
users = mkMerge (flip mapAttrsToList instancesCfg (node-name: node-cfg: genUsers node-name ));
systemd = mkMerge (flip mapAttrsToList instancesCfg (node-name: node-cfg:
let tezos-service = service-pkgs."${node-cfg.baseProtocol}";
let tezos-client = "${pkgs.tezosPackages.tezos-client}/bin/tezos-client";
passwordFilenameArg = if node-cfg.passwordFilename != null then "-f ${node-cfg.passwordFilename}" else "";
in {
services."tezos-${node-name}-tezos-${service-name}" = genSystemdService node-name node-cfg service-name // rec {
services."tezos-${node-name}-tezos-${service-name}" = lib.recursiveUpdate (genSystemdService node-name node-cfg service-name) rec {
bindsTo = [ "network.target" "tezos-${node-name}-tezos-node.service" ];
after = bindsTo;
path = with pkgs; [ curl ];
Expand All @@ -69,14 +69,17 @@ rec {
# Generate or update service config file
if [[ ! -f "$service_data_dir/config" ]]; then
${tezos-service} -d "$service_data_dir" -E "http://localhost:${toString node-cfg.rpcPort}" ${passwordFilenameArg} \
${tezos-client} -d "$service_data_dir" -E "http://localhost:${toString node-cfg.rpcPort}" ${passwordFilenameArg} \
config init --output "$service_data_dir/config" >/dev/null 2>&1
else
${tezos-service} -d "$service_data_dir" -E "http://localhost:${toString node-cfg.rpcPort}" ${passwordFilenameArg} \
${tezos-client} -d "$service_data_dir" -E "http://localhost:${toString node-cfg.rpcPort}" ${passwordFilenameArg} \
config update >/dev/null 2>&1
fi
'' + service-prestart-script node-cfg;
script = service-start-script node-cfg;
serviceConfig = {
Type = "forking";
};
};
}));
};
Expand Down
9 changes: 5 additions & 4 deletions nix/modules/tezos-accuser.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ in {
};
};
config =
let accuser-start-script = node-cfg: ''
${tezos-accuser-pkgs.${node-cfg.baseProtocol}} -d "$STATE_DIRECTORY/client/data" \
let accuser-start-script = node-cfg: concatMapStringsSep "\n" (baseProtocol:
''
${tezos-accuser-pkgs.${baseProtocol}} -d "$STATE_DIRECTORY/client/data" \
-E "http://localhost:${toString node-cfg.rpcPort}" \
run "$@"
'';
run "$@" &
'') node-cfg.baseProtocols;
in common.genDaemonConfig {
instancesCfg = cfg.instances;
service-name = "accuser";
Expand Down
9 changes: 5 additions & 4 deletions nix/modules/tezos-baker.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ in {
let baker-start-script = node-cfg:
let
voting-option = "--liquidity-baking-toggle-vote ${node-cfg.liquidityBakingToggleVote}";
in ''
${tezos-baker-pkgs.${node-cfg.baseProtocol}} -d "$STATE_DIRECTORY/client/data" \
in concatMapStringsSep "\n" (baseProtocol:
''
${tezos-baker-pkgs.${baseProtocol}} -d "$STATE_DIRECTORY/client/data" \
-E "http://localhost:${toString node-cfg.rpcPort}" \
run with local node "$STATE_DIRECTORY/node/data" ${voting-option} ${node-cfg.bakerAccountAlias}
'';
run with local node "$STATE_DIRECTORY/node/data" ${voting-option} ${node-cfg.bakerAccountAlias} &
'') node-cfg.baseProtocols;
baker-prestart-script = node-cfg: if node-cfg.bakerSecretKey != null then ''
${tezos-client} -d "$STATE_DIRECTORY/client/data" import secret key "${node-cfg.bakerAccountAlias}" ${node-cfg.bakerSecretKey} --force
'' else "";
Expand Down
4 changes: 2 additions & 2 deletions tests/tezos-modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import "${nixpkgs}/nixos/tests/make-test-python.nix" ({ ... }:

services.tezos-accuser.instances.jakartanet = {
enable = true;
baseProtocol = "013-PtJakart";
baseProtocols = ["013-PtJakart" "014-PtKathma"];
};

services.tezos-baker.instances.jakartanet = {
enable = true;
baseProtocol = "013-PtJakart";
baseProtocols = ["013-PtJakart" "014-PtKathma"];
bakerAccountAlias = "baker";
bakerSecretKey = "unencrypted:edsk3KaTNj1d8Xd3kMBrZkJrfkqsz4XwwiBXatuuVgTdPye2KpE98o";
};
Expand Down

0 comments on commit 189a24e

Please sign in to comment.