Skip to content

Commit

Permalink
refactor: remove useless fields in BlockHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason committed Aug 21, 2023
1 parent 1d89fa1 commit 7841c3d
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 35 deletions.
9 changes: 1 addition & 8 deletions core/api/src/jsonrpc/impl/web3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use protocol::traits::{APIAdapter, Context, Interoperation};
use protocol::types::{
Block, BlockNumber, Bytes, CellDepWithPubKey, Hash, Hasher, Header, Hex, Proposal, Receipt,
SignatureComponents, SignatureR, SignatureS, SignedTransaction, TxResp, UnverifiedTransaction,
BASE_FEE_PER_GAS, H160, H256, H64, MAX_FEE_HISTORY, MAX_RPC_GAS_CAP, MIN_TRANSACTION_GAS_LIMIT,
BASE_FEE_PER_GAS, H160, H256, MAX_FEE_HISTORY, MAX_RPC_GAS_CAP, MIN_TRANSACTION_GAS_LIMIT,
U256,
};
use protocol::{
Expand Down Expand Up @@ -1166,7 +1166,6 @@ fn mock_header_by_call_req(latest_header: Header, call_req: &Web3CallRequest) ->
signed_txs_hash: Default::default(),
receipts_root: Default::default(),
log_bloom: Default::default(),
difficulty: latest_header.difficulty,
timestamp: latest_header.timestamp,
number: latest_header.number,
gas_used: latest_header.gas_used,
Expand All @@ -1176,12 +1175,6 @@ fn mock_header_by_call_req(latest_header: Header, call_req: &Web3CallRequest) ->
latest_header.gas_limit
},
extra_data: Default::default(),
mixed_hash: None,
nonce: if let Some(nonce) = call_req.nonce {
H64::from_low_u64_le(nonce.as_u64())
} else {
latest_header.nonce
},
base_fee_per_gas: if let Some(base_fee) = call_req.max_fee_per_gas {
base_fee
} else {
Expand Down
4 changes: 2 additions & 2 deletions core/api/src/jsonrpc/web3_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl From<Block> for Web3Block {
state_root: b.header.state_root,
receipts_root: b.header.receipts_root,
miner: b.header.proposer,
difficulty: b.header.difficulty,
difficulty: U256::zero(),
total_difficulty: Some(U256::zero()),
seal_fields: vec![],
base_fee_per_gas: b.header.base_fee_per_gas,
Expand Down Expand Up @@ -839,7 +839,7 @@ impl From<Header> for Web3Header {
state_root: h.state_root,
receipts_root: h.receipts_root,
miner: h.proposer,
difficulty: h.difficulty,
difficulty: U256::zero(),
extra_data: Hex::encode(&h.extra_data),
gas_limit: h.gas_limit,
gas_used: h.gas_used,
Expand Down
1 change: 0 additions & 1 deletion core/consensus/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ impl<Adapter: ConsensusAdapter + 'static> Engine<Proposal> for ConsensusEngine<A
number: next_number,
gas_limit: MAX_BLOCK_GAS_LIMIT.into(),
extra_data: Default::default(),
mixed_hash: None,
base_fee_per_gas: BASE_FEE_PER_GAS.into(),
proof: status.proof,
chain_id: self.node_info.chain_id,
Expand Down
3 changes: 0 additions & 3 deletions core/consensus/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ fn _mock_block_from_status(status: &CurrentStatus) -> Block {
proposer: _mock_address().0,
proof: _mock_proof(status.last_number),
log_bloom: Default::default(),
difficulty: Default::default(),
extra_data: Default::default(),
mixed_hash: Default::default(),
nonce: Default::default(),
base_fee_per_gas: Default::default(),
call_system_script_count: 0,
};
Expand Down
3 changes: 0 additions & 3 deletions core/consensus/src/tests/synchronization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ pub fn get_mock_rick_block() -> RichBlock {
signed_txs_hash: Default::default(),
receipts_root: Default::default(),
log_bloom: Default::default(),
difficulty: Default::default(),
timestamp: time_now(),
number: 1,
gas_used: Default::default(),
gas_limit: Default::default(),
extra_data: Default::default(),
mixed_hash: Default::default(),
nonce: Default::default(),
base_fee_per_gas: Default::default(),
proof: Default::default(),
call_system_script_count: 0,
Expand Down
1 change: 0 additions & 1 deletion core/interoperation/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ fn mock_proposal() -> Proposal {
number: Default::default(),
gas_limit: 1000000000u64.into(),
extra_data: Default::default(),
mixed_hash: Default::default(),
base_fee_per_gas: U256::one(),
proof: Default::default(),
chain_id: Default::default(),
Expand Down
3 changes: 0 additions & 3 deletions core/storage/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,11 @@ fn mock_block(height: u64, _block_hash: Hash) -> Block {
signed_txs_hash: Default::default(),
receipts_root: Default::default(),
log_bloom: Default::default(),
difficulty: Default::default(),
timestamp: 0,
number: height,
gas_used: Default::default(),
gas_limit: Default::default(),
extra_data: Default::default(),
mixed_hash: None,
nonce: Default::default(),
base_fee_per_gas: Default::default(),
proof: Proof::default(),
call_system_script_count: 1,
Expand Down
1 change: 0 additions & 1 deletion protocol/src/codec/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ impl Decodable for Proposal {
number: r.val_at(7)?,
gas_limit: MAX_BLOCK_GAS_LIMIT.into(),
extra_data: Default::default(),
mixed_hash: None,
base_fee_per_gas: BASE_FEE_PER_GAS.into(),
proof: r.val_at(8)?,
chain_id: **CHAIN_ID.load(),
Expand Down
14 changes: 1 addition & 13 deletions protocol/src/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use crate::codec::{serialize_bytes, serialize_uint};
use crate::types::{
logs_bloom, Bloom, BloomInput, Bytes, ExecResp, Hash, Hasher, Log, MerkleRoot, Receipt,
SignedTransaction, H160, H64, U256,
SignedTransaction, H160, U256,
};
use crate::{codec::ProtocolCodec, types::TypesError};

Expand Down Expand Up @@ -59,7 +59,6 @@ pub struct Proposal {
pub gas_limit: U256,
#[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_bytes"))]
pub extra_data: Bytes,
pub mixed_hash: Option<Hash>,
pub base_fee_per_gas: U256,
pub proof: Proof,
#[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))]
Expand All @@ -86,7 +85,6 @@ impl Proposal {
number: h.number,
gas_limit: h.gas_limit,
extra_data: h.extra_data.clone(),
mixed_hash: h.mixed_hash,
base_fee_per_gas: h.base_fee_per_gas,
proof: h.proof.clone(),
chain_id: h.chain_id,
Expand All @@ -107,7 +105,6 @@ impl Proposal {
number: h.number,
gas_limit: h.gas_limit,
extra_data: h.extra_data.clone(),
mixed_hash: h.mixed_hash,
base_fee_per_gas: h.base_fee_per_gas,
proof: h.proof.clone(),
chain_id: h.chain_id,
Expand Down Expand Up @@ -148,14 +145,11 @@ impl Block {
log_bloom: Bloom::from(BloomInput::Raw(
rlp::encode_list(&logs).as_ref(),
)),
difficulty: U256::one(),
timestamp: proposal.timestamp,
number: proposal.number,
gas_used: exec_resp.gas_used.into(),
gas_limit: proposal.gas_limit,
extra_data: proposal.extra_data,
mixed_hash: proposal.mixed_hash,
nonce: Default::default(),
base_fee_per_gas: proposal.base_fee_per_gas,
proof: proposal.proof,
call_system_script_count: proposal.call_system_script_count,
Expand Down Expand Up @@ -219,7 +213,6 @@ pub struct Header {
pub signed_txs_hash: Hash,
pub receipts_root: MerkleRoot,
pub log_bloom: Bloom,
pub difficulty: U256,
#[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))]
pub timestamp: u64,
#[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))]
Expand All @@ -228,8 +221,6 @@ pub struct Header {
pub gas_limit: U256,
#[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_bytes"))]
pub extra_data: Bytes,
pub mixed_hash: Option<Hash>,
pub nonce: H64,
pub base_fee_per_gas: U256,
pub proof: Proof,
#[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))]
Expand Down Expand Up @@ -315,14 +306,11 @@ mod tests {
signed_txs_hash: Default::default(),
receipts_root: Default::default(),
log_bloom: Default::default(),
difficulty: Default::default(),
timestamp: time_now(),
number: 0,
gas_used: Default::default(),
gas_limit: Default::default(),
extra_data: Default::default(),
mixed_hash: Default::default(),
nonce: Default::default(),
base_fee_per_gas: Default::default(),
proof: Default::default(),
call_system_script_count: 0,
Expand Down

0 comments on commit 7841c3d

Please sign in to comment.