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); 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); const nodeBalance = await this.web3.eth.getBalance(this.config.node.blockchain.account);

View File

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

View File

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