@@ -81,30 +81,27 @@ where
81
81
pubkey
82
82
) ;
83
83
84
+ let target_gas = handle. gas_limit ( ) ;
84
85
let caller: H160 = handle. context ( ) . caller . into ( ) ;
85
86
let input: Vec < u8 > = call. into ( ) ;
86
87
87
88
// 1. Decode the call
88
89
let call = Runtime :: RuntimeCall :: decode_with_depth_limit ( DecodeLimit :: get ( ) , & mut & * input)
89
90
. map_err ( |_| revert ( "could not decode call" ) ) ?;
90
91
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()
98
97
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()
103
98
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
+ }
108
105
}
109
106
handle. record_external_cost ( Some ( weight) , None ) ?;
110
107
@@ -128,7 +125,6 @@ where
128
125
Ok ( post_info) => {
129
126
if post_info. pays_fee ( & info) == Pays :: Yes {
130
127
let actual_weight = post_info. actual_weight . unwrap_or ( info. weight ) ;
131
- let cost = Runtime :: GasWeightMapping :: weight_to_gas ( actual_weight) ;
132
128
handle. record_external_cost ( None , Some ( info. weight . proof_size ( ) ) ) ?;
133
129
134
130
handle. refund_external_cost (
0 commit comments