From f85cc3e41f88422db1b1dfeae431f410978668e1 Mon Sep 17 00:00:00 2001 From: dayong Date: Fri, 6 Dec 2024 16:55:26 +0800 Subject: [PATCH 1/3] feat: support gasFee for espace transaction receipt related RPC, resolves #2926 --- .gitignore | 3 ++- .../core/src/block_data_manager/db_manager.rs | 27 ++++++++++++------- crates/rpc/rpc-eth-types/src/receipt.rs | 2 ++ crates/rpc/rpc/src/eth.rs | 1 + run/clear_state.sh | 4 ++- tests/evm_space/tx_and_receipt_test.py | 1 + tests/rpc/test_tx_receipt_by_hash.py | 1 + 7 files changed, 27 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index ea5f25493b..6e28b42135 100644 --- a/.gitignore +++ b/.gitignore @@ -10,10 +10,11 @@ target .phabricator* build/ build_clippy/ -**/blockchain_db/ +**/blockchain_data/ **/sqlite_db/ **/net_config/ **/*.log +**/stderr.txt **/testnet.toml *~ .DS_Store diff --git a/crates/cfxcore/core/src/block_data_manager/db_manager.rs b/crates/cfxcore/core/src/block_data_manager/db_manager.rs index 906ca0b96b..09d79fe64c 100644 --- a/crates/cfxcore/core/src/block_data_manager/db_manager.rs +++ b/crates/cfxcore/core/src/block_data_manager/db_manager.rs @@ -531,22 +531,25 @@ impl DBManager { .expect("db read failure") } - fn insert_encodable_val( - &self, table: DBTable, db_key: &[u8], value: &V, - ) where V: DatabaseEncodable { + fn insert_encodable_val(&self, table: DBTable, db_key: &[u8], value: &V) + where + V: DatabaseEncodable, + { self.insert_to_db(table, db_key, value.db_encode()) } fn insert_encodable_list( &self, table: DBTable, db_key: &[u8], value: &Vec, - ) where V: DatabaseEncodable { + ) where + V: DatabaseEncodable, + { self.insert_to_db(table, db_key, db_encode_list(value)) } - fn load_decodable_val( - &self, table: DBTable, db_key: &[u8], - ) -> Option - where V: DatabaseDecodable { + fn load_decodable_val(&self, table: DBTable, db_key: &[u8]) -> Option + where + V: DatabaseDecodable, + { let encoded = self.load_from_db(table, db_key)?; Some(V::db_decode(&encoded).expect("decode succeeds")) } @@ -554,7 +557,9 @@ impl DBManager { fn load_might_decodable_val( &self, table: DBTable, db_key: &[u8], ) -> Option - where V: DatabaseDecodable { + where + V: DatabaseDecodable, + { let encoded = self.load_from_db(table, db_key)?; V::db_decode(&encoded).ok() } @@ -562,7 +567,9 @@ impl DBManager { fn load_decodable_list( &self, table: DBTable, db_key: &[u8], ) -> Option> - where V: DatabaseDecodable { + where + V: DatabaseDecodable, + { let encoded = self.load_from_db(table, db_key)?; Some(db_decode_list(&encoded).expect("decode succeeds")) } diff --git a/crates/rpc/rpc-eth-types/src/receipt.rs b/crates/rpc/rpc-eth-types/src/receipt.rs index dce0100935..cb4691e51e 100644 --- a/crates/rpc/rpc-eth-types/src/receipt.rs +++ b/crates/rpc/rpc-eth-types/src/receipt.rs @@ -44,6 +44,8 @@ pub struct Receipt { pub cumulative_gas_used: U256, /// Gas used pub gas_used: U256, + /// The gas fee charged in the execution of the transaction. + pub gas_fee: U256, /// Contract address pub contract_address: Option, /// Logs diff --git a/crates/rpc/rpc/src/eth.rs b/crates/rpc/rpc/src/eth.rs index b08bc2a838..a054e164a5 100644 --- a/crates/rpc/rpc/src/eth.rs +++ b/crates/rpc/rpc/src/eth.rs @@ -355,6 +355,7 @@ impl EthApi { block_number: block_height, cumulative_gas_used: receipt.accumulated_gas_used, gas_used, + gas_fee: receipt.gas_fee, contract_address, logs, logs_bloom: receipt.log_bloom, diff --git a/run/clear_state.sh b/run/clear_state.sh index da44590ce2..8a5a35c755 100755 --- a/run/clear_state.sh +++ b/run/clear_state.sh @@ -1,8 +1,10 @@ #!/bin/bash rm -rf blockchain_data rm -rf log +rm stderr.txt rm -rf pos_db rm pos.log rm -rf pos_config/private_keys -cd pos_config && ls | grep -v pos_config.yaml | grep -v pos_key | xargs rm \ No newline at end of file + +cd pos_config && ls | grep -v pos_config.yaml | grep -v pos_key | xargs rm diff --git a/tests/evm_space/tx_and_receipt_test.py b/tests/evm_space/tx_and_receipt_test.py index 3110615adc..935c1864bf 100755 --- a/tests/evm_space/tx_and_receipt_test.py +++ b/tests/evm_space/tx_and_receipt_test.py @@ -42,6 +42,7 @@ def run_test(self): receipt = self.w3.eth.wait_for_transaction_receipt(return_tx_hash) assert_equal(receipt["status"], 1) assert_equal(receipt["gasUsed"], 21000) + assert_equal(receipt["gasFee"], "0x2673c") assert_equal(receipt["txExecErrorMsg"], None) tx = self.w3.eth.get_transaction(return_tx_hash) diff --git a/tests/rpc/test_tx_receipt_by_hash.py b/tests/rpc/test_tx_receipt_by_hash.py index ceec698393..08e6c58e88 100644 --- a/tests/rpc/test_tx_receipt_by_hash.py +++ b/tests/rpc/test_tx_receipt_by_hash.py @@ -36,6 +36,7 @@ def test_simple_receipt(self): assert_equal(receipt['storageCoveredBySponsor'], False) assert_equal(len(receipt['storageReleased']), 0) assert_equal(receipt['txExecErrorMsg'], None) + assert_equal(receipt['gasFee'], "0x5208") def test_receipt_with_storage_changes(self): bytecode_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), CONTRACT_PATH) From ce0a2aeeb92a1538d2cd13291c475dd250102acc Mon Sep 17 00:00:00 2001 From: dayong Date: Fri, 6 Dec 2024 16:56:57 +0800 Subject: [PATCH 2/3] fmt --- .../core/src/block_data_manager/db_manager.rs | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/crates/cfxcore/core/src/block_data_manager/db_manager.rs b/crates/cfxcore/core/src/block_data_manager/db_manager.rs index 09d79fe64c..906ca0b96b 100644 --- a/crates/cfxcore/core/src/block_data_manager/db_manager.rs +++ b/crates/cfxcore/core/src/block_data_manager/db_manager.rs @@ -531,25 +531,22 @@ impl DBManager { .expect("db read failure") } - fn insert_encodable_val(&self, table: DBTable, db_key: &[u8], value: &V) - where - V: DatabaseEncodable, - { + fn insert_encodable_val( + &self, table: DBTable, db_key: &[u8], value: &V, + ) where V: DatabaseEncodable { self.insert_to_db(table, db_key, value.db_encode()) } fn insert_encodable_list( &self, table: DBTable, db_key: &[u8], value: &Vec, - ) where - V: DatabaseEncodable, - { + ) where V: DatabaseEncodable { self.insert_to_db(table, db_key, db_encode_list(value)) } - fn load_decodable_val(&self, table: DBTable, db_key: &[u8]) -> Option - where - V: DatabaseDecodable, - { + fn load_decodable_val( + &self, table: DBTable, db_key: &[u8], + ) -> Option + where V: DatabaseDecodable { let encoded = self.load_from_db(table, db_key)?; Some(V::db_decode(&encoded).expect("decode succeeds")) } @@ -557,9 +554,7 @@ impl DBManager { fn load_might_decodable_val( &self, table: DBTable, db_key: &[u8], ) -> Option - where - V: DatabaseDecodable, - { + where V: DatabaseDecodable { let encoded = self.load_from_db(table, db_key)?; V::db_decode(&encoded).ok() } @@ -567,9 +562,7 @@ impl DBManager { fn load_decodable_list( &self, table: DBTable, db_key: &[u8], ) -> Option> - where - V: DatabaseDecodable, - { + where V: DatabaseDecodable { let encoded = self.load_from_db(table, db_key)?; Some(db_decode_list(&encoded).expect("decode succeeds")) } From bc2040935f7367772c2e8d49f3a1c427d585eed9 Mon Sep 17 00:00:00 2001 From: dayong Date: Mon, 9 Dec 2024 10:54:42 +0800 Subject: [PATCH 3/3] update JSONRPC changelog --- .gitignore | 1 + changelogs/JSONRPC.md | 1 + run/clear_state.sh | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6e28b42135..fc3f898e7d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ target build/ build_clippy/ **/blockchain_data/ +**/pos_db/ **/sqlite_db/ **/net_config/ **/*.log diff --git a/changelogs/JSONRPC.md b/changelogs/JSONRPC.md index f54b79ee86..0da342b15b 100644 --- a/changelogs/JSONRPC.md +++ b/changelogs/JSONRPC.md @@ -1,6 +1,7 @@ # JSON-RPC CHANGELOG ## vNext +1. Support gasFee in transaction receipt for espace RPC ## v2.4.1 diff --git a/run/clear_state.sh b/run/clear_state.sh index 8a5a35c755..180385966c 100755 --- a/run/clear_state.sh +++ b/run/clear_state.sh @@ -7,4 +7,4 @@ rm -rf pos_db rm pos.log rm -rf pos_config/private_keys -cd pos_config && ls | grep -v pos_config.yaml | grep -v pos_key | xargs rm +cd pos_config && ls | grep -v pos_config.yaml | grep -v pos_key | grep -v genesis_file | grep -v initial_nodes.json | xargs rm -rf