Skip to content

Commit

Permalink
Nix definitions: update to the topology trimming
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfire committed Nov 20, 2019
1 parent a2c9b2e commit e701a1f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
20 changes: 11 additions & 9 deletions nix/nixos/cardano-cluster-service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ let
node-ids = range 0 (cfg.node-count - 1);
cardano-node = ncfg.package;

# mkFullyConnectedLocalClusterTopology
# :: Address String -> Port String -> Int -> Int -> Topology FilePath
mkFullyConnectedLocalClusterTopology =
# mkFullyConnectedLocalNodeSetup
# :: Address String -> Port String -> Port String -> Int -> Int -> Topology FilePath
mkFullyConnectedLocalNodeSetup =
{ hostAddr
, port
, portBase
, node-count
, valency ? 1
Expand All @@ -22,12 +23,11 @@ let
addr = hostAddr;
ports = map (x: portBase + x) (range 0 (node-count - 1));
mkPeer = port: { inherit addr port valency; };
mkNodeTopo = nodeId: port: {
inherit nodeId;
mkNodeTopo = port: {
nodeAddress = { inherit addr port; };
producers = map mkPeer (remove port ports);
};
in toFile "topology.yaml" (toJSON (imap0 mkNodeTopo ports));
in toFile "topology.yaml" (toJSON (mkNodeTopo port));

## Note how some values are literal strings, and some integral.
## This is an important detail.
Expand Down Expand Up @@ -122,11 +122,12 @@ let
delegationCertificate = ''$(printf "%s/delegation-cert.%03d.json" $(dirname $2) $1)'';
nodeId = "$1";
port = "$((${toString portBase} + $1))";
topology = mkFullyConnectedLocalClusterTopology
mkNetworkConfig = port: mkFullyConnectedLocalNodeSetup
{ inherit (cfg) node-count;
inherit (ncfg) hostAddr;
inherit portBase;
inherit port portBase;
};
network-configs = map mkNetworkConfig (range portBase (portBase + cfg.node-count - 1));
in {
options = with types; {

Expand Down Expand Up @@ -154,7 +155,8 @@ in {
enable = true;
instanced = true;
genesisHash = genesisHashValue;
inherit topology genesisFile signingKey delegationCertificate nodeId port;
inherit genesisFile signingKey delegationCertificate nodeId port;
topology = ''$(choice "$1" ${concatStringsSep " " network-configs})'';
};
services.chairman.genesisHash = genesisHashValue;
systemd.services."cardano-node@" = {
Expand Down
4 changes: 2 additions & 2 deletions nix/nixos/cardano-node-service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ let
# "--node-id ${toString cfg.nodeId}"
"--host-addr ${cfg.hostAddr}"
"--port ${toString cfg.port}"
"${lib.optionalString (cfg.pbftThreshold != null) "--pbft-signature-threshold ${cfg.pbftThreshold}"}"
"${lib.optionalString (cfg.signingKey != null) "--signing-key ${cfg.signingKey}"}"
"${lib.optionalString (cfg.delegationCertificate != null) "--delegation-certificate ${cfg.delegationCertificate}"}"
"${cfg.extraArgs}"
];
in ''
choice() { i=$1; shift; eval "echo \''${$((i + 1))}"; }
echo "Starting ${exec}: '' + concatStringsSep "\"\n echo \"" cmd + ''"
echo "..or, once again, in a signle line:"
echo "'' + concatStringsSep " " cmd + ''"
Expand Down Expand Up @@ -188,7 +188,7 @@ in {
};

topology = mkOption {
type = types.path;
type = types.string;
default = mkEdgeTopology {
inherit (cfg) hostAddr nodeId port;
edgeHost = envConfig.edgeHost or "127.0.0.1";
Expand Down
1 change: 0 additions & 1 deletion nix/nixos/chairman-as-a-service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ let
exec = "chairman";
cmd = builtins.filter (x: x != "") [
"${ncfg.package}/bin/chairman"
"--${ncfg.consensusProtocol}"
(nodeIdArgs)
"--timeout ${toString cfg.timeout}"
"--database-path ${cfg.stateDir}/${cfg.dbPrefix}"
Expand Down

0 comments on commit e701a1f

Please sign in to comment.