Conflux is a fully decentralized network based on PoW(Proof of Work). If you want to participate in this decentralized network mining, or have your own RPC service, you need to run a node (also called client). This article shows you how to run a Conflux node.

Archivenode VS fullnode

Conflux nodes are divided into three types: Archivenode, fullNode, and lightNode. The difference between different types of nodes lies in the amount of data reserved for storage. The archive node is the most complete and the light node is the least. Of course, storing more data consumes more system hardware resources. See here for details on the different types of nodes

In general, if you want to participate in mining, you can run a full node, and if you want to use it as an RPC service, you need to run Archivenode. The light node is mainly used as a wallet.

The machine configuration

The machine resources to run an Archivenode are roughly as follows:

  • CPU:4Core
  • Memory:16G
  • Hard disk:200G

Fullnode has lower machine configuration requirements and requires a separate graphics card if you want to participate in mining blocks.

How do I get the node program and configuration

To obtain the Conflux network node program, first go to the Release page of the official Github Conflux-rust repository to download it. Generally, you can download the latest Release directly. Each Release not only contains the source code, but also provides pre-compiled node programs for Windows, Mac, and Linux.

It should be noted that at present, the version release of the node program on the master network and the test network is in two lines: conflux-vx.x on the master network and conflux-vx.x.x-testnet on the test network. When downloading the program, you need to select the correct version line according to your personal needs.

The downloaded zip package is decompressed into a run folder, which contains the following contents:

➜ Run tree. ├─ conflux# node program├ ─ ─ the yamlLog configuration file├ ─ ─ start. Bat# Windows startup script├ ─ ─ start. Sh# Unix startup script├ ─ ─ tethys. Toml# mainnet configuration file└ ─ ─ throttling. Toml# Stream limiting profile

0 directories, 6 files
Copy the code

The main files are Conflux and tethys.toml. If the Windows package is downloaded, the node program is Conflux.exe

The other way is to compile the node program from source, and if you are interested, you can refer to this documentation to compile it yourself.

Main Configuration items

You need to prepare the node configuration file before running the node. You can find the configuration file in the downloaded program package. The configuration file is tethys.toml on the main network and testnet.toml on the test network. The main difference between the two configuration files is the configuration values of bootNodes and chainId. Developers can also look for configuration files in the Run directory of the Conflux-rust Github repository. The file name is also tethys.toml or testnet.toml.

Usually the user doesn’t need to change any configuration, just run the startup script (don’t want to know configuration details? Skip to the next section to run the node). However, if you want to enable certain functions or customize certain behaviors of nodes, you need to set some configuration parameters by yourself. The following are some of the most common configurations:

The node type

  • node_type: Used to set the type of the startup node. The optional value isfull(Default value),archive.light

chainId

  • ChainId Specifies the ID of the chain to which the node is to be connected. The value is 1029 on the primary network and 1 on the test network.

Miner related

  • mining_address: Node mining reward receiving address. The value can be hex40 or CIP-37 (note: The network prefix of the address must be the same as the chainId currently configured). If this parameter is specifiedminint_typeThe default isstratum
  • mining_type: The value is optionalstratum.cpu.disable
  • stratum_listen_addressAddress: stratum
  • stratum_port: stratum port number
  • stratum_secret: Stratum connection certificate

RPC related

  • jsonrpc_cors: used to control RPC domain name authentication policies. The optional value isnone.all, or domain names separated by commas (no Spaces)
  • jsonrpc_http_keep_alive: false or trueUsed to control whether to set KeepAlive for RPC HTTP connections
  • jsonrpc_ws_port: websocket RPC port number
  • jsonrpc_http_port: INDICATES the HTTP RPC port number
  • public_rpc_apis: RPC API accessible to the public. The optional value isall.safe.cfx.debug.pubsub.test.traceProvided (safe = CFX + pubsub). You are advised to set this parameter tosafe
  • persist_tx_index: true or falseIf you need to process transaction-related RPCs, you need to enable this configuration at the same time, otherwise you will only be able to access the most recent transaction information
  • persist_block_number_index: true or falseTo query block information using blockNumber, you need to enable this configuration
  • executive_trace: true or falseWhether to enable trace EVM execution. If trace is enabled, it will be recorded in the database
  • get_logs_filter_max_epoch_range: Indicates the method of obtaining Event logscfx_getLogsCall, which has a significant impact on node performance. You can use this option to configure the maximum epoch range that this method can query at a time
  • get_logs_filter_max_limit: cfx_getLogsMethod the maximum number of logs that can be returned in a query

Snapshot

  • additional_maintained_snapshot_count: Specifies the number of snapshots to be retained before stable checkpoint. The default value is 0. Snapshots before stable Checkpoint are deleted. This option is required if the user wants to query for a more distant historical state. When this option is started, the disk usage also increases considerably.

directries

  • conflux_data_dir: Directory for storing data (block data, state data, node database)
  • block_db_dirBy default, block data is stored in the blockchain_db directory under the conflux_data_dir directory
  • netconf_dir: Used to control network-related persistent directories, includingnet_key

Log related

  • log_conf: specifies the log details configuration filelog.yamlThe Settings in the configuration file are overwrittenlog_levelSet up the
  • log_file: Specifies the path to log. If this is not set, it will be output to stdout
  • log_level: Indicates the log printing level. The optional value iserror.warn.info.debug.trace.off

The higher the log level is, the more logs are generated. The response logs occupy the storage space and affect node performance.

Developer (Dev) mode

Smart contract developers who want to deploy and test their code in a local node environment early in contract development can use this pattern:

  • Comment out thebootnodesconfiguration
  • mode: Sets the node mode todev
  • dev_block_interval_ms: Block generation interval, in ms

In this mode, a single node network is run and all RPC methods open.

Configuring a Genesis Account

The genesis account can be configured in dev mode using a separate genesis_secrets. TXT file, which requires a single line of private key (without the 0x prefix), and add the genesis_secrets configuration item to the configuration file. Configure the value as the path to the file:

genesis_secrets = './genesis_secrets.txt'
Copy the code

This node, each account provided the initial 10000000000000000000000 Drip is 1 w CFX.

other

  • net_key: is a 256-bit private key used to generate a unique node ID. This option is randomly generated if left unchecked. If set, a 64-length HEX string can be filled in
  • tx_pool_size: Maximum number of transactions allowed to be stored (The default 50 w)
  • tx_pool_min_tx_gas_price: Minimum limit of trading gasPrice by trading pool (The default is 1)

For complete configuration items, you can directly view the configuration file, which contains all configurable items and detailed comments.

The node

Once the configuration file is configured, you can run the node through the node program.

Run the startup script
$ ./start.sh
Copy the code

If you see something like this in the stdout or log file, the node has started successfully:

2021-04-14T11:54:23.518634+08:00 INFO Main Network :: Thr-throttling. Initialize: Min = 10 m, Max = 64 m, cap 2021-04-14 = 256 m T11:54:23. 519229 + 08:00 INFO main conflux - : '# # # # # # : : : "# # # # # # # : :' # # : : : '# # # # # # # # # # :' # # : : : : : : : '# # : # # :' # # : # # : '# #... # # # # : '... # # # # # : : # # # #... :: ##::::::: ##:::: ##:. ##::'##:: ## #::.. : : # # : # #, # # # #, # #, # # : : : : : : : # # : : : : : : : # # : : : : ': # # # #. # # # # : : : : : : : : : : # # : : : : # #, # # # # # # : # # # # # # : : : # # : : : : : : : # # # # : : : : : : : # # # : # # : : : : : : : # # : # #, # #, # # # #, # #... : : : : # # : : : : : : : # # : # # : : : # # # # : : : # # : : : # #, # # : # #, # # : # # #, # # : : : : : : : # # : : : : : : : # # : # # : # # : # #... . # # # # # # : :. # # # # # # #, # # : :. # # : # # : : : : : : : # # # # # # # # : # # # # # # #, # # : : :. # # : :... : : : :... : : :.. : : : :.. : :.. : : : : : : : :... : : :... : : :.. : : : : :.. :: Current Version: 1.1.3- Testnet 2021-04-14T11:54:23.519271+08:00 INFO Main Conflux - Starting Full client...Copy the code

After a node is started, two blockchain_data folders are created in the run directory and log are used to store node data and logs.

After starting a new main network or test network node, it will synchronize historical block data from the network, and the nodes in the catch-up mode will be in catch up mode. You can see the status of the node and the latest epoch number from the log:

2021-04-16T14:49:11.896942+08:00 INFO IO Worker #1 CFxcore :: syn-catch-up mode: true, latest epoch: 102120 missing_bodies: 0 2021-04-16T14:49:12.909607+08:00 INFO IO Worker #3 cfxcore:: syn-catch-up mode: true, latest epoch: 102120 missing_bodies: 0 2021-04-16T14:49:13.922918+08:00 INFO IO Worker #1 cfxcore:: syn-catch-up mode: true, latest epoch: 102120 missing_bodies: 0 2021-04-16T14:49:14.828910+08:00 INFO IO Worker #1 cfxcore:: syn-catch-up mode: true, latest epoch: 102180 missing_bodies: 0Copy the code

You can also use the cfx_getStatus method to obtain the latest epochNumber of the current node and compare it with the latest EPOCH of scan to determine whether the data has been synchronized to the latest.

The RPC service

After the node is started and rPC-related port numbers and configurations are enabled, the wallet and Dapp can access the node through the RPC URL. For example,

http://node-ip:12537

This address can be used when adding networks to the Portal wallet, or when adding SDK instances.

Run nodes using Docker

Friends who are familiar with Docker can also use Docker to run a node. All versions of Docker Image can be pulled and run by themselves.

Since the node data is large, it is recommended to mount a data directory to store node data when running image.

There are currently three piplines for the mirrored tag:

  • x.x.x-mainnet: Primary network mirroring
  • x.x.x-testnet: Tests network mirroring
  • x.x.x: Development mode mirroring. In this mode, ten accounts are automatically initialized for rapid local development

Q&A

Why does synchronization take a long time after restart?

After a node is restarted, it synchronizes data from the last checkpoint and replays block data. The synchronization starts from the latest block after the node is synchronized according to the distance to the last checkpoint. This is a normal phenomenon, generally will wait a few minutes to more than ten minutes.

Why does the node sync block height become stuck master and no longer grow?

Block Through the card master, you can check whether there is any error in the log or terminal. If there is no error, it is most likely due to network reasons, you can try to restart the node.

After the configuration is modified, do I need to know the data before restarting the node?

Depending on the situation, some need, some don’t need. If the configuration involves data stores or data indexes, you need to restart the node if the configuration changes, for example:

  • persist_tx_index
  • executive_trace
  • persist_block_number_index

Other configurations are generally not required.

How big is the current Archive Node data?

Up to 2021.11.04 block data compression package size is less than 90 G

How to get involved in mining?

Mining requires GPU participation, see here for details

How do I quickly synchronize data to run an Archive node

You can use the fullnode-node command to download the snapshot of archive node data. The node data can be quickly synchronized to the latest data.

How do I run a PoS node?

TO BE UPDATE

reference

  • Official run node documentation
  • Node program source code

How do I run a Conflux node