From 7841c3d7da8f4e14d792ba6bf1e1db3dcce6dca8 Mon Sep 17 00:00:00 2001 From: Eason Date: Mon, 21 Aug 2023 00:29:03 +0800 Subject: [PATCH 1/4] refactor: remove useless fields in BlockHeader --- core/api/src/jsonrpc/impl/web3.rs | 9 +-------- core/api/src/jsonrpc/web3_types.rs | 4 ++-- core/consensus/src/engine.rs | 1 - core/consensus/src/tests/mod.rs | 3 --- core/consensus/src/tests/synchronization.rs | 3 --- core/interoperation/src/tests/mod.rs | 1 - core/storage/src/tests/mod.rs | 3 --- protocol/src/codec/block.rs | 1 - protocol/src/types/block.rs | 14 +------------- 9 files changed, 4 insertions(+), 35 deletions(-) diff --git a/core/api/src/jsonrpc/impl/web3.rs b/core/api/src/jsonrpc/impl/web3.rs index c47590c1b..48a928b2a 100644 --- a/core/api/src/jsonrpc/impl/web3.rs +++ b/core/api/src/jsonrpc/impl/web3.rs @@ -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::{ @@ -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, @@ -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 { diff --git a/core/api/src/jsonrpc/web3_types.rs b/core/api/src/jsonrpc/web3_types.rs index ac62a306f..b091eeb6d 100644 --- a/core/api/src/jsonrpc/web3_types.rs +++ b/core/api/src/jsonrpc/web3_types.rs @@ -318,7 +318,7 @@ impl From 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, @@ -839,7 +839,7 @@ impl From
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, diff --git a/core/consensus/src/engine.rs b/core/consensus/src/engine.rs index 5fbbe75ce..5ae801b9c 100644 --- a/core/consensus/src/engine.rs +++ b/core/consensus/src/engine.rs @@ -89,7 +89,6 @@ impl Engine for ConsensusEngine 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, }; diff --git a/core/consensus/src/tests/synchronization.rs b/core/consensus/src/tests/synchronization.rs index 8ad413991..377b4008e 100644 --- a/core/consensus/src/tests/synchronization.rs +++ b/core/consensus/src/tests/synchronization.rs @@ -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, diff --git a/core/interoperation/src/tests/mod.rs b/core/interoperation/src/tests/mod.rs index a87fa192d..5ca39f099 100644 --- a/core/interoperation/src/tests/mod.rs +++ b/core/interoperation/src/tests/mod.rs @@ -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(), diff --git a/core/storage/src/tests/mod.rs b/core/storage/src/tests/mod.rs index d74ec2c30..8f3c90bd2 100644 --- a/core/storage/src/tests/mod.rs +++ b/core/storage/src/tests/mod.rs @@ -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, diff --git a/protocol/src/codec/block.rs b/protocol/src/codec/block.rs index ee49bef27..a3e64d85f 100644 --- a/protocol/src/codec/block.rs +++ b/protocol/src/codec/block.rs @@ -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(), diff --git a/protocol/src/types/block.rs b/protocol/src/types/block.rs index f5ad0fc1a..0c092fc94 100644 --- a/protocol/src/types/block.rs +++ b/protocol/src/types/block.rs @@ -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}; @@ -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, pub base_fee_per_gas: U256, pub proof: Proof, #[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))] @@ -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, @@ -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, @@ -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, @@ -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"))] @@ -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, - pub nonce: H64, pub base_fee_per_gas: U256, pub proof: Proof, #[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))] @@ -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, From 6e65306427a7e92585e7825574f56966b105aca3 Mon Sep 17 00:00:00 2001 From: Eason Date: Mon, 21 Aug 2023 10:52:10 +0800 Subject: [PATCH 2/4] fix unit test --- core/run/src/tests.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/run/src/tests.rs b/core/run/src/tests.rs index 18ec7ef17..9a35f307f 100644 --- a/core/run/src/tests.rs +++ b/core/run/src/tests.rs @@ -39,7 +39,7 @@ 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", }, @@ -47,7 +47,7 @@ const TESTCASES: &[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", }, @@ -55,7 +55,7 @@ const TESTCASES: &[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", }, From db0c6083339a44e46962bd113c3c5798a740ddc4 Mon Sep 17 00:00:00 2001 From: Eason Date: Mon, 21 Aug 2023 16:34:16 +0800 Subject: [PATCH 3/4] fix difficulty in executor context --- protocol/src/types/executor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol/src/types/executor.rs b/protocol/src/types/executor.rs index a2f39cc2c..71767bae1 100644 --- a/protocol/src/types/executor.rs +++ b/protocol/src/types/executor.rs @@ -63,7 +63,7 @@ impl From 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, From fbb43705e3135afe9e902d3a42b57f4f2acbd7ba Mon Sep 17 00:00:00 2001 From: Eason Date: Tue, 22 Aug 2023 10:32:55 +0800 Subject: [PATCH 4/4] change default difficulty from 0x0 to 0x1 --- core/api/src/jsonrpc/web3_types.rs | 6 +++--- core/executor/benches/bench_transfer.rs | 1 - core/executor/benches/mock.rs | 1 - core/executor/src/adapter/mod.rs | 2 +- core/executor/src/debugger/mod.rs | 1 - protocol/src/types/executor.rs | 3 --- tests/data/genesis.json | 3 --- 7 files changed, 4 insertions(+), 13 deletions(-) diff --git a/core/api/src/jsonrpc/web3_types.rs b/core/api/src/jsonrpc/web3_types.rs index b091eeb6d..297a2f6f9 100644 --- a/core/api/src/jsonrpc/web3_types.rs +++ b/core/api/src/jsonrpc/web3_types.rs @@ -318,8 +318,8 @@ impl From for Web3Block { state_root: b.header.state_root, receipts_root: b.header.receipts_root, miner: b.header.proposer, - difficulty: U256::zero(), - total_difficulty: Some(U256::zero()), + difficulty: U256::one(), + total_difficulty: Some(b.header.number.into()), seal_fields: vec![], base_fee_per_gas: b.header.base_fee_per_gas, extra_data: Hex::encode(&b.header.extra_data), @@ -839,7 +839,7 @@ impl From
for Web3Header { state_root: h.state_root, receipts_root: h.receipts_root, miner: h.proposer, - difficulty: U256::zero(), + difficulty: U256::one(), extra_data: Hex::encode(&h.extra_data), gas_limit: h.gas_limit, gas_used: h.gas_used, diff --git a/core/executor/benches/bench_transfer.rs b/core/executor/benches/bench_transfer.rs index a400b5221..e77e0a28e 100644 --- a/core/executor/benches/bench_transfer.rs +++ b/core/executor/benches/bench_transfer.rs @@ -70,7 +70,6 @@ impl BenchAdapter { block_coinbase: DISTRIBUTE_ADDRESS.0, block_timestamp: time_now().into(), chain_id: U256::one(), - difficulty: U256::one(), origin: DISTRIBUTE_ADDRESS.0, gas_price: 85u64.into(), block_gas_limit: 100_000_000_000u64.into(), diff --git a/core/executor/benches/mock.rs b/core/executor/benches/mock.rs index 3e90004bb..e432b5a6b 100644 --- a/core/executor/benches/mock.rs +++ b/core/executor/benches/mock.rs @@ -52,7 +52,6 @@ pub fn mock_executor_context() -> ExecutorContext { block_coinbase: DISTRIBUTE_ADDRESS.0, block_timestamp: time_now().into(), chain_id: U256::one(), - difficulty: U256::one(), origin: DISTRIBUTE_ADDRESS.0, gas_price: 85u64.into(), block_gas_limit: 100_000_000_000u64.into(), diff --git a/core/executor/src/adapter/mod.rs b/core/executor/src/adapter/mod.rs index c3532f7b4..a3c1b5050 100644 --- a/core/executor/src/adapter/mod.rs +++ b/core/executor/src/adapter/mod.rs @@ -131,7 +131,7 @@ where } fn block_difficulty(&self) -> U256 { - self.exec_ctx.difficulty + U256::one() } fn block_gas_limit(&self) -> U256 { diff --git a/core/executor/src/debugger/mod.rs b/core/executor/src/debugger/mod.rs index 9dee3ed13..f889c5ce0 100644 --- a/core/executor/src/debugger/mod.rs +++ b/core/executor/src/debugger/mod.rs @@ -103,7 +103,6 @@ impl EvmDebugger { block_coinbase: H160::random(), block_timestamp: time_now().into(), chain_id: 5u64.into(), - difficulty: U256::one(), origin: H160::random(), gas_price: 1u64.into(), block_gas_limit: 4294967295000u64.into(), diff --git a/protocol/src/types/executor.rs b/protocol/src/types/executor.rs index 71767bae1..af0af70af 100644 --- a/protocol/src/types/executor.rs +++ b/protocol/src/types/executor.rs @@ -48,7 +48,6 @@ pub struct ExecutorContext { pub block_coinbase: H160, pub block_timestamp: U256, pub chain_id: U256, - pub difficulty: U256, pub origin: H160, pub gas_price: U256, pub block_gas_limit: U256, @@ -63,7 +62,6 @@ impl From for ExecutorContext { block_coinbase: h.proposer, block_timestamp: h.timestamp.into(), chain_id: h.chain_id.into(), - difficulty: U256::zero(), origin: h.proposer, gas_price: U256::one(), block_gas_limit: h.gas_limit, @@ -80,7 +78,6 @@ impl From<&Header> for ExecutorContext { block_coinbase: h.proposer, block_timestamp: h.timestamp.into(), chain_id: h.chain_id.into(), - difficulty: U256::one(), origin: h.proposer, gas_price: U256::one(), block_gas_limit: h.gas_limit, diff --git a/tests/data/genesis.json b/tests/data/genesis.json index 9b1fe538f..b95084c44 100644 --- a/tests/data/genesis.json +++ b/tests/data/genesis.json @@ -9,14 +9,11 @@ "signed_txs_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "receipts_root": "0x0000000000000000000000000000000000000000000000000000000000000000", "log_bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "difficulty": "0x0", "timestamp": 1679656015, "number": 0, "gas_used": "0x0", "gas_limit": "0x0", "extra_data": [], - "mixed_hash": null, - "nonce": "0x0000000000000000", "base_fee_per_gas": "0x539", "proof": { "number": 0,