@@ -1729,6 +1729,8 @@ where
1729
1729
self ,
1730
1730
filler : & crate :: fillers:: GasEstimationFiller ,
1731
1731
) -> Result < ( crate :: EstimationResult , Self ) , EvmErrored < Db , Insp > > {
1732
+ use tracing:: trace;
1733
+
1732
1734
let mut estimation = std:: mem:: MaybeUninit :: uninit ( ) ;
1733
1735
1734
1736
let this = self . try_with_estimate_gas_filler ( filler, |this| match this. run ( ) {
@@ -1744,6 +1746,7 @@ where
1744
1746
// SAFETY: if we did not shortcut return, then estimation was
1745
1747
// definitely written
1746
1748
Ok ( ( unsafe { estimation. assume_init ( ) } , this) )
1749
+ . inspect ( |( est, _) | trace ! ( ?est, "gas estimation result" , ) )
1747
1750
}
1748
1751
1749
1752
/// Implements gas estimation. This will output an estimate of the minimum
@@ -1848,7 +1851,10 @@ where
1848
1851
trace ! ( %estimate, "optimistic estimate succeeded" ) ;
1849
1852
1850
1853
// Now we know that it succeeds at _some_ gas limit. We can now binary
1851
- // search.
1854
+ // search. We start by recording the initial best estimate. We'll update
1855
+ // this best-estimate as we go inside the `estimate_and_adjust` macro
1856
+ // invocations.
1857
+ let mut best = estimate. clone ( ) ;
1852
1858
let mut gas_used = estimate. gas_used ( ) ;
1853
1859
let gas_refunded = estimate. gas_refunded ( ) . expect ( "checked is_failure" ) ;
1854
1860
@@ -1868,7 +1874,7 @@ where
1868
1874
1869
1875
// If the first search is outside the range, we don't need to try it.
1870
1876
if search_range. contains ( needle) {
1871
- estimate_and_adjust ! ( estimate, trevm, needle, search_range) ;
1877
+ estimate_and_adjust ! ( best , estimate, trevm, needle, search_range) ;
1872
1878
// NB: `estimate` is rebound in the macro, so do not move this line
1873
1879
// up.
1874
1880
gas_used = estimate. gas_used ( ) ;
@@ -1885,11 +1891,11 @@ where
1885
1891
// highest gas limit)
1886
1892
// <https://github.com/ethereum/go-ethereum/blob/a5a4fa7032bb248f5a7c40f4e8df2b131c4186
1887
1893
while search_range. size ( ) > 1 && search_range. ratio ( ) > 0.015 {
1888
- estimate_and_adjust ! ( estimate, trevm, needle, search_range) ;
1894
+ estimate_and_adjust ! ( best , estimate, trevm, needle, search_range) ;
1889
1895
needle = search_range. midpoint ( ) ;
1890
1896
}
1891
1897
1892
- Ok ( ( estimate , trevm) )
1898
+ Ok ( ( best , trevm) )
1893
1899
}
1894
1900
}
1895
1901
0 commit comments