@@ -4,10 +4,10 @@ mod utils;
44
55use crate :: standard:: Config ;
66use crate :: {
7- ExitError , ExitException , Gasometer as GasometerT , Machine , MergeStrategy , Opcode ,
7+ ExitError , ExitException , ExitFatal , Gasometer as GasometerT , Machine , MergeStrategy , Opcode ,
88 RuntimeBackend , RuntimeState , Stack ,
99} ;
10- use core:: cmp:: max;
10+ use core:: cmp:: { max, min } ;
1111use primitive_types:: { H160 , H256 , U256 } ;
1212
1313pub trait TransactGasometer < ' config , S : AsRef < RuntimeState > > : Sized {
@@ -25,6 +25,8 @@ pub trait TransactGasometer<'config, S: AsRef<RuntimeState>>: Sized {
2525 access_list : & Vec < ( H160 , Vec < H256 > ) > ,
2626 config : & ' config Config ,
2727 ) -> Result < Self , ExitError > ;
28+
29+ fn effective_gas ( & self ) -> U256 ;
2830}
2931
3032pub struct Gasometer < ' config > {
@@ -36,6 +38,7 @@ pub struct Gasometer<'config> {
3638}
3739
3840impl < ' config > Gasometer < ' config > {
41+ #[ inline]
3942 pub fn perform < R , F : FnOnce ( & mut Self ) -> Result < R , ExitError > > (
4043 & mut self ,
4144 f : F ,
@@ -125,6 +128,17 @@ impl<'config, S: AsRef<RuntimeState>> TransactGasometer<'config, S> for Gasomete
125128 s. record_cost ( transaction_cost) ?;
126129 Ok ( s)
127130 }
131+
132+ fn effective_gas ( & self ) -> U256 {
133+ U256 :: from (
134+ self . gas_limit
135+ - ( self . total_used_gas ( )
136+ - min (
137+ self . total_used_gas ( ) / self . config . max_refund_quotient ,
138+ self . refunded_gas ,
139+ ) ) ,
140+ )
141+ }
128142}
129143
130144impl < ' config , S : AsRef < RuntimeState > , H : RuntimeBackend > GasometerT < S , H > for Gasometer < ' config > {
@@ -134,8 +148,12 @@ impl<'config, S: AsRef<RuntimeState>, H: RuntimeBackend> GasometerT<S, H> for Ga
134148 is_static : bool ,
135149 handler : & H ,
136150 ) -> Result < ( ) , ExitError > {
151+ if machine. is_empty ( ) {
152+ return Ok ( ( ) ) ;
153+ }
154+
137155 self . perform ( |gasometer| {
138- let opcode = machine. peek_opcode ( ) . ok_or ( ExitException :: OutOfGas ) ?;
156+ let opcode = machine. peek_opcode ( ) . ok_or ( ExitFatal :: AlreadyExited ) ?;
139157
140158 if let Some ( cost) = consts:: STATIC_COST_TABLE [ opcode. as_usize ( ) ] {
141159 gasometer. record_cost ( cost) ?;
0 commit comments