Skip to content

Commit

Permalink
fix(quorum/api): contract deploy uses gas estimate
Browse files Browse the repository at this point in the history
Instead of hardcoding guesses regarding what the CI
environment will produce as a gas price for the contract
deployment be pro-active, ask for a quote and then offer to
spend the quote + a million gas to be on the safe side. This
should guarantee that there will be enough gas unless there's a
bug in the underlying network (which has happened in the past,
quorum had a gas bug where it was asking for more than the
maximum possible gas).

Also downgraded quorum to v2.2.5 because that is considered
stabl while 2.3.0 is a beta release and therefore it is possible
that has issues with the gas estimates like previous versions did.

Changed the gas upper and lower bounds for blocks through the
newly introduced CLI flags of Quorum eth:
Consensys/quorum#700 (comment)
https://github.com/jpmorganchase/quorum/blob/v2.2.5/cmd/utils/flags.go#L333
https://github.com/jpmorganchase/quorum/blob/v2.2.5/cmd/utils/flags.go#L343

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Dec 2, 2019
1 parent 9618d71 commit 1b74da4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ module.exports = (async () => {
}
tryCount += 1;
}
if (notSuccessful) {
throw new Error(`Failed to deploy contracts after ${maxTries} attempts. See logs above for details.`);
}
if (config.env !== 'test') {
/* Forcibly exit the process as we suspect that web3.js may leave dangling
open network connections that prevent normal exit. */
Expand Down
24 changes: 14 additions & 10 deletions examples/simple-asset-transfer/quorum/api/utils/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ const Contracts = {
},

async newPublicContract(contractObject, ...contractArguments) {
const newContract = await contractObject
.deploy({
arguments: contractArguments,
})
.send({
from: web3Ws.eth.defaultAccount,
gas: 10000000,
})
.on('transactionHash', txHash => logger.log('info', `newPublicContract: txHash:${txHash}`));
logger.log('debug', `newPublicContract: ${newContract.options.address}`);
const deployTask = contractObject.deploy({ arguments: contractArguments });
const gasEstimate = await deployTask.estimateGas({
from: web3Ws.eth.defaultAccount,
gas: 10000000,
});
const gas = gasEstimate * 3; // offer triple the gas estimate to be sure
const taskPayload = {
from: web3Ws.eth.defaultAccount,
gas,
};
logger.info(`newPublicContract: gasEstimate=%s taskPayload=%s`, gasEstimate, JSON.stringify(taskPayload));
const newContract = await deployTask.send(taskPayload);

logger.log('debug', `newPublicContract: deployment DONE. address=${newContract.options.address}`);
return newContract;
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ async function registerActor({ name, type, constKey, ethAddress, host, port }) {
host,
port
);
const receipt = await rootContract.methods
.registerActor(name, constKey, ethAddress, ActorTypes[type], host, port)
.send({
from: web3.eth.defaultAccount,
gas: 3000000,
});
const actorRegistrationTask = rootContract.methods
.registerActor(name, constKey, ethAddress, ActorTypes[type], host, port);

const gasEstimate = await actorRegistrationTask.estimateGas();
const gas = gasEstimate * 3; // offer triple the gas estimate to be sure
const taskPayload = {
from: web3.eth.defaultAccount,
gas,
};
logger.info(`registerActor gasEstimate=%s taskPayload=%s`, gasEstimate, JSON.stringify(taskPayload));
const receipt = await actorRegistrationTask.send(taskPayload);
logger.log('debug', 'registerActor receipt %j', receipt);
return receipt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ version: "3.6"
x-quorum-def:
&quorum-def
restart: "on-failure"
image: "${QUORUM_DOCKER_IMAGE:-quorumengineering/quorum:2.3.0}"
image: "${QUORUM_DOCKER_IMAGE:-quorumengineering/quorum:2.2.5}"
expose:
- "21000"
- "50400"
Expand Down Expand Up @@ -71,6 +71,10 @@ x-quorum-def:
--rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum,${QUORUM_CONSENSUS:-istanbul} \
--port 21000 \
--unlock 0 \
--mine \
--miner.threads 1 \
--miner.gaslimit 60000000 \
--miner.gastarget 10 \
--password /examples/passwords.txt \
${QUORUM_GETH_ARGS:-} $${GETH_ARGS_${QUORUM_CONSENSUS:-istanbul}}
x-tx-manager-def:
Expand Down

0 comments on commit 1b74da4

Please sign in to comment.