Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/cachix/install-nix…
Browse files Browse the repository at this point in the history
…-action-27
  • Loading branch information
nhenin authored Jun 7, 2024
2 parents 5ff9e7b + f0634f3 commit ec41412
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 121 deletions.
2 changes: 1 addition & 1 deletion deploy/marlowe-oracle/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ networks:
- preprod
# Reach out to dev empowerment to add secrets for new environments when needed
images:
stagingTag: e780a902
stagingTag: c86a8b5e
4 changes: 2 additions & 2 deletions deploy/marlowe-runtime/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ networks:
instances:
qa:
parentDomain: scdev.aws.iohkdev.io
webTag: e780a902
tag: e780a902
webTag: c86a8b5e
tag: c86a8b5e
repo: ghcr.io
org: input-output-hk
cardanoNode: cardano-node-873
Expand Down
2 changes: 1 addition & 1 deletion marlowe-apps/marlowe-apps.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.4
name: marlowe-apps
version: 0.4.0.0
version: 1.0.0
synopsis: Marlowe Runtimee applications
license: Apache-2.0
license-file: LICENSE
Expand Down
2 changes: 1 addition & 1 deletion marlowe-client/marlowe-client.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ library
, exceptions ^>=0.10
, general-allocate ^>=0.2
, marlowe-chain-sync ==1.0.0
, marlowe-object ==0.2.0.1
, marlowe-object ==1.0.0
, marlowe-protocols ==0.3.0.0
, marlowe-runtime:{marlowe-runtime, contract-api, proxy-api, sync-api, tx-api} ==1.0.0
, monad-control ^>=1
Expand Down
2 changes: 1 addition & 1 deletion marlowe-contracts/marlowe-contracts.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.4
name: marlowe-contracts
version: 0.2.0.0
version: 1.0.0
license: Apache-2.0
license-files:
LICENSE
Expand Down
4 changes: 2 additions & 2 deletions marlowe-object/marlowe-object.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.4
name: marlowe-object
version: 0.2.0.1
version: 1.0.0
synopsis: Object format for Marlowe contracts.
bug-reports: https://github.com/input-output-hk/marlowe-marlowe/issues
license: Apache-2.0
Expand Down Expand Up @@ -91,7 +91,7 @@ library gen
, cardano-api-gen ^>=8.1
, hedgehog-quickcheck ^>=0.1
, lens >=5.2 && <6
, marlowe-object ==0.2.0.1
, marlowe-object ==1.0.0
, marlowe-test ==0.2.1.0
, QuickCheck >=2.14 && <3
, quickcheck-instances ^>=0.3.29
Expand Down
2 changes: 1 addition & 1 deletion marlowe-object/src/Language/Marlowe/Object/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ instance FromJSON ShelleyAddress where
fromCoreAddress :: Core.Network -> PV2.Address -> ShelleyAddress
fromCoreAddress network addr =
ShelleyAddress $
fromRight (error "fromRight: Left") $
fromRight (error $ "core address deserialization failed: " ++ show network ++ " / " ++ show addr) $
deserialiseFromBech32 (AsAddress AsShelleyAddr) $
serialiseAddressBech32 network addr

Expand Down
2 changes: 1 addition & 1 deletion marlowe-runtime-web/marlowe-runtime-web.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ library
, marlowe-cardano ==0.2.1.0
, marlowe-chain-sync ==1.0.0
, marlowe-client ==1.0.0
, marlowe-object ==0.2.0.1
, marlowe-object ==1.0.0
, marlowe-protocols ==0.3.0.0
, marlowe-runtime:{marlowe-runtime, contract-api, proxy-api, sync-api, tx-api} ==1.0.0
, monad-control ^>=1
Expand Down
4 changes: 2 additions & 2 deletions marlowe-runtime/marlowe-runtime.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ library contract-api
, hs-opentelemetry-api ^>=0.0.3
, marlowe-cardano ==0.2.1.0
, marlowe-chain-sync ==1.0.0
, marlowe-object ==0.2.0.1
, marlowe-object ==1.0.0
, marlowe-protocols ==0.3.0.0
, marlowe-runtime ==1.0.0
, plutus-ledger-api ^>=1.21
Expand Down Expand Up @@ -400,7 +400,7 @@ library contract
, lock-file ^>=0.7
, marlowe-cardano ==0.2.1.0
, marlowe-chain-sync ==1.0.0
, marlowe-object ==0.2.0.1
, marlowe-object ==1.0.0
, marlowe-protocols ==0.3.0.0
, marlowe-runtime:{marlowe-runtime, contract-api, sync-api} ==1.0.0
, plutus-ledger-api ^>=1.21
Expand Down
246 changes: 137 additions & 109 deletions nix/nixos.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ self, marlowe-plutus, cardano-node, ... }: { lib, config, pkgs, ... }: let
{ self, marlowe-plutus, cardano-node, ... }: { lib, config, pkgs, ... }:
let
inherit (lib) mkOption types mkIf attrNames listToAttrs imap0 foldr attrValues mapAttrs' makeBinPath concatStringsSep optionalAttrs mkForce optionals versionAtLeast;

allowedEnvs = [ "preprod" "preview" "mainnet" ];
Expand Down Expand Up @@ -34,7 +35,7 @@

cfg = config.marlowe.runtimes;

neededEnvs = attrNames (foldr (x: acc: acc // { ${x.network} = null; }) {} (attrValues cfg));
neededEnvs = attrNames (foldr (x: acc: acc // { ${x.network} = null; }) { } (attrValues cfg));

mkNode = env: {
autoStart = true;
Expand All @@ -52,7 +53,8 @@
};
};
};
in {
in
{
options = {
marlowe.runtimes = mkOption {
type = types.attrsOf (types.submodule runtimeOptions);
Expand All @@ -68,38 +70,45 @@ in {
};

config = mkIf (cfg != { }) {
http-services.proxied-services = listToAttrs (imap0 (idx: name: let runtime = cfg.${name}; in {
name = "marlowe-runtime-${name}-web";
value = {
inherit (runtime) domain;
systemdConfig = port: {
description = "Marlowe Runtime Web (${name})";
# allow unlimited restarts
unitConfig.StartLimitIntervalSec = 0;
serviceConfig = {
# Restart on exit, with exponential fallback up to an hour
# runtime-web needs to wait for runtime, which can take arbitrarily
# long to be ready (see comment there).
Restart = "always";
RestartMaxDelaySec= "1hour";
RestartSteps = 10;

ExecSearchPath = makeBinPath [ runtime.flake.packages.${pkgs.system}.marlowe-web-server ];
DynamicUser = true;
ExecStart = concatStringsSep " " [
"marlowe-web-server"
"--http-port" (toString port)
"--marlowe-runtime-host" "127.0.0.1"
"--marlowe-runtime-port" (toString (3701 + 3 * idx))
"--enable-open-api"
"--access-control-allow-origin-all"
];
http-services.proxied-services = listToAttrs (imap0
(idx: name:
let runtime = cfg.${name}; in
{
name = "marlowe-runtime-${name}-web";
value = {
inherit (runtime) domain;
systemdConfig = port: {
description = "Marlowe Runtime Web (${name})";
# allow unlimited restarts
unitConfig.StartLimitIntervalSec = 0;
serviceConfig = {
# Restart on exit, with exponential fallback up to an hour
# runtime-web needs to wait for runtime, which can take arbitrarily
# long to be ready (see comment there).
Restart = "always";
RestartMaxDelaySec = "1hour";
RestartSteps = 10;

ExecSearchPath = makeBinPath [ runtime.flake.packages.${pkgs.system}.marlowe-web-server ];
DynamicUser = true;
ExecStart = concatStringsSep " " [
"marlowe-web-server"
"--http-port"
(toString port)
"--marlowe-runtime-host"
"127.0.0.1"
"--marlowe-runtime-port"
(toString (3701 + 3 * idx))
"--enable-open-api"
"--access-control-allow-origin-all"
];
};
requires = [ "marlowe-runtime-${name}.service" ];
after = [ "marlowe-runtime-${name}.service" ];
};
};
requires = [ "marlowe-runtime-${name}.service" ];
after = [ "marlowe-runtime-${name}.service" ];
};
};
}) (attrNames cfg));
})
(attrNames cfg));
services.postgresql = {
enable = true;
ensureDatabases = map (inst: "runtime-${inst}") (attrNames cfg);
Expand All @@ -125,80 +134,99 @@ in {
};
};

systemd.services = listToAttrs (imap0 (idx: name: let
inherit (pkgs) writeShellApplication sqitchPg z3 postgresql;
runtimeCfg = cfg.${name};
env = runtimeCfg.network;
envConfig = config.containers."cardano-node-${env}".config.services.cardano-node.environments.${env};
db = "postgresql://postgres@/runtime-${name}";
sqitch-conf = builtins.toFile "sqitch.conf" ''
[user]
name = chainindexer
email = [email protected]
'';
runSqitch = writeShellApplication {
name = "run-sqitch";
text = ''
export SQITCH_USER_CONFIG=${sqitch-conf}
export TZ=Etc/UTC
cd ${runtimeCfg.flake.sqitch-plan-dirs.chain-sync}
sqitch --quiet deploy --target ${db}
cd ${runtimeCfg.flake.sqitch-plan-dirs.runtime}
sqitch --quiet deploy --target ${db}
'';
runtimeInputs = [ sqitchPg postgresql ];
};
pkg = runtimeCfg.flake.packages.${pkgs.system}.marlowe-runtime;
in {
name = "marlowe-runtime-${name}";
value = {
description = "Marlowe Runtime (${name})";
# allow unlimited restarts
unitConfig.StartLimitIntervalSec = 0;
serviceConfig = {
# Restart on exit, with exponential fallback up to an hour
# The runtime needs to wait for postgres and the node to be up (which
# should be relatively quick) /and/ for the node to be in Babbage (which
# can take an arbitrarily long time).
Restart = "always";
RestartMaxDelaySec= "1hour";
RestartSteps = 10;

ExecSearchPath = makeBinPath [ runSqitch pkg ];
# TODO: Wait for the nodes to be in babbage to start
ExecStartPre = "run-sqitch";
ExecStart = concatStringsSep " " ([
"marlowe-runtime"
"--socket-path" "/var/lib/nixos-containers/cardano-node-${env}/var/lib/cardano-node/node.socket"
"--database-uri" db
"--shelley-genesis-config-file" envConfig.networkConfig.ShelleyGenesisFile
"--genesis-config-file" envConfig.networkConfig.ByronGenesisFile
"--genesis-config-file-hash" envConfig.networkConfig.ByronGenesisHash
"--store-dir" "/var/lib/marlowe-runtime-${name}/store"
"--host" "0.0.0.0"
"--port" (toString (3700 + 3 * idx))
"--port-traced" (toString (3701 + 3 * idx))
"--http-port" (toString (3702 + 3 * idx))
"--minting-policy-cmd" "marlowe-minting-validator"
] ++ optionals (versionAtLeast pkg.version "0.6") [
"--min-contract-age" "87400s"
"--max-store-size" "8589934592"
]);
};
requires = [ "container@cardano-node-${env}.service" "postgresql.service" ];
after = [ "container@cardano-node-${env}.service" "postgresql.service" ];
environment = optionalAttrs (envConfig.networkConfig.RequiresNetworkMagic == "RequiresMagic") {
CARDANO_TESTNET_MAGIC = toString (builtins.fromJSON (builtins.readFile envConfig.networkConfig.ShelleyGenesisFile)).networkMagic;
};
path = [ z3 runtimeCfg.marlowe-plutus-flake.packages.${pkgs.system}.marlowe-minting-validator ];
};
}) (attrNames cfg));

containers = listToAttrs (map (env: {
name = "cardano-node-${env}";
value = mkNode env;
}) neededEnvs);
systemd.services = listToAttrs (imap0
(idx: name:
let
inherit (pkgs) writeShellApplication sqitchPg z3 postgresql;
runtimeCfg = cfg.${name};
env = runtimeCfg.network;
envConfig = config.containers."cardano-node-${env}".config.services.cardano-node.environments.${env};
db = "postgresql://postgres@/runtime-${name}";
sqitch-conf = builtins.toFile "sqitch.conf" ''
[user]
name = chainindexer
email = [email protected]
'';
runSqitch = writeShellApplication {
name = "run-sqitch";
text = ''
export SQITCH_USER_CONFIG=${sqitch-conf}
export TZ=Etc/UTC
cd ${runtimeCfg.flake.sqitch-plan-dirs.chain-sync}
sqitch --quiet deploy --target ${db}
cd ${runtimeCfg.flake.sqitch-plan-dirs.runtime}
sqitch --quiet deploy --target ${db}
'';
runtimeInputs = [ sqitchPg postgresql ];
};
pkg = runtimeCfg.flake.packages.${pkgs.system}.marlowe-runtime;
in
{
name = "marlowe-runtime-${name}";
value = {
description = "Marlowe Runtime (${name})";
# allow unlimited restarts
unitConfig.StartLimitIntervalSec = 0;
serviceConfig = {
# Restart on exit, with exponential fallback up to an hour
# The runtime needs to wait for postgres and the node to be up (which
# should be relatively quick) /and/ for the node to be in Babbage (which
# can take an arbitrarily long time).
Restart = "always";
RestartMaxDelaySec = "1hour";
RestartSteps = 10;

ExecSearchPath = makeBinPath [ runSqitch pkg ];
# TODO: Wait for the nodes to be in babbage to start
ExecStartPre = "run-sqitch";
ExecStart = concatStringsSep " " ([
"marlowe-runtime"
"--socket-path"
"/var/lib/nixos-containers/cardano-node-${env}/var/lib/cardano-node/node.socket"
"--database-uri"
db
"--shelley-genesis-config-file"
envConfig.networkConfig.ShelleyGenesisFile
"--genesis-config-file"
envConfig.networkConfig.ByronGenesisFile
"--genesis-config-file-hash"
envConfig.networkConfig.ByronGenesisHash
"--store-dir"
"/var/lib/marlowe-runtime-${name}/store"
"--host"
"0.0.0.0"
"--port"
(toString (3700 + 3 * idx))
"--port-traced"
(toString (3701 + 3 * idx))
"--http-port"
(toString (3702 + 3 * idx))
"--minting-policy-cmd"
"marlowe-minting-validator"
] ++ optionals (versionAtLeast pkg.version "0.6") [
"--min-contract-age"
"87400s"
"--max-store-size"
"8589934592"
]);
};
requires = [ "container@cardano-node-${env}.service" "postgresql.service" ];
after = [ "container@cardano-node-${env}.service" "postgresql.service" ];
environment = optionalAttrs (envConfig.networkConfig.RequiresNetworkMagic == "RequiresMagic") {
CARDANO_TESTNET_MAGIC = toString (builtins.fromJSON (builtins.readFile envConfig.networkConfig.ShelleyGenesisFile)).networkMagic;
};
path = [ z3 runtimeCfg.marlowe-plutus-flake.packages.${pkgs.system}.marlowe-minting-validator ];
};
})
(attrNames cfg));

containers = listToAttrs (map
(env: {
name = "cardano-node-${env}";
value = mkNode env;
})
neededEnvs);
};
}

0 comments on commit ec41412

Please sign in to comment.