From 25d2f24b03a0fa29629fe8fbb3a2c918fb49834b Mon Sep 17 00:00:00 2001 From: Kevin Peters Date: Fri, 28 Oct 2022 15:39:10 +0000 Subject: [PATCH] ethereum: deploy test token nonce race condition fix Noticed this error happening in tilt sometimes: [tests] Error: Returned error: VM Exception while processing transaction: the tx doesn't have the correct nonce. account has nonce of: 17 tx has nonce of: 16 It's not safe to submit txs in parallel, because the nonce can get out of sync. Instead we should submit them serially. --- ethereum/scripts/deploy_test_token.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/ethereum/scripts/deploy_test_token.js b/ethereum/scripts/deploy_test_token.js index 236f85ed1..76d68011e 100644 --- a/ethereum/scripts/deploy_test_token.js +++ b/ethereum/scripts/deploy_test_token.js @@ -16,19 +16,14 @@ const interateToStandardTransactionCount = async () => { ); const transactionsToBurn = 32 - transactionCount; - const promises = []; for (let i = 0; i < transactionsToBurn; i++) { - promises.push( - web3.eth.sendTransaction({ - to: accounts[0], - from: accounts[0], - value: 530, - }) - ); + await web3.eth.sendTransaction({ + to: accounts[0], + from: accounts[0], + value: 530, + }) } - await Promise.all(promises); - const burnCount = await web3.eth.getTransactionCount(accounts[0], "latest"); console.log("transaction count after burn: ", burnCount); @@ -36,7 +31,7 @@ const interateToStandardTransactionCount = async () => { return Promise.resolve(); }; -module.exports = async function(callback) { +module.exports = async function (callback) { try { const accounts = await web3.eth.getAccounts();