mirror of https://github.com/poanetwork/quorum.git
Merge pull request #644 from QuorumEngineering/estimategas-for-privatetransaction
EstimateGas to handle private transaction gas cost differences
This commit is contained in:
commit
2735367497
|
@ -55,6 +55,9 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultGasPrice = 50 * params.Shannon
|
defaultGasPrice = 50 * params.Shannon
|
||||||
|
|
||||||
|
//Hex-encoded 64 byte array of "17" values
|
||||||
|
maxPrivateIntrinsicDataHex = "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PublicEthereumAPI provides an API to access Ethereum related information.
|
// PublicEthereumAPI provides an API to access Ethereum related information.
|
||||||
|
@ -771,6 +774,33 @@ func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs) (h
|
||||||
return 0, fmt.Errorf("gas required exceeds allowance or always failing transaction")
|
return 0, fmt.Errorf("gas required exceeds allowance or always failing transaction")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//QUORUM
|
||||||
|
|
||||||
|
//We don't know if this is going to be a private or public transaction
|
||||||
|
//It is possible to have a data field that has a lower intrinsic value than the PTM hash
|
||||||
|
//so this checks that if we were to place a PTM hash (with all non-zero values) here then the transaction would
|
||||||
|
//still run
|
||||||
|
//This makes the return value a potential over-estimate of gas, rather than the exact cost to run right now
|
||||||
|
|
||||||
|
//if the transaction has a value then it cannot be private, so we can skip this check
|
||||||
|
if args.Value.ToInt().Cmp(big.NewInt(0)) == 0 {
|
||||||
|
|
||||||
|
isHomestead := s.b.ChainConfig().IsHomestead(new(big.Int).SetInt64(int64(rpc.PendingBlockNumber)))
|
||||||
|
intrinsicGasPublic, _ := core.IntrinsicGas(args.Data, args.To == nil, isHomestead)
|
||||||
|
intrinsicGasPrivate, _ := core.IntrinsicGas(common.Hex2Bytes(maxPrivateIntrinsicDataHex), args.To == nil, isHomestead)
|
||||||
|
|
||||||
|
if intrinsicGasPrivate > intrinsicGasPublic {
|
||||||
|
if math.MaxUint64 - hi < intrinsicGasPrivate - intrinsicGasPublic {
|
||||||
|
return 0, fmt.Errorf("private intrinsic gas addition exceeds allowance")
|
||||||
|
}
|
||||||
|
return hexutil.Uint64(hi + (intrinsicGasPrivate - intrinsicGasPublic)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//END QUORUM
|
||||||
|
|
||||||
return hexutil.Uint64(hi), nil
|
return hexutil.Uint64(hi), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue