Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: remove useless fields in BlockHeader #1339

Merged
merged 4 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions core/run/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ const TESTCASES: &[TestCase] = &[
chain_name: "single_node",
config_file: "config.toml",
chain_spec_file: "specs/single_node/chain-spec.toml",
input_genesis_hash: "0x2cc987996d5d26d18cb76dceb85d9b46e4f05f11ff331247225d983ec7a7b78f",
input_genesis_hash: "0x2043f690fc6e086c6940a083072a82dee16c18a4c4afaf6f4e1c7a585fae2543",
genesis_state_root: "0x65f57a6a666e656de33ed68957e04b35b3fe1b35a90f6eafb6f283c907dc3d77",
genesis_receipts_root: "0x8544b530238201f1620b139861a6841040b37f78f8bdae8736ef5cec474e979b",
},
TestCase {
chain_name: "multi_nodes",
config_file: "nodes/node_1.toml",
chain_spec_file: "specs/multi_nodes/chain-spec.toml",
input_genesis_hash: "0xcb35c763bcfc5c68e2b4435d9eec7753190384b3af032c7a951f413d05db04c1",
input_genesis_hash: "0x5e5c47725bb1face59965a326b1d69e1ada1892da2e2f53c4520ed5da3d88d59",
genesis_state_root: "0x7b288320399a1b1f2d6b1483b473e0067a7ff8358f927bb2a09ce6f463eb0208",
genesis_receipts_root: "0x8544b530238201f1620b139861a6841040b37f78f8bdae8736ef5cec474e979b",
},
TestCase {
chain_name: "multi_nodes_short_epoch_len",
config_file: "nodes/node_1.toml",
chain_spec_file: "specs/multi_nodes_short_epoch_len/chain-spec.toml",
input_genesis_hash: "0x2cc987996d5d26d18cb76dceb85d9b46e4f05f11ff331247225d983ec7a7b78f",
input_genesis_hash: "0x2043f690fc6e086c6940a083072a82dee16c18a4c4afaf6f4e1c7a585fae2543",
genesis_state_root: "0x815c8fa8d46aac47f789611a21abb8e43e69b04425c80f9b2c425d5a2575d32c",
genesis_receipts_root: "0x8544b530238201f1620b139861a6841040b37f78f8bdae8736ef5cec474e979b",
},
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
2 changes: 1 addition & 1 deletion protocol/src/types/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl From<Proposal> for ExecutorContext {
block_coinbase: h.proposer,
block_timestamp: h.timestamp.into(),
chain_id: h.chain_id.into(),
difficulty: U256::one(),
difficulty: U256::zero(),
origin: h.proposer,
gas_price: U256::one(),
block_gas_limit: h.gas_limit,
Expand Down