From f0efe9fa7d81e29229741958e8495fb18d89ea98 Mon Sep 17 00:00:00 2001 From: Karan Dhareshwar Date: Tue, 22 Oct 2024 11:15:20 -0500 Subject: [PATCH 1/3] Fix fee field in record_transfer --- execution_engine/src/runtime/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/execution_engine/src/runtime/mod.rs b/execution_engine/src/runtime/mod.rs index 4287183daa..854a55c2b6 100644 --- a/execution_engine/src/runtime/mod.rs +++ b/execution_engine/src/runtime/mod.rs @@ -2280,7 +2280,13 @@ where let txn_hash = self.context.get_transaction_hash(); let from = InitiatorAddr::AccountHash(self.context.get_caller()); - let fee = Gas::zero(); // TODO + let fee = Gas::from( + self.context + .engine_config() + .system_config() + .mint_costs() + .transfer, + ); let transfer = Transfer::V2(TransferV2::new( txn_hash, from, maybe_to, source, target, amount, fee, id, )); From 8e5f328a32003c83f99028800e9ab738e94071b8 Mon Sep 17 00:00:00 2001 From: Karan Dhareshwar Date: Tue, 22 Oct 2024 12:33:05 -0500 Subject: [PATCH 2/3] Fix fee field in record_transfer in mint_internal --- storage/src/system/mint/mint_native.rs | 2 +- storage/src/system/runtime_native.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/storage/src/system/mint/mint_native.rs b/storage/src/system/mint/mint_native.rs index 44d15a2f26..4210130e26 100644 --- a/storage/src/system/mint/mint_native.rs +++ b/storage/src/system/mint/mint_native.rs @@ -241,7 +241,7 @@ where Id::Seed(_) => return Ok(()), }; let from = InitiatorAddr::AccountHash(self.get_caller()); - let fee = Gas::zero(); // TODO + let fee = Gas::from(self.native_transfer_cost()); let transfer = Transfer::V2(TransferV2::new( txn_hash, from, maybe_to, source, target, amount, fee, id, )); diff --git a/storage/src/system/runtime_native.rs b/storage/src/system/runtime_native.rs index 8f04d8bfb8..1ba6e5c805 100644 --- a/storage/src/system/runtime_native.rs +++ b/storage/src/system/runtime_native.rs @@ -26,6 +26,7 @@ pub struct Config { balance_hold_interval: u64, include_credits: bool, credit_cap: Ratio, + native_transfer_cost: u32, } impl Config { @@ -43,6 +44,7 @@ impl Config { balance_hold_interval: u64, include_credits: bool, credit_cap: Ratio, + native_transfer_cost: u32, ) -> Self { Config { transfer_config, @@ -56,6 +58,7 @@ impl Config { balance_hold_interval, include_credits, credit_cap, + native_transfer_cost, } } @@ -75,6 +78,7 @@ impl Config { U512::from(*chainspec.core_config.validator_credit_cap.numer()), U512::from(*chainspec.core_config.validator_credit_cap.denom()), ); + let native_transfer_cost = chainspec.system_costs_config.mint_costs().transfer; Config::new( transfer_config, fee_handling, @@ -87,6 +91,7 @@ impl Config { balance_hold_interval, include_credits, credit_cap, + native_transfer_cost, ) } @@ -159,6 +164,7 @@ impl Config { balance_hold_interval: self.balance_hold_interval, include_credits: self.include_credits, credit_cap: self.credit_cap, + native_transfer_cost: self.native_transfer_cost, } } } @@ -541,4 +547,8 @@ where pub fn into_transfers(self) -> Vec { self.transfers } + + pub(crate) fn native_transfer_cost(&self) -> u32 { + self.config.native_transfer_cost + } } From 4906b14aa6d765afa0334ff81844f635c0dc9e5d Mon Sep 17 00:00:00 2001 From: Karan Dhareshwar Date: Tue, 22 Oct 2024 13:17:24 -0500 Subject: [PATCH 3/3] Fix fee field in record_transfer in mint_internal --- .../src/transfer_request_builder.rs | 1 + .../test_support/src/wasm_test_builder.rs | 2 + .../tests/src/test/deploy/receipts.rs | 105 ++++++++++++++++-- 3 files changed, 96 insertions(+), 12 deletions(-) diff --git a/execution_engine_testing/test_support/src/transfer_request_builder.rs b/execution_engine_testing/test_support/src/transfer_request_builder.rs index 0e3b17f5a3..ecd969a58d 100644 --- a/execution_engine_testing/test_support/src/transfer_request_builder.rs +++ b/execution_engine_testing/test_support/src/transfer_request_builder.rs @@ -56,6 +56,7 @@ impl TransferRequestBuilder { DEFAULT_GAS_HOLD_INTERVAL.millis(), false, Ratio::new_raw(U512::zero(), U512::zero()), + 2_500_000_000, ); /// The default value used for `TransferRequest::state_hash`. pub const DEFAULT_STATE_HASH: Digest = Digest::from_raw([1; 32]); diff --git a/execution_engine_testing/test_support/src/wasm_test_builder.rs b/execution_engine_testing/test_support/src/wasm_test_builder.rs index 239f691bf8..cef7b96d41 100644 --- a/execution_engine_testing/test_support/src/wasm_test_builder.rs +++ b/execution_engine_testing/test_support/src/wasm_test_builder.rs @@ -810,6 +810,7 @@ where balance_hold_interval, include_credits, credit_cap, + config.system_costs_config.mint_costs().transfer, ); let bidding_req = BiddingRequest::new( @@ -975,6 +976,7 @@ where self.chainspec.core_config.gas_hold_interval.millis(), include_credits, credit_cap, + self.chainspec.system_costs_config.mint_costs().transfer, ) } diff --git a/execution_engine_testing/tests/src/test/deploy/receipts.rs b/execution_engine_testing/tests/src/test/deploy/receipts.rs index 1496e4215e..ac4ad122b2 100644 --- a/execution_engine_testing/tests/src/test/deploy/receipts.rs +++ b/execution_engine_testing/tests/src/test/deploy/receipts.rs @@ -97,7 +97,16 @@ fn should_record_wasmless_transfer() { assert_eq!(transfer.source, default_account.main_purse()); assert_eq!(transfer.target, alice_attenuated_main_purse); assert_eq!(transfer.amount, *TRANSFER_AMOUNT_1); - assert_eq!(transfer.gas, Gas::zero()); + assert_eq!( + transfer.gas, + Gas::from( + builder + .chainspec() + .system_costs_config + .mint_costs() + .transfer + ) + ); assert_eq!(transfer.id, Some(id)); } @@ -153,7 +162,16 @@ fn should_record_wasm_transfer() { assert_eq!(transfer.source, default_account.main_purse()); assert_eq!(transfer.target, alice_attenuated_main_purse); assert_eq!(transfer.amount, *TRANSFER_AMOUNT_1); - assert_eq!(transfer.gas, Gas::zero()) // TODO + assert_eq!( + transfer.gas, + Gas::from( + builder + .chainspec() + .system_costs_config + .mint_costs() + .transfer + ) + ) } #[ignore] @@ -211,7 +229,16 @@ fn should_record_wasm_transfer_with_id() { assert_eq!(transfer.source, default_account.main_purse()); assert_eq!(transfer.target, alice_attenuated_main_purse); assert_eq!(transfer.amount, *TRANSFER_AMOUNT_1); - assert_eq!(transfer.gas, Gas::zero()); // TODO + assert_eq!( + transfer.gas, + Gas::from( + builder + .chainspec() + .system_costs_config + .mint_costs() + .transfer + ) + ); assert_eq!(transfer.id, id); } @@ -309,7 +336,13 @@ fn should_record_wasm_transfers() { source: default_account.main_purse(), target: alice_attenuated_main_purse, amount: *TRANSFER_AMOUNT_1, - gas: Gas::zero(), + gas: Gas::from( + builder + .chainspec() + .system_costs_config + .mint_costs() + .transfer + ), id: alice_id, }))); @@ -320,7 +353,13 @@ fn should_record_wasm_transfers() { source: default_account.main_purse(), target: bob_attenuated_main_purse, amount: *TRANSFER_AMOUNT_2, - gas: Gas::zero(), + gas: Gas::from( + builder + .chainspec() + .system_costs_config + .mint_costs() + .transfer + ), id: bob_id, }))); @@ -331,7 +370,13 @@ fn should_record_wasm_transfers() { source: default_account.main_purse(), target: carol_attenuated_main_purse, amount: *TRANSFER_AMOUNT_3, - gas: Gas::zero(), + gas: Gas::from( + builder + .chainspec() + .system_costs_config + .mint_costs() + .transfer + ), id: carol_id, }))); } @@ -469,7 +514,13 @@ fn should_record_wasm_transfers_with_subcall() { source: default_account.main_purse(), target: alice_attenuated_main_purse, amount: *TRANSFER_AMOUNT_1, - gas: Gas::zero(), + gas: Gas::from( + builder + .chainspec() + .system_costs_config + .mint_costs() + .transfer, + ), id: alice_id, }); @@ -480,7 +531,13 @@ fn should_record_wasm_transfers_with_subcall() { source: default_account.main_purse(), target: bob_attenuated_main_purse, amount: *TRANSFER_AMOUNT_2, - gas: Gas::zero(), + gas: Gas::from( + builder + .chainspec() + .system_costs_config + .mint_costs() + .transfer, + ), id: bob_id, }); @@ -491,7 +548,13 @@ fn should_record_wasm_transfers_with_subcall() { source: default_account.main_purse(), target: carol_attenuated_main_purse, amount: *TRANSFER_AMOUNT_3, - gas: Gas::zero(), + gas: Gas::from( + builder + .chainspec() + .system_costs_config + .mint_costs() + .transfer, + ), id: carol_id, }); @@ -519,7 +582,13 @@ fn should_record_wasm_transfers_with_subcall() { source: contract_purse, target: alice_attenuated_main_purse, amount: *TRANSFER_AMOUNT_1, - gas: Gas::zero(), + gas: Gas::from( + builder + .chainspec() + .system_costs_config + .mint_costs() + .transfer, + ), id: alice_id, }); @@ -530,7 +599,13 @@ fn should_record_wasm_transfers_with_subcall() { source: contract_purse, target: bob_attenuated_main_purse, amount: *TRANSFER_AMOUNT_2, - gas: Gas::zero(), + gas: Gas::from( + builder + .chainspec() + .system_costs_config + .mint_costs() + .transfer, + ), id: bob_id, }); @@ -541,7 +616,13 @@ fn should_record_wasm_transfers_with_subcall() { source: contract_purse, target: carol_attenuated_main_purse, amount: *TRANSFER_AMOUNT_3, - gas: Gas::zero(), + gas: Gas::from( + builder + .chainspec() + .system_costs_config + .mint_costs() + .transfer, + ), id: carol_id, });