cfx_internal_common/debug/
mod.rs

1// Copyright 2019 Conflux Foundation. All rights reserved.
2// Conflux is free software and distributed under GNU General Public License.
3// See http://www.gnu.org/licenses/
4
5#[derive(Debug, Serialize, Deserialize)]
6pub struct BlockHashAuthorValue<ValueType>(
7    pub H256,
8    pub Address,
9    pub ValueType,
10);
11
12//#[derive(Debug, Serialize, Deserialize)]
13//pub struct BlockHashValue<ValueType>(pub H256, pub ValueType);
14
15#[derive(Debug, Serialize, Deserialize)]
16pub struct AuthorValue<ValueType>(pub Address, pub ValueType);
17
18#[derive(Debug, Serialize, Deserialize)]
19pub struct ComputeEpochDebugRecord {
20    // Basic information.
21    pub block_height: u64,
22    pub block_hash: H256,
23    pub parent_epoch_hash: H256,
24    pub parent_state_root: StateRootWithAuxInfo,
25    pub reward_epoch_hash: Option<H256>,
26    pub anticone_penalty_cutoff_epoch_hash: Option<H256>,
27
28    // Blocks.
29    pub block_hashes: Vec<H256>,
30    pub block_txs: Vec<usize>,
31    pub transactions: Vec<Arc<SignedTransaction>>,
32
33    // Rewards. Rewards for anticone overlimit blocks may be skipped.
34    pub block_authors: Vec<Address>,
35    pub no_reward_blocks: Vec<H256>,
36    pub block_rewards: Vec<BlockHashAuthorValue<U256>>,
37    pub anticone_penalties: Vec<BlockHashAuthorValue<U256>>,
38    // pub anticone_set_size: Vec<BlockHashValue<usize>>,
39    pub tx_fees: Vec<BlockHashAuthorValue<U256>>,
40    pub secondary_rewards: Vec<BlockHashAuthorValue<U256>>,
41    pub block_final_rewards: Vec<BlockHashAuthorValue<U256>>,
42    pub merged_rewards_by_author: Vec<AuthorValue<U256>>,
43
44    // State root sequence.
45    // TODO: the fields below are not yet filled for debugging.
46    pub delta_roots_post_tx: Vec<H256>,
47    pub state_root_after_applying_rewards: StateRootWithAuxInfo,
48
49    // Storage operations.
50    // op name, key, maybe_value
51    pub state_ops: Vec<StateOp>,
52}
53
54#[derive(Debug, Serialize, Deserialize)]
55pub enum StateOp {
56    IncentiveLevelOp {
57        op_name: String,
58        key: Vec<u8>,
59        maybe_value: Option<Vec<u8>>,
60    },
61    StorageLevelOp {
62        op_name: String,
63        key: Vec<u8>,
64        maybe_value: Option<Vec<u8>>,
65    },
66}
67
68impl Default for ComputeEpochDebugRecord {
69    fn default() -> Self {
70        Self {
71            block_hash: Default::default(),
72            block_height: 0,
73            parent_epoch_hash: Default::default(),
74            parent_state_root: StateRootWithAuxInfo::genesis(
75                &Default::default(),
76            ),
77            reward_epoch_hash: None,
78            anticone_penalty_cutoff_epoch_hash: None,
79            block_hashes: Default::default(),
80            block_txs: Default::default(),
81            transactions: Default::default(),
82            block_authors: Default::default(),
83            no_reward_blocks: Default::default(),
84            block_rewards: Default::default(),
85            anticone_penalties: Default::default(),
86            tx_fees: Default::default(),
87            secondary_rewards: Default::default(),
88            block_final_rewards: Default::default(),
89            merged_rewards_by_author: Default::default(),
90            delta_roots_post_tx: Default::default(),
91            state_root_after_applying_rewards: StateRootWithAuxInfo::genesis(
92                &Default::default(),
93            ),
94            state_ops: Default::default(),
95        }
96    }
97}
98
99use crate::StateRootWithAuxInfo;
100use cfx_types::{Address, H256, U256};
101use primitives::SignedTransaction;
102use serde_derive::{Deserialize, Serialize};
103use std::{sync::Arc, vec::Vec};