Explain the difference between static and dynamic configuration. Move out specific configuration parts from here to their howto sections, such as multi-synchronizer below.Documentation Index
Fetch the complete documentation index at: https://docs.canton.network/llms.txt
Use this file to discover all available pages before exploring further.
Set Configuration Options
Canton differentiates between static and dynamic configuration. Static configuration is immutable and therefore has to be known from the beginning of the process. For a static configuration, examples would be the connectivity parameters to the local persistence store or the port the admin-apis should bind to. On the other hand, connecting to a synchronizer or adding parties are not matters of static configuration and therefore are not set via the config file but through console commands (or the administration APIs). The configuration files themselves are written in HOCON format with some extensions:- Durations are specified scala durations using a
<length><unit>format. Valid units are defined by scala directly, but behave as expected usingms,s,m,h,dto refer to milliseconds, seconds, minutes, hours and days. Durations have to be non-negative in our context.
Configuration reference
The Canton configuration file for static properties is based on PureConfig. PureConfig maps Scala case classes and their class structure into analogue configuration options (see e.g. the PureConfig quick start for an example). Therefore, the ultimate source of truth for all available configuration options and the configuration file syntax is given by the appropriate scaladocs of the CantonConfig classes. When understanding the mapping from scaladocs to configuration, please keep in mind that:- CamelCase Scala names are mapped to lowercase-with-dashes names in configuration files, e.g.
synchronizerParametersin the scaladocs becomessynchronizer-parametersin a configuration file (dash, not underscore). Option[<scala-class>]means that the configuration can be specified but doesn’t need to be, e.g. you can specify a JWT token viatoken=tokenin a remote participant configuration, but not specifyingtokenis also valid.
Configuration Compatibility
The enterprise edition configuration files extend the community configuration. As such, any community configuration can run with an enterprise binary, whereas not every enterprise configuration file will also work with community versions.Advanced Configurations
Configuration files can be nested and combined together. First, using theinclude required directive (with relative paths), a configuration file can include other configuration files.
required keyword will trigger an error, if the included file does not exist; without the required keyword, any missing files will be silently ignored. The file keyword instructs the configuration parser to interpret its argument as a file name; without this keyword, the parser may interpret the given name as a URL or classpath resource. By using the file keyword, you will also get the most intuitive semantics and most stable semantics of include. The precise rules for resolving relative paths can be found here.
Second, by providing several configuration files, we can override configuration settings using explicit configuration option paths:
key = ${ENV_VAR_NAME} or optional substitution key = ${?ENV_VAR_NAME}, where the key will only be set if the environment variable exists.
Configuration Mixin
Even more than multiple configuration files, we can leverage PureConfig to create shared configuration items that refer to environment variables. A handy example is the following, which allows for sharing database configuration settings in a setup involving several synchronizers or participant nodes:Multiple Synchronizers
A Canton configuration allows you to define multiple synchronizers. Also, a Canton participant can connect to multiple synchronizers. This is however only supported as a preview feature and not yet suitable for production use. In particular, contract key uniqueness cannot be enforced over multiple synchronizers. In this situation, we need to turn contract key uniqueness off by setting #22917: Fix broken literalinclude literalinclude:: CANTON/community/app/src/test/resources/documentation-snippets/non-uck-mode.conf Please note that the setting is final and cannot be changed subsequently. We will provide a migration path once multi-synchronizer functionality is fully implemented.Fail Fast Mode
By default, Canton will fail to start if it cannot access some external dependency such as the database. This is preferable during initial deployment and development, as it provides instantaneous feedback, but can cause problems in production. As an example, if Canton is started with a database in parallel, the Canton process would fail if the database is not ready before the Canton process attempts to access it. To avoid this problem, you can configure a node to wait indefinitely for an external dependency such as a database to start. The config option below will disable the “fail fast” behavior forparticipant1.
Init Configuration
Some configuration values are only used during the first initialization of a node and cannot be changed afterwards. These values are located under theinit section of the relevant configuration of the node. Below is an example with some init values for a participant config
ledger-api.max-deduplication-duration sets the maximum deduplication duration that the participant uses for command deduplication.
Use the Canton Command Line
Canton supports a variety of command line arguments. Please runbin/canton --help to see all of them. Here, we explain the most relevant ones.
Selecting a Configuration
Canton requires a configuration file to run. There is no default topology configuration built in and therefore, the user needs to at least define what kind of node (synchronizer or participant) and how many they want to run in the given process. Sample configuration files can be found in our release package, under theexamples directory.
When starting Canton, configuration files can be provided using
conf_filename2 into conf_filename. Both options -c and --config are equivalent. If several configuration files assign values to the same key, the last value is taken. The section on static configuration explains how to write a configuration file.
You can also specify config parameters on the command line, alone or along with configuration files, to specify missing parameters or to overwrite others. This can be useful for providing simple short config info. Config parameters can be provided using -C:
Run Modes
You can run Canton in various modes, depending on the desired environment and task.Interactive Console
The default method to run Canton is in the interactive mode. The process will start a command line interface (REPL) which allows to conveniently operate, modify and inspect the Canton application. In this mode, all errors will be reported asCommandExecutionException to the console, but Canton will remain running.
The interactive console can be started together with a script, using the --bootstrap=... option. The script uses the same syntax as the console.
The interactive mode is useful for development, education and expert use.
Daemon
If the console is undesired such as in server operation, Canton can be started in daemon modeSandbox
During development, it can be useful to run a lightweight ledger with a given DAR. For this purpose, you can run Canton in sandbox mode, which runs the Daml Sandbox.Headless Script Mode
For testing and scripting purposes, Canton can also start in headless script mode:Interactive Server Process using Screen
In some situations, we find it convenient to run even a server process interactively. For server use on Linux / OSX, this can be accomplished by using the screen command:canton which does not terminate on user-logout and therefore allows to inspect the Canton process whenever necessary.
A previously started process can be joined using
Java Virtual Machine Arguments
Thebin/canton application is a convenient wrapper to start a Java virtual machine running the Canton process. The wrapper supports providing additional JVM options using the JAVA_OPTS environment variable or using the -D command line option.
For example, you can configure the heap size as follows:
Declarative Configuration
Declarative configuration is an alpha feature and initially only available for participant nodes.
daml.declarative_api.items and daml.declarative_api.errors provide insights into the amount of items managed through the state configuration file. Negative error codes mean that something fundamental with the sync did not succeed (-1 if the config file cannot be parsed, -2 if something failed during the preparation of the sync, and -3 if the sync itself failed fundamentally), while positive error codes point to a number of items that failed. Anything other than 0 errors means something is wrong.
Some settings can only be applied if certain preconditions are met. Assigning a party to a user is only possible if a synchronizer is already registered. Therefore, some of the changes will only appear once these preconditions are met. However, it is safe to define a target state with parties before the participant is connected to a synchronizer.
It is also possible to mix declarative and imperative configurations. Excess items defined through the API will not be deleted unless explicitly configured to do so.
Configure storage
Canton needs to persist data to operate. Participant Nodes, Mediator Nodes, and Synchronizer Nodes all require storage configuration.Canton creates, manages and upgrades the database schema directly on startup.
Configure production storage
For production deployments, the only supported storage is PostgreSQL. Please see Configure Canton with Postgres for details on how to configure it.Other storage configurations
Configure in-memory storage
By default, in-memory storage is used if no other storage configuration is provided. With in-memory storage, in place of a relational database, in-memory data structures store the data. A consequence of this is that all data is lost when the node is stopped. This example shows explicit in-memory configuration for a Sequencer, Mediator, and Participant Node:Configure H2 storage
This example shows H2 storage configuration for a Sequencer, Mediator, and Participant Node:jdbc: prefixed url can be configured in many ways. The example above configures:
Embedded file based storage
On canton startup embedded H2 databases will be created in the ./data directory relative to the Canton node’s working directory and will have the file suffix .mv.db. When using H2 embedded connection mode only a single process can access the database at a time, so to inspect the database, it will be necessary to stop Canton first. Once no other process is accessing the database, it can be inspected using the H2 tools, such as the H2 Console.
MODE=PostgreSQL
This is essential as the SQL dialect used by Canton is PostgreSQL. This setting enables PostgreSQL compatibility mode.
LOCK_TIMEOUT=10000
This gives a thread 10 seconds to acquire a database lock before timing out.
DB_CLOSE_DELAY=-1
This setting keeps the database open until the Canton process terminates.
Configure Canton with PostgreSQL
Example configuration
This example shows a PostgreSQL storage configuration for a Sequencer, Mediator, and Participant Node all running on a local PostgreSQL database instance on port5432.
Configure the connection pool
Canton uses HikariCP for connection pooling. This is configured instorage.config. We recommend this article on how to choose the size of the pool.
The setup of
dataSourceClassName and properties for PostgreSQL are discussed in the next section.get/set method descriptions for HikariConfig.
| allowPoolSuspension | catalog | connectionInitSql |
| connectionTestQuery | connectionTimeout | dataSourceClassName |
| idleTimeout | initializationFailTimeout | isolateInternalQueries |
| leakDetectionThreshold | maxLifetime | maximumPoolSize |
| minimumIdle | poolName | properties |
| readOnly | registerMbeans | schema |
| validationTimeout |
Configure the PostgreSQL data source
To create a connectionHikariCP uses the data-source dataSourceClassName configured using the properties in properties. We recommend using the org.postgresql.ds.PGSimpleDataSource data-source configured with the following properties:
You can find the details of additional supported properties by reviewing the associated
- serverName
- databaseName
- portNumber
- user
- password
get/set method descriptions for PGSimpleDataSource.
Use environment variables in configuration
You can use environment variables to configure the PostgreSQL data-source properties. This is useful for sensitive information like passwords or when you want to avoid hardcoding values in your configuration files. In this example all the database properties are set using environment variables. The environment variables are prefixed withSEQUENCER1_ to avoid conflicts with other configurations.
Share database configuration across nodes
This example shows how PureConfig can be used to share common database configuration across multiple nodes in a Canton setup.Use SSL
Configure SSL using the followingPGSimpleDataSource properties.
ssl = true
Verify both the SSL certificate and verify the hostname
sslmode= “verify-ca”
Check the certificate chain up to the root certificate stored on the client.
sslrootcert = “path/to/root.cert”
Optionally set this to set with path to root certificate.
For more details on how to configure SSL in PostgreSQL, see the PostgreSQL SSL documentation.
Use mTLS
To configure mutual TLS (mTLS) you can use the following additional properties:
- sslcert = “path/to/client-cert.pem”
- sslkey = “path/to/client-key.p12”
Set up the PostgreSQL database
A separate database is required for each Canton node. Create the database before starting Canton.The canton distribution provides a script,
config/utils/postgres/db.sh, to help create the database and users.Create the database
Databases must be created with UTF8 encoding to ensure proper handling of Unicode characters. The following SQL command creates a database namedparticipant1_db with UTF8 encoding:
Create a database user
The database user configured in the data-source properties must have the necessary permissions to create and modify the database schema, in addition to reading and writing data. The following SQL commands create a user namedparticipant1_user with a password and grant all privileges on the database:
Operations
Optimize storage
See Storage Optimization.Backup
See Backup and Restore.Setup HA
See High Availability Usage.Use a cloud hosted database
You can use a cloud-hosted PostgreSQL database, such as Amazon RDS, Google Cloud SQL, or Azure Database for PostgreSQL. Please refer to the documentation of the respective cloud provider for details on how to set up and configure and secure a PostgreSQL database.Configure Canton parameters
Participant Node protocol version
On Participant Node connection to a Sequencer Node there is a handshake between the nodes to ensure that the Synchronizer protocol version is compatible. By default a Participant Node can connect to a Synchronizer running any stable protocol version.Ensure a minimum protocol version
Setting a minimum protocol version ensures that the Participant Node can only connect to a Synchronizer running a protocol version at least as high as the configured minimum. Use this to ensure a Participant Node cannot connect to a Synchronizer running an protocol version known to have an security exploit or that doesn’t support a required feature. For example to ensure that the Synchronizer protocol version is at least version 33 set theminimum-protocol-version Participant Node parameter:
Enable early access protocol features
Enable alpha protocol versions
To allow a Participant Node to connect to a Synchronizer running an alpha protocol version, set thealpha-version-support parameter to true. As this is an experimental feature, it’s necessary to also set the non-standard-config parameter to true:
Enable beta protocol versions
To allow a Participant Node to connect to a Synchronizer running an beta protocol version, set thebeta-version-support parameter to true. As this is an experimental feature, it’s necessary to also set the non-standard-config parameter to true:
Detect when Canton has started
When running Canton inside a test environment, it can be useful to detect when Canton has started. To instruct Canton to write a file containing details of the running ports when initialized, configure a ports-file:Enable preview commands
Canton console preview commands are commands that are not considered stable and are not listed in command group help requests. To enable preview commands, set theenable-preview-commands parameter to yes in the configuration file. Preview commands are now listed in command group help requests and may be used.