zebra_rpc/config/mining.rs
1//! Mining config
2
3use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6use serde_with::{serde_as, DisplayFromStr};
7
8use strum_macros::EnumIter;
9use zcash_address::ZcashAddress;
10use zebra_chain::parameters::NetworkKind;
11
12/// Mining configuration section.
13#[serde_as]
14#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
15#[serde(deny_unknown_fields, default)]
16pub struct Config {
17 /// Address for receiving miner subsidy and tx fees.
18 ///
19 /// Used in coinbase tx constructed in `getblocktemplate` RPC.
20 #[serde_as(as = "Option<DisplayFromStr>")]
21 pub miner_address: Option<ZcashAddress>,
22
23 /// Optional data that Zebra will include in the transparent input of a coinbase transaction.
24 /// Limited to 94 bytes.
25 ///
26 /// If this string is hex-encoded, it will be hex-decoded into bytes. Otherwise, it will be
27 /// UTF-8 encoded into bytes.
28 pub extra_coinbase_data: Option<String>,
29
30 /// Optional shielded memo that Zebra will include in the output of a shielded coinbase
31 /// transaction. Limited to 512 bytes.
32 ///
33 /// Applies only if [`Self::miner_address`] contains a shielded component.
34 pub miner_memo: Option<String>,
35
36 /// Mine blocks using Zebra's internal miner, without an external mining pool or equihash solver.
37 ///
38 /// This experimental feature is only supported on regtest as it uses null solutions and skips checking
39 /// for a valid Proof of Work.
40 ///
41 /// The internal miner is off by default.
42 #[serde(default)]
43 pub internal_miner: bool,
44}
45
46impl Config {
47 /// Is the internal miner enabled using at least one thread?
48 #[cfg(feature = "internal-miner")]
49 pub fn is_internal_miner_enabled(&self) -> bool {
50 // TODO: Changed to return always false so internal miner is never started. Part of https://github.com/ZcashFoundation/zebra/issues/8180
51 // Find the removed code at https://github.com/ZcashFoundation/zebra/blob/v1.5.1/zebra-rpc/src/config/mining.rs#L83
52 // Restore the code when conditions are met. https://github.com/ZcashFoundation/zebra/issues/8183
53 self.internal_miner
54 }
55}
56
57/// The desired address type for the `mining.miner_address` field in the config.
58#[derive(EnumIter, Eq, PartialEq, Default, Hash)]
59pub enum MinerAddressType {
60 /// A unified address, containing the components of all the other address types.
61 Unified,
62 /// A Sapling address.
63 Sapling,
64 /// A transparent address.
65 #[default]
66 Transparent,
67}
68
69/// Returns the hard-coded default miner address string for a given network and address type.
70///
71/// All addresses come from a single address:
72///
73/// - addresses for different networks are only different encodings of the same address;
74/// - addresses of different types are components of the same unified address.
75pub fn default_miner_address(kind: NetworkKind, addr_type: &MinerAddressType) -> &'static str {
76 MINER_ADDRESS[&kind][addr_type]
77}
78
79lazy_static::lazy_static! {
80 static ref MINER_ADDRESS: HashMap<NetworkKind, HashMap<MinerAddressType, &'static str>> = [
81 (NetworkKind::Mainnet, [
82 (MinerAddressType::Unified, "u1cymdny2u2vllkx7t5jnelp0kde0dgnwu0jzmggzguxvxj6fe7gpuqehywejndlrjwgk9snr6g69azs8jfet78s9zy60uepx6tltk7ee57jlax49dezkhkgvjy2puuue6dvaevt53nah7t2cc2k4p0h0jxmlu9sx58m2xdm5f9sy2n89jdf8llflvtml2ll43e334avu2fwytuna404a"),
83 // (MinerAddressType::Orchard, "u1hmfjpqdxaec3mvqypl7fkqcy53u438csydljpuepsfs7jx6sjwyznuzlna8qsslj3tg6sn9ua4q653280aqv4m2fjd4csptwxq3fjpwy"),
84 (MinerAddressType::Sapling, "zs1xl84ekz6stprmvrp39s77mf9t953nqjndwlcjtzfrr3cgjjez87639xm4u9pfuvylrhec3uryy5"),
85 (MinerAddressType::Transparent, "t1T92bmyoPM7PTSWUnaWnLGcxkF6Jp1AwMY"),
86 ].into()),
87 (NetworkKind::Testnet, [
88 (MinerAddressType::Unified, "utest10a8k6aw5w33kvyt7x6fryzu7vvsjru5vgcfnvr288qx2zm6p63ygcajtaze0px08t583dyrgr42vasazjhhnntus2tqrpkzu0dm2l4cgf3ld6wdqdrf3jv8mvfx9c80e73syer9l2wlgawjtf7yvj0eqwdf354trtelxnr0fhpw9792eaf49ghstkyftc9lwqqwy4ye0cleagp4nzyt"),
89 // (MinerAddressType::Orchard, "utest10zg6frxk32ma8980kdv9473e4aclw7clq9hydzcj6l349pkqzxk2mmj3cn7j5x38w6l4wyryv50whnlrw0k9agzpdf5fxyj7kq96ukcp"),
90 (MinerAddressType::Sapling, "ztestsapling1xl84ekz6stprmvrp39s77mf9t953nqjndwlcjtzfrr3cgjjez87639xm4u9pfuvylrhecet38rq"),
91 (MinerAddressType::Transparent, "tmJymvcUCn1ctbghvTJpXBwHiMEB8P6wxNV"),
92 ].into()),
93 (NetworkKind::Regtest, [
94 (MinerAddressType::Unified, "uregtest1efxggx6lduhm2fx5lnrhxv7h7kpztlpa3ahf3n4w0q0zj5epj4av9xjq6ljsja3xk8z7rzd067kc7mgpy9448rdfzpfjz5gq389zdmpgnk6rp4ykk0xk6cmqw6zqcrnmsuaxv3yzsvcwsd4gagtalh0uzrdvy03nhmltjz2eu0232qlcs0zvxuqyut73yucd9gy5jaudnyt7yqhgpqv"),
95 // (MinerAddressType::Orchard, "uregtest1pszqlgxaf5w8mu2yd9uygg8cswp0ec4f7eejqnqc35tztw4tk0sxnt3pym2f3s2872cy2ruuc5n8y9cen5q6ngzlmzu8ztrjesv8zm9j"),
96 (MinerAddressType::Sapling, "zregtestsapling1xl84ekz6stprmvrp39s77mf9t953nqjndwlcjtzfrr3cgjjez87639xm4u9pfuvylrhecx0c2j8"),
97 (MinerAddressType::Transparent, "tmJymvcUCn1ctbghvTJpXBwHiMEB8P6wxNV"),
98 ].into()),
99 ].into();
100}