Skip to main content

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    /// Optional bearer token to authenticate block-template notifications.
31    ///
32    /// When `listen` is set and this token is configured, incoming notify
33    /// requests must include the header `Authorization: Bearer <token>`.
34    /// If `listen` is set but this token is not configured, ckb-miner will
35    /// accept any request that deserializes as a BlockTemplate, which can be
36    /// abused if the notify endpoint is reachable by untrusted parties.
37    ///
38    /// Must be non-empty and free of leading/trailing whitespace; ckb-miner
39    /// refuses to start otherwise.
40    pub auth_token: Option<String>,
41}
42
43/// Miner worker config options.
44#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
45#[serde(tag = "worker_type")]
46pub enum WorkerConfig {
47    /// Dummy worker which submits an arbitrary answer.
48    Dummy(DummyConfig),
49    /// Eaglesong worker which solves Eaglesong PoW.
50    EaglesongSimple(EaglesongSimpleConfig),
51}
52
53/// Dummy worker config options.
54///
55/// Dummy worker can submit the new block at any time. This controls the pace that how much time
56/// the worker must wait before submitting a new block.
57#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
58#[serde(tag = "delay_type")]
59pub enum DummyConfig {
60    /// Waits for a constant delay.
61    Constant {
62        /// The delay in seconds.
63        value: u64,
64    },
65    /// Waits for a time which is uniformly sampled from a range.
66    Uniform {
67        /// The lower bound of the range (in seconds).
68        low: u64,
69        /// The upper bound of the range (in seconds).
70        high: u64,
71    },
72    /// Picks the wait time from a normal distribution.
73    Normal {
74        /// The mean of the distribution (in seconds).
75        mean: f64,
76        /// The standard deviation.
77        std_dev: f64,
78    },
79    /// Picks the wait time from a poisson distribution.
80    Poisson {
81        /// The parameter lambda of the poisson distribution.
82        lambda: f64,
83    },
84}
85
86/// Eaglesong worker config options.
87#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Eq)]
88#[serde(deny_unknown_fields)]
89pub struct EaglesongSimpleConfig {
90    /// Number of worker threads.
91    pub threads: usize,
92    /// Whether to perform an extra round of hash function on the Eaglesong output.
93    #[serde(default)]
94    pub extra_hash_function: Option<ExtraHashFunction>,
95}
96
97/// Specifies the hash function.
98#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq)]
99pub enum ExtraHashFunction {
100    /// Blake2b hash with CKB preferences.
101    Blake2b,
102}