ckb_types/core/
reward.rs

1use crate::{core::Capacity, packed::Byte32};
2
3/// Details of miner rewards issued by block cellbase transaction.
4///
5/// # References:
6/// - [Token Issuance](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0015-ckb-cryptoeconomics/0015-ckb-cryptoeconomics.md#token-issuance)
7/// - [Miner Compensation](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0015-ckb-cryptoeconomics/0015-ckb-cryptoeconomics.md#miner-compensation)
8/// - [Paying for Transaction Fees](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0015-ckb-cryptoeconomics/0015-ckb-cryptoeconomics.md#paying-for-transaction-fees)
9/// - [`RewardCalculator::txs_fee(..)`](../../ckb_reward_calculator/struct.RewardCalculator.html#method.txs_fees)
10/// - [Collecting State Rent with Secondary Issuance and the NervosDAO](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0015-ckb-cryptoeconomics/0015-ckb-cryptoeconomics.md#collecting-state-rent-with-secondary-issuance-and-the-nervosdao)
11/// - [Calculation of Nervos DAO and Examples](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0023-dao-deposit-withdraw/0023-dao-deposit-withdraw.md#calculation)
12#[derive(Debug, Default)]
13pub struct BlockReward {
14    /// The total block reward.
15    pub total: Capacity,
16    /// The primary block reward.
17    pub primary: Capacity,
18    /// The secondary block reward.
19    ///
20    /// # Notice
21    ///
22    /// - A part of the secondary issuance goes to the miners, the ratio depends on how many CKB
23    ///   are used to store state.
24    /// - And a part of the secondary issuance goes to the NervosDAO, the ratio depends on how many
25    ///   CKB are deposited and locked in the NervosDAO.
26    /// - The rest of the secondary issuance is determined by the community through the governance
27    ///   mechanism.
28    ///   Before the community can reach agreement, this part of the secondary issuance is going to
29    ///   be burned.
30    pub secondary: Capacity,
31    /// The transaction fees that are rewarded to miners because the transaction is committed in
32    /// the block.
33    ///
34    /// # Notice
35    ///
36    /// Miners only get 60% of the transaction fee for each transaction committed in the block.
37    pub tx_fee: Capacity,
38    /// The transaction fees that are rewarded to miners because the transaction is proposed in the
39    /// block or its uncles.
40    ///
41    /// # Notice
42    ///
43    /// Miners only get 40% of the transaction fee for each transaction proposed in the block
44    /// and committed later in its active commit window.
45    pub proposal_reward: Capacity,
46}
47
48/// Native token issuance.
49///
50/// # References:
51/// - [Token Issuance](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0015-ckb-cryptoeconomics/0015-ckb-cryptoeconomics.md#token-issuance)
52#[derive(Debug, Default, PartialEq, Eq)]
53pub struct BlockIssuance {
54    /// The primary issuance.
55    pub primary: Capacity,
56    /// The secondary issuance.
57    pub secondary: Capacity,
58}
59
60/// Miner reward.
61///
62/// # References:
63/// - [Token Issuance](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0015-ckb-cryptoeconomics/0015-ckb-cryptoeconomics.md#token-issuance)
64/// - [Miner Compensation](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0015-ckb-cryptoeconomics/0015-ckb-cryptoeconomics.md#miner-compensation)
65/// - [Paying for Transaction Fees](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0015-ckb-cryptoeconomics/0015-ckb-cryptoeconomics.md#paying-for-transaction-fees)
66/// - [`RewardCalculator::txs_fee(..)`](../../ckb_reward_calculator/struct.RewardCalculator.html#method.txs_fees)
67#[derive(Debug, Default, PartialEq, Eq)]
68pub struct MinerReward {
69    /// The miner receives all the primary issuance.
70    pub primary: Capacity,
71    /// The miner receives part of the secondary issuance.
72    pub secondary: Capacity,
73    /// The miner receives 60% of the transaction fee for each transaction committed in the block.
74    pub committed: Capacity,
75    /// The miner receives 40% of the transaction fee for each transaction proposed in the block,
76    /// and committed later in its active commit window.
77    pub proposal: Capacity,
78}
79
80/// Includes the rewards details for a block and when the block is finalized.
81#[derive(Debug, Default, PartialEq, Eq)]
82pub struct BlockEconomicState {
83    /// Native token issuance in the block.
84    pub issuance: BlockIssuance,
85    /// Miner reward in the block.
86    pub miner_reward: MinerReward,
87    /// The total fees of all transactions committed in the block.
88    pub txs_fee: Capacity,
89    ///  The block hash of the block which creates the rewards as cells in its cellbase
90    ///  transaction.
91    pub finalized_at: Byte32,
92}
93
94impl From<BlockReward> for MinerReward {
95    fn from(reward: BlockReward) -> Self {
96        Self {
97            primary: reward.primary,
98            secondary: reward.secondary,
99            committed: reward.tx_fee,
100            proposal: reward.proposal_reward,
101        }
102    }
103}