@@ -1486,28 +1486,34 @@ impl Call for Client {
1486
1486
let sender = t. sender ( ) ;
1487
1487
let options = || TransactOptions :: with_tracing ( ) . dont_check_nonce ( ) ;
1488
1488
1489
- let cond = |gas| {
1489
+ let exec = |gas| {
1490
1490
let mut tx = t. as_unsigned ( ) . clone ( ) ;
1491
1491
tx. gas = gas;
1492
1492
let tx = tx. fake_sign ( sender) ;
1493
1493
1494
1494
let mut clone = state. clone ( ) ;
1495
- Ok ( Executive :: new ( & mut clone, & env_info, self . engine . machine ( ) )
1495
+ Executive :: new ( & mut clone, & env_info, self . engine . machine ( ) )
1496
1496
. transact_virtual ( & tx, options ( ) )
1497
+ . ok ( )
1497
1498
. map ( |r| r. exception . is_none ( ) )
1498
- . unwrap_or ( false ) )
1499
1499
} ;
1500
1500
1501
- if !cond ( upper) ? {
1501
+ let cond = |gas| exec ( gas) . unwrap_or ( false ) ;
1502
+
1503
+ if !cond ( upper) {
1502
1504
upper = max_upper;
1503
- if !cond ( upper) ? {
1504
- trace ! ( target: "estimate_gas" , "estimate_gas failed with {}" , upper) ;
1505
- let err = ExecutionError :: Internal ( format ! ( "Requires higher than upper limit of {}" , upper) ) ;
1506
- return Err ( err. into ( ) )
1505
+ match exec ( upper) {
1506
+ Some ( false ) => return Err ( CallError :: Exceptional ) ,
1507
+ None => {
1508
+ trace ! ( target: "estimate_gas" , "estimate_gas failed with {}" , upper) ;
1509
+ let err = ExecutionError :: Internal ( format ! ( "Requires higher than upper limit of {}" , upper) ) ;
1510
+ return Err ( err. into ( ) )
1511
+ } ,
1512
+ _ => { } ,
1507
1513
}
1508
1514
}
1509
1515
let lower = t. gas_required ( & self . engine . schedule ( env_info. number ) ) . into ( ) ;
1510
- if cond ( lower) ? {
1516
+ if cond ( lower) {
1511
1517
trace ! ( target: "estimate_gas" , "estimate_gas succeeded with {}" , lower) ;
1512
1518
return Ok ( lower)
1513
1519
}
@@ -1516,12 +1522,12 @@ impl Call for Client {
1516
1522
/// Returns the lowest value between `lower` and `upper` for which `cond` returns true.
1517
1523
/// We assert: `cond(lower) = false`, `cond(upper) = true`
1518
1524
fn binary_chop < F , E > ( mut lower : U256 , mut upper : U256 , mut cond : F ) -> Result < U256 , E >
1519
- where F : FnMut ( U256 ) -> Result < bool , E >
1525
+ where F : FnMut ( U256 ) -> bool
1520
1526
{
1521
1527
while upper - lower > 1 . into ( ) {
1522
1528
let mid = ( lower + upper) / 2 . into ( ) ;
1523
1529
trace ! ( target: "estimate_gas" , "{} .. {} .. {}" , lower, mid, upper) ;
1524
- let c = cond ( mid) ? ;
1530
+ let c = cond ( mid) ;
1525
1531
match c {
1526
1532
true => upper = mid,
1527
1533
false => lower = mid,
0 commit comments