Changing logic related to estimation
This commit is contained in:
parent
8efd444a79
commit
3f56fd4676
|
@ -108,10 +108,10 @@ 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);
|
||||
|
||||
|
||||
if(nodeBalance < p.gas){
|
||||
reply("Relayer unavailable");
|
||||
console.error("Relayer doesn't have enough gas to process trx: %s, required %s", nodeBalance, p.gas);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue