Skip to content

Commit

Permalink
Make cardano-configurations configurable #438
Browse files Browse the repository at this point in the history
  • Loading branch information
klntsky committed May 26, 2022
2 parents 27ba7c9 + 8fc41c0 commit 7a7d8f4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ Here is an example that uses the overlay to launch runtime services:
# shared between `buildCtlRuntime` and `launchCtlRuntime`, as shown below
#
# You can refer to the final configuration value by passing a function
# that takes a single arugment. Alternately, you can pass an attrset
# that takes a single arugment. Alternatively, you can pass an attrset
# directly
runtimeConfig = final: with final; {
network = {
name = "testnet";
magic = 1097911063;
};
# *All* of these values are optional, and shown with their default
# values. If you need even more customization, you can use `overideAttrs`
# to change the values after calling `buildCtlRuntime` (e.g. a secrets
Expand Down Expand Up @@ -425,6 +429,24 @@ Furthermore, CTL exposes an `overlay` from its flake. You can use this in the Ni

We have recenly set up a small scaffolding repository for projects wishing to adopt CTL: https://github.com/mlabs-haskell/ctl-scaffold. More documentation and resources will be added soon to the repo

### Changing network configurations.

CTL supports using networks other than testnet to provide development environment.

First you need to specify an alternative way of getting the network configuration.

[cardano-configurations](https://github.com/input-output-hk/cardano-configurations) repo provides configs for `mainnet`, `staging` and a few other networks.

Which of the network config directories is chosen is determined by `network.name` parameter of `buildCtlRuntime`

You can specify your own fork of `cardano-configurations` like this:

```
inputs.cardano-transaction-lib.inputs.cardano-configurations.follows = "...";
```

When changing networks, make sure that `network.magic` is correctly synchronized with value in config (see `protocolConsts.protocolMagic` in `byron.json`).

## Architecture

CTL is directly inspired by the Plutus Application Backend (PAB). Unlike PAB, however, CTL is a library and not a standalone process. Over the course of CTL's development, several questions have been raised as to how best create PAB-as-a-library:
Expand Down
21 changes: 15 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
cardano-node-exe = {
url = "github:input-output-hk/cardano-node/ea8b632820db5546b22430bbb5ed8db4a2fef7dd";
};
# Repository with network parameters
cardano-configurations = {
# Override with "path:/path/to/cardano-configurations";
url = "github:input-output-hk/cardano-configurations";
flake = false;
};
Expand Down Expand Up @@ -165,6 +167,11 @@
};

defaultConfig = final: with final; {
inherit (inputs) cardano-configurations;
network = {
name = "testnet";
magic = 1097911063; # use `null` for mainnet
};
node = { port = 3001; };
ogmios = { port = 1337; };
ctlServer = { port = 8081; };
Expand Down Expand Up @@ -206,8 +213,8 @@
fix (final: recursiveUpdate
(defaultConfig final)
(if isFunction extraConfig then extraConfig final else extraConfig));
nodeDbVol = "node-db";
nodeIpcVol = "node-ipc";
nodeDbVol = "node-${config.network.name}-db";
nodeIpcVol = "node-${config.network.name}-ipc";
nodeSocketPath = "/ipc/node.socket";
serverName = "ctl-server:exe:ctl-server";
server = self.packages.${system}."${serverName}";
Expand All @@ -227,8 +234,8 @@
image = "inputoutput/cardano-node:1.34.1";
ports = [ (bindPort node.port) ];
volumes = [
"${cardano-configurations}/network/testnet/cardano-node:/config"
"${cardano-configurations}/network/testnet/genesis:/genesis"
"${config.cardano-configurations}/network/${config.network.name}/cardano-node:/config"
"${config.cardano-configurations}/network/${config.network.name}/genesis:/genesis"
"${nodeDbVol}:/data"
"${nodeIpcVol}:/ipc"
];
Expand All @@ -250,7 +257,7 @@
useHostStore = true;
ports = [ (bindPort ogmios.port) ];
volumes = [
"${cardano-configurations}/network/testnet:/config"
"${config.cardano-configurations}/network/${config.network.name}:/config"
"${nodeIpcVol}:/ipc"
];
command = [
Expand Down Expand Up @@ -279,7 +286,9 @@
${server}/bin/ctl-server \
--port ${toString ctlServer.port} \
--node-socket ${nodeSocketPath} \
--network-id 1097911063
--network-id ${if config.network.magic == null
then "mainnet"
else toString config.network.magic}
''
];
};
Expand Down

0 comments on commit 7a7d8f4

Please sign in to comment.