@@ -241,8 +241,8 @@ pub struct GasMetering {
241
241
pub recording : bool ,
242
242
/// The gas used in the last frame.
243
243
pub last_gas_used : u64 ,
244
- /// Gas records for the active snapshots .
245
- pub gas_records : Vec < GasRecord > ,
244
+ /// The gas record for the current snapshot .
245
+ pub gas_record : GasRecord ,
246
246
}
247
247
248
248
impl GasMetering {
@@ -253,13 +253,6 @@ impl GasMetering {
253
253
254
254
/// Stop the gas recording.
255
255
pub fn stop ( & mut self ) {
256
- println ! ( "gas records: {:?}" , self . gas_records) ;
257
-
258
- // self.gas_records.iter_mut().for_each(|record| {
259
- // record.gas_used.saturating_add(self.recorded_frames.iter().sum::<u64>());
260
- // });
261
-
262
- // reduce sum of gas frames to a single value
263
256
self . recording = false ;
264
257
}
265
258
@@ -786,11 +779,10 @@ impl Cheatcodes {
786
779
}
787
780
788
781
// Store the total gas used for all active gas records started by `startSnapshotGas`.
789
- self . gas_metering . gas_records . iter_mut ( ) . for_each ( |record| {
790
- if ecx. journaled_state . depth ( ) == record. depth + 1 {
791
- record. gas_used = record. gas_used . saturating_add ( outcome. result . gas . spent ( ) ) ;
792
- }
793
- } ) ;
782
+ if ecx. journaled_state . depth ( ) == self . gas_metering . gas_record . depth + 1 {
783
+ self . gas_metering . gas_record . gas_used =
784
+ self . gas_metering . gas_record . gas_used . saturating_add ( outcome. result . gas . spent ( ) ) ;
785
+ }
794
786
795
787
// If `startStateDiffRecording` has been called, update the `reverted` status of the
796
788
// previous call depth's recorded accesses, if any
@@ -1352,11 +1344,10 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
1352
1344
} ) ;
1353
1345
1354
1346
// Store the total gas used for all active gas records started by `startSnapshotGas`.
1355
- self . gas_metering . gas_records . iter_mut ( ) . for_each ( |record| {
1356
- if ecx. journaled_state . depth ( ) == record. depth + 1 {
1357
- record. gas_used = record. gas_used . saturating_add ( gas. spent ( ) ) ;
1358
- }
1359
- } ) ;
1347
+ if ecx. journaled_state . depth ( ) == self . gas_metering . gas_record . depth + 1 {
1348
+ self . gas_metering . gas_record . gas_used =
1349
+ self . gas_metering . gas_record . gas_used . saturating_add ( gas. spent ( ) ) ;
1350
+ }
1360
1351
1361
1352
// If `startStateDiffRecording` has been called, update the `reverted` status of the
1362
1353
// previous call depth's recorded accesses, if any
@@ -1624,27 +1615,30 @@ impl Cheatcodes {
1624
1615
self . gas_metering . last_gas_used = 0 ;
1625
1616
}
1626
1617
_ => {
1627
- self . gas_metering . gas_records . iter_mut ( ) . for_each ( |record| {
1628
- if ecx. journaled_state . depth ( ) == record. depth + 1 {
1629
- // Initialize after new frame, use this as the starting point.
1630
- if self . gas_metering . last_gas_used == 0 {
1631
- self . gas_metering . last_gas_used = interpreter. gas . spent ( ) ;
1632
- return ;
1633
- }
1618
+ if ecx. journaled_state . depth ( ) == self . gas_metering . gas_record . depth + 1 {
1619
+ // Initialize after new frame, use this as the starting point.
1620
+ if self . gas_metering . last_gas_used == 0 {
1621
+ self . gas_metering . last_gas_used = interpreter. gas . spent ( ) ;
1622
+ return ;
1623
+ }
1634
1624
1635
- // Calculate the gas difference between the last and current frame.
1636
- let gas_diff = interpreter
1637
- . gas
1638
- . spent ( )
1639
- . saturating_sub ( self . gas_metering . last_gas_used ) ;
1625
+ // Calculate the gas difference between the last and current frame.
1626
+ let gas_diff =
1627
+ interpreter. gas . spent ( ) . saturating_sub ( self . gas_metering . last_gas_used ) ;
1640
1628
1641
- // Update the gas record.
1642
- record. gas_used = record. gas_used . saturating_add ( gas_diff) ;
1629
+ println ! (
1630
+ "opcode: {:?}, gas_diff: {}" ,
1631
+ interpreter. current_opcode( ) ,
1632
+ gas_diff
1633
+ ) ;
1643
1634
1644
- // Update for next iteration.
1645
- self . gas_metering . last_gas_used = interpreter. gas . spent ( ) ;
1646
- }
1647
- } ) ;
1635
+ // Update the gas record.
1636
+ self . gas_metering . gas_record . gas_used =
1637
+ self . gas_metering . gas_record . gas_used . saturating_add ( gas_diff) ;
1638
+
1639
+ // Update for next iteration.
1640
+ self . gas_metering . last_gas_used = interpreter. gas . spent ( ) ;
1641
+ }
1648
1642
}
1649
1643
}
1650
1644
}
0 commit comments