ckb_app_config/configs/
miner.rs

1use serde::{Deserialize, Serialize};
2use std::net::SocketAddr;
3
4/// Miner config options.
5#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
6#[serde(deny_unknown_fields)]
7pub struct Config {
8    /// RPC client config options.
9    ///
10    /// Miner connects to CKB node via RPC.
11    pub client: ClientConfig,
12    /// Miner workers config options.
13    pub workers: Vec<WorkerConfig>,
14}
15
16/// RPC client config options.
17#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Eq)]
18#[serde(deny_unknown_fields)]
19pub struct ClientConfig {
20    /// CKB node RPC endpoint.
21    pub rpc_url: String,
22    /// The poll interval in seconds to get work from the CKB node.
23    pub poll_interval: u64,
24    /// By default, miner submits a block and continues to get the next work.
25    ///
26    /// When this is enabled, miner will block until the submission RPC returns.
27    pub block_on_submit: bool,
28    /// listen block_template notify instead of loop poll
29    pub listen: Option<SocketAddr>,
30}
31
32/// Miner worker config options.
33#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
34#[serde(tag = "worker_type")]
35pub enum WorkerConfig {
36    /// Dummy worker which submits an arbitrary answer.
37    Dummy(DummyConfig),
38    /// Eaglesong worker which solves Eaglesong PoW.
39    EaglesongSimple(EaglesongSimpleConfig),
40}
41
42/// Dummy worker config options.
43///
44/// Dummy worker can submit the new block at any time. This controls the pace that how much time
45/// the worker must wait before submitting a new block.
46#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
47#[serde(tag = "delay_type")]
48pub enum DummyConfig {
49    /// Waits for a constant delay.
50    Constant {
51        /// The delay in seconds.
52        value: u64,
53    },
54    /// Waits for a time which is uniformly sampled from a range.
55    Uniform {
56        /// The lower bound of the range (in seconds).
57        low: u64,
58        /// The upper bound of the range (in seconds).
59        high: u64,
60    },
61    /// Picks the wait time from a normal distribution.
62    Normal {
63        /// The mean of the distribution (in seconds).
64        mean: f64,
65        /// The standard deviation.
66        std_dev: f64,
67    },
68    /// Picks the wait time from a poisson distribution.
69    Poisson {
70        /// The parameter lambda of the poisson distribution.
71        lambda: f64,
72    },
73}
74
75/// Eaglesong worker config options.
76#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Eq)]
77#[serde(deny_unknown_fields)]
78pub struct EaglesongSimpleConfig {
79    /// Number of worker threads.
80    pub threads: usize,
81    /// Whether to perform an extra round of hash function on the Eaglesong output.
82    #[serde(default)]
83    pub extra_hash_function: Option<ExtraHashFunction>,
84}
85
86/// Specifies the hash function.
87#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq)]
88pub enum ExtraHashFunction {
89    /// Blake2b hash with CKB preferences.
90    Blake2b,
91}