Changing logic related to estimation

This commit is contained in:
Richard Ramos 2018-09-01 00:44:14 -04:00
parent 8efd444a79
commit 3f56fd4676
3 changed files with 21 additions and 9 deletions

View File

@ -108,7 +108,7 @@ class MessageProcessor {
validationResult.estimatedGas = await this.web3.eth.estimateGas(p);
}
p.gas = parseInt(validationResult.estimatedGas * 1.05, 10); // Tune this
p.gas = Math.floor(parseInt(validationResult.estimatedGas, 10)); // Tune this
const nodeBalance = await this.web3.eth.getBalance(this.config.node.blockchain.account);

View File

@ -1,6 +1,9 @@
const Strategy = require('./BaseStrategy');
const erc20ABI = require('../../abi/ERC20Token.json');
const CallGasRelayed = "0xfd0dded5";
const ApproveAndCallGasRelayed = "0x59f4ac61";
/**
* Class representing a strategy to validate a `transaction` request when the topic is related to Identities.
* @extends Strategy
@ -64,16 +67,25 @@ class IdentityStrategy extends Strategy {
let estimatedGas = 0;
try {
// Geth tends to fail estimation with proxies, so we simulate it with ganache
const simReceipt = await this._simulateTransaction(input);
estimatedGas = this.web3.utils.toBN(simReceipt.gasUsed);
// TODO: Investigate why sometimes geth fails estimations with proxies
if(input.functionName == CallGasRelayed){
estimatedGas = await this._estimateGas(input);
} else {
const tmp = Math.floor(parseInt((await this._estimateGas(input)).toString(10), 10) * 1.05);
console.log(tmp);
estimatedGas = this.web3.utils.toBN(tmp); // TODO: tune this
}
if(gasLimit.lt(estimatedGas)) {
return {success: false, message: "Gas limit below estimated gas (" + estimatedGas + ")"};
}
} catch(exc){
if(exc.message.indexOf("revert") > -1) return {success: false, message: "Transaction will revert"};
console.log(exc);
else {
console.error(exc);
return {success: false, message: "Couldn't process transaction"};
}
}
return {

View File

@ -119,7 +119,7 @@ contract IdentityGasRelay is Identity {
uint startGas = gasleft();
//verify transaction parameters
require(startGas >= _gasLimit);
//require(startGas >= _gasLimit); // TODO: Tune this
require(_nonce == nonce);
//verify if signatures are valid and came from correct actors;
@ -255,7 +255,7 @@ contract IdentityGasRelay is Identity {
uint startGas = gasleft();
//verify transaction parameters
require(startGas >= _gasLimit);
// require(startGas >= _gasLimit); // TODO: tune this
require(_nonce == nonce);
//verify if signatures are valid and came from correct actors;