Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
4928: [BUGFIX]: Fix transfer recording r=darthsiroftardis a=darthsiroftardis

CHANGELOG:

- Fixed recording of transfer to global state to use the cost of native transfer as opposed to zero 

Co-authored-by: Karan Dhareshwar <[email protected]>
  • Loading branch information
2 parents 2623d45 + 4906b14 commit b8f2c20
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 14 deletions.
8 changes: 7 additions & 1 deletion execution_engine/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ where
balance_hold_interval,
include_credits,
credit_cap,
config.system_costs_config.mint_costs().transfer,
);

let bidding_req = BiddingRequest::new(
Expand Down Expand Up @@ -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,
)
}

Expand Down
105 changes: 93 additions & 12 deletions execution_engine_testing/tests/src/test/deploy/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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,
})));

Expand All @@ -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,
})));

Expand All @@ -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,
})));
}
Expand Down Expand Up @@ -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,
});

Expand All @@ -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,
});

Expand All @@ -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,
});

Expand Down Expand Up @@ -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,
});

Expand All @@ -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,
});

Expand All @@ -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,
});

Expand Down
2 changes: 1 addition & 1 deletion storage/src/system/mint/mint_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
Expand Down
10 changes: 10 additions & 0 deletions storage/src/system/runtime_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct Config {
balance_hold_interval: u64,
include_credits: bool,
credit_cap: Ratio<U512>,
native_transfer_cost: u32,
}

impl Config {
Expand All @@ -43,6 +44,7 @@ impl Config {
balance_hold_interval: u64,
include_credits: bool,
credit_cap: Ratio<U512>,
native_transfer_cost: u32,
) -> Self {
Config {
transfer_config,
Expand All @@ -56,6 +58,7 @@ impl Config {
balance_hold_interval,
include_credits,
credit_cap,
native_transfer_cost,
}
}

Expand All @@ -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,
Expand All @@ -87,6 +91,7 @@ impl Config {
balance_hold_interval,
include_credits,
credit_cap,
native_transfer_cost,
)
}

Expand Down Expand Up @@ -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,
}
}
}
Expand Down Expand Up @@ -541,4 +547,8 @@ where
pub fn into_transfers(self) -> Vec<Transfer> {
self.transfers
}

pub(crate) fn native_transfer_cost(&self) -> u32 {
self.config.native_transfer_cost
}
}

0 comments on commit b8f2c20

Please sign in to comment.