Skip to content

Commit c625065

Browse files
committed
handle gas limit
1 parent 304a56c commit c625065

File tree

1 file changed

+12
-16
lines changed
  • precompiles/dispatch-lockdrop/src

1 file changed

+12
-16
lines changed

precompiles/dispatch-lockdrop/src/lib.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -81,30 +81,27 @@ where
8181
pubkey
8282
);
8383

84+
let target_gas = handle.gas_limit();
8485
let caller: H160 = handle.context().caller.into();
8586
let input: Vec<u8> = call.into();
8687

8788
// 1. Decode the call
8889
let call = Runtime::RuntimeCall::decode_with_depth_limit(DecodeLimit::get(), &mut &*input)
8990
.map_err(|_| revert("could not decode call"))?;
9091

91-
// 2. Check if dispatching the call will not exceed the gas limit
92-
let mut gas_limit = handle.remaining_gas();
93-
// If caller specified a gas limit, make sure it's not exceeded.
94-
if let Some(user_limit) = handle.gas_limit() {
95-
gas_limit = gas_limit.min(user_limit);
96-
}
97-
92+
// 2. Charge the max amount of weight ref_time and
93+
// later when call is successfully dispatched,
94+
// charge proof_size and refund the ref_time difference.
95+
// Note: adding hard coded ref_time corresponding to the blake2b Hash
96+
// and the keccak256 Hash based on the weight of UA::claim_default_evm_address()
9897
let info = call.get_dispatch_info();
99-
100-
// Charge the weight of the call to dispatch AND the overhead weight
101-
// corresponding to the blake2b Hash and the keccak256 Hash
102-
// based on the weight of UA::claim_default_evm_address()
10398
let weight = info.weight.ref_time().saturating_add(40_000_000u64);
104-
if !(weight <= Runtime::GasWeightMapping::gas_to_weight(gas_limit, false).ref_time()) {
105-
return Err(PrecompileFailure::Error {
106-
exit_status: ExitError::OutOfGas,
107-
});
99+
if let Some(gas) = target_gas {
100+
if !(weight <= Runtime::GasWeightMapping::gas_to_weight(gas, false).ref_time()) {
101+
return Err(PrecompileFailure::Error {
102+
exit_status: ExitError::OutOfGas,
103+
});
104+
}
108105
}
109106
handle.record_external_cost(Some(weight), None)?;
110107

@@ -128,7 +125,6 @@ where
128125
Ok(post_info) => {
129126
if post_info.pays_fee(&info) == Pays::Yes {
130127
let actual_weight = post_info.actual_weight.unwrap_or(info.weight);
131-
let cost = Runtime::GasWeightMapping::weight_to_gas(actual_weight);
132128
handle.record_external_cost(None, Some(info.weight.proof_size()))?;
133129

134130
handle.refund_external_cost(

0 commit comments

Comments
 (0)