config.json
Overview
The `config.json` file serves as the centralized configuration source for the application, specifying critical runtime parameters related to networking, blockchain interaction, database connectivity, WebSocket settings, and asset pools. It provides structured JSON-formatted configuration data that governs how the application connects to Thorchain nodes, manages database connections, and handles various operational parameters such as timeouts, batch sizes, and parallelism.
This file does **not** contain executable code or functions but defines key-value pairs and nested objects used by the application components at startup or during runtime initialization. It is essential for configuring the application's behavior in different environments (e.g., local development, staging, production) without code changes.
Detailed Explanation of Configuration Sections
1. Top-Level Properties
Property | Type | Description |
|---|---|---|
`listen_port` | Integer | TCP port on which the application listens for incoming connections (default: `8080`). |
`max_block_age` | String | Maximum age of blockchain blocks considered valid, specified as a duration string (e.g., `60s` for 60 seconds). |
2. thorchain Object
Configures connectivity and synchronization parameters with Thorchain blockchain nodes.
Property | Type | Description |
|---|---|---|
`tendermint_url` | String (URL) | WebSocket URL endpoint for Tendermint RPC service used to receive block events in real-time. |
`thornode_url` | String (URL) | HTTP REST API endpoint for Thorchain node interaction. |
`last_chain_backoff` | String | Duration to back off after hitting the last chain block in case of errors or forks (e.g., `7s`). |
`fetch_batch_size` | Integer | Number of blocks or transactions to fetch per batch request from Thorchain nodes. |
`parallelism` | Integer | Number of concurrent fetch operations allowed when processing blockchain data. |
`read_timeout` | String | Timeout duration for read operations from Thorchain nodes (e.g., `32s`). |
`fork_infos` | Array | List of fork information objects describing chain forks and their parameters. |
**Fork Info Object Properties:**
Property | Type | Description |
|---|---|---|
`chain_id` | String | Identifier for the blockchain chain or fork. |
`parent_chain_id` | String | (Optional) Identifier of the parent chain from which this fork originated. |
`earliest_block_hash` | String | Hash of the earliest block considered valid for this fork. |
`earliest_block_height` | Integer | Height of the earliest block valid for this fork. |
`hard_fork_height` | Integer | (Optional) Block height at which a hard fork occurred, marking a significant chain upgrade. |
3. timescale Object
Defines connection and operational parameters for the TimescaleDB (a PostgreSQL extension for time-series data) database used by the application for storing blockchain and operational data.
Property | Type | Description |
|---|---|---|
`host` | String | Database server hostname or IP. |
`port` | Integer | Port number to connect to the database (default PostgreSQL port: 5432). |
`user_name` | String | Username credential for database authentication. |
`password` | String | Password for database authentication. |
`database` | String | Database name to connect to. |
`sslmode` | String | SSL mode for the connection (e.g., `disable`). |
`commit_batch_size` | Integer | Number of records to commit per batch operation for efficiency. |
`max_open_conns` | Integer | Maximum number of open connections allowed by the connection pool. |
4. websockets Object
Controls WebSocket server parameters used for real-time client communication.
Property | Type | Description |
|---|---|---|
`enable` | Boolean | Flag to enable or disable WebSocket server functionality. |
`connection_limit` | Integer | Maximum number of concurrent WebSocket connections allowed. |
5. usdpools Array
A list of string identifiers for specific liquidity pools involving USD-pegged assets that the application monitors or interacts with. These are usually in the format `.-`, where:
CHAIN: Blockchain network symbol (e.g., BNB, ETH, AVAX).ASSET: Asset ticker symbol (e.g., BUSD, USDT, USDC).IDENTIFIER: Contract address or pool identifier.
Important Implementation Details
Duration Strings: Time-related parameters such as
max_block_age,last_chain_backoff, andread_timeoutare expressed as strings with suffixes (e.g., "60s" for 60 seconds). The application code parsing this config must convert these strings into appropriate time duration objects or values.Fork Handling: The
fork_infosarray allows the application to handle multiple chain forks by specifying the earliest valid blocks and hard fork points. This supports robust synchronization and correct chain state management across network upgrades or forks.Batch and Parallelism Settings: Parameters like
fetch_batch_size,parallelism, andcommit_batch_sizeare tuned for performance optimization—balancing load on external services (Thorchain nodes, database) while ensuring timely data processing.Security Considerations: Sensitive information such as database
passwordis stored in plaintext here, so access to this file should be restricted. In production, consider environment variables or secret management solutions.
Interaction With Other System Components
Blockchain Synchronization Modules: Use the
thorchainsection for connecting to Thorchain Tendermint and Thornode nodes to fetch blockchain data, process blocks, and handle forks.Database Layer: Utilizes the
timescaleconfiguration to establish connections to the TimescaleDB database, managing connection pooling and batch commits.WebSocket Server: Reads the
websocketssection to determine if real-time communication via WebSocket is enabled and how many client connections are permitted.Liquidity Pool Monitoring: The
usdpoolslist informs the business logic about which pools to track for USD-pegged asset transactions and analytics.Startup and Runtime: On application startup, this JSON is parsed and loaded into configuration objects or structs accessible throughout the system, enabling consistent configuration management.
Usage Example (Pseudo-code)
import json
# Load config file
with open('config.json') as f:
config = json.load(f)
# Access listen port
port = config['listen_port']
# Connect to TimescaleDB using config
db_config = config['timescale']
db_connection = connect_to_db(
host=db_config['host'],
port=db_config['port'],
user=db_config['user_name'],
password=db_config['password'],
database=db_config['database'],
sslmode=db_config['sslmode']
)
# Fetch blockchain data with batch size and parallelism
thorchain_config = config['thorchain']
batch_size = thorchain_config['fetch_batch_size']
parallel_workers = thorchain_config['parallelism']
# Use fork info to initialize blockchain state
forks = thorchain_config['fork_infos']
for fork in forks:
initialize_fork(
chain_id=fork['chain_id'],
earliest_block_height=fork['earliest_block_height'],
earliest_block_hash=fork['earliest_block_hash'],
hard_fork_height=fork.get('hard_fork_height')
)
Visual Diagram
The following Mermaid flowchart illustrates the hierarchical structure of the `config.json` file and relationships between its main sections and nested objects.
flowchart TD
Config["config.json"]
Config --> ListenPort["listen_port: Integer"]
Config --> MaxBlockAge["max_block_age: String"]
Config --> Thorchain["thorchain"]
Thorchain --> TendermintURL["tendermint_url: String"]
Thorchain --> ThornodeURL["thornode_url: String"]
Thorchain --> LastChainBackoff["last_chain_backoff: String"]
Thorchain --> FetchBatchSize["fetch_batch_size: Integer"]
Thorchain --> Parallelism["parallelism: Integer"]
Thorchain --> ReadTimeout["read_timeout: String"]
Thorchain --> ForkInfos["fork_infos: Array"]
ForkInfos --> Fork1["ForkInfo Object"]
ForkInfos --> Fork2["ForkInfo Object"]
ForkInfos --> Fork3["ForkInfo Object"]
Config --> Timescale["timescale"]
Timescale --> Host["host: String"]
Timescale --> Port["port: Integer"]
Timescale --> UserName["user_name: String"]
Timescale --> Password["password: String"]
Timescale --> Database["database: String"]
Timescale --> SSLMode["sslmode: String"]
Timescale --> CommitBatchSize["commit_batch_size: Integer"]
Timescale --> MaxOpenConns["max_open_conns: Integer"]
Config --> Websockets["websockets"]
Websockets --> Enable["enable: Boolean"]
Websockets --> ConnectionLimit["connection_limit: Integer"]
Config --> USDpools["usdpools: Array of Strings"]
Summary
config.jsonis a critical declarative configuration file that defines the application's key parameters.It provides structured settings for blockchain node connections, database access, WebSocket communication, and asset pool monitoring.
Proper parsing and validation of this file at startup ensure the application behaves consistently and can adapt to different environments.
The
fork_infosarray is a sophisticated feature to handle blockchain fork events, supporting multi-fork chain topologies.Security of this file must be maintained due to embedded sensitive credentials.
This file ties together multiple subsystems by providing them with the necessary configuration to operate harmoniously within the broader modular architecture of the project.