zebra_rpc/methods/types/get_block_template/constants.rs
1//! Constant values used in mining rpcs methods.
2
3use jsonrpsee_types::ErrorCode;
4
5use zebra_chain::{
6 block,
7 parameters::subsidy::FundingStreamReceiver::{self, *},
8};
9
10/// When long polling, the amount of time we wait between mempool queries.
11/// (And sync status queries, which we do right before mempool queries.)
12///
13/// State tip changes make long polling return immediately. But miners can re-use old work
14/// with an old set of transactions, so they don't need to know about mempool changes immediately.
15///
16/// Sync status changes are rare, and the blocks they download cause a chain tip change anyway.
17///
18/// `zcashd` waits 10 seconds between checking the state
19/// <https://github.com/zcash/zcash/blob/420f8dfe38fd6b2465a665324366c2ae14aa98f4/src/rpc/mining.cpp#L626>
20pub const MEMPOOL_LONG_POLL_INTERVAL: u64 = 5;
21
22/// A range of valid block template nonces, that goes from `u32::MIN` to `u32::MAX` as a string.
23pub const NONCE_RANGE_FIELD: &str = "00000000ffffffff";
24
25/// A hardcoded list of fields that the miner can change from the block template.
26///
27/// <https://en.bitcoin.it/wiki/BIP_0023#Mutations>
28pub const MUTABLE_FIELD: &[&str] = &[
29 // Standard mutations, copied from zcashd
30 "time",
31 "transactions",
32 "prevblock",
33];
34
35/// A hardcoded list of Zebra's getblocktemplate RPC capabilities.
36///
37/// <https://en.bitcoin.it/wiki/BIP_0023#Block_Proposal>
38pub const CAPABILITIES_FIELD: &[&str] = &["proposal"];
39
40/// The max estimated distance to the chain tip for the getblocktemplate method.
41///
42/// Allows the same clock skew as the Zcash network, which is 100 blocks, based on the standard rule:
43/// > A full validator MUST NOT accept blocks with nTime more than two hours in the future
44/// > according to its clock. This is not strictly a consensus rule because it is nondeterministic,
45/// > and clock time varies between nodes.
46/// >
47/// > <https://zips.z.cash/protocol/protocol.pdf#blockheader>
48pub const MAX_ESTIMATED_DISTANCE_TO_NETWORK_CHAIN_TIP: block::HeightDiff = 100;
49
50/// The RPC error code used by `zcashd` for when it's still downloading initial blocks.
51///
52/// `s-nomp` mining pool expects error code `-10` when the node is not synced:
53/// <https://github.com/s-nomp/node-stratum-pool/blob/d86ae73f8ff968d9355bb61aac05e0ebef36ccb5/lib/pool.js#L142>
54pub const NOT_SYNCED_ERROR_CODE: ErrorCode = ErrorCode::ServerError(-10);
55
56/// The default window size specifying how many blocks to check when estimating the chain's solution rate.
57///
58/// Based on default value in zcashd.
59pub const DEFAULT_SOLUTION_RATE_WINDOW_SIZE: i32 = 120;
60
61/// The funding stream order in `zcashd` RPC responses.
62///
63/// [`zcashd`]: https://github.com/zcash/zcash/blob/3f09cfa00a3c90336580a127e0096d99e25a38d6/src/consensus/funding.cpp#L13-L32
64pub const ZCASHD_FUNDING_STREAM_ORDER: &[FundingStreamReceiver] =
65 &[Ecc, ZcashFoundation, MajorGrants];