Skip to content

Proposer to propose multiple L2 blocks at once #553

New issue

Have a question about this project? Sign up for a free account to open an issue and contact its maintainers and the community.

By clicking “Sign up for ”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on ? Sign in to your account

Merged
merged 16 commits into from
Mar 14, 2022
Merged
PrevPrevious commit
Next Next commit
fix: restore nonce variable in nf3
  • Loading branch information
@daveroga
daveroga committedMar 10, 2022
commit 93dd0570f463636f8d02f890e03fe9c687a21a85
12 changes: 8 additions & 4 deletions cli/lib/nf3.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,8 @@ class Nf3 {

BLOCK_STAKE = DEFAULT_BLOCK_STAKE;

nonce = 0;

nonceMutex = new Mutex();

latestWithdrawHash;
Expand DownExpand Up@@ -130,6 +132,8 @@ class Nf3 {
async setEthereumSigningKey(key) {
this.ethereumSigningKey = key;
this.ethereumAddress = await this.getAccounts();
// clear the nonce as we're using a fresh account
this.nonce = 0;
}

/**
Expand DownExpand Up@@ -193,10 +197,8 @@ class Nf3 {
// we need a Mutex so that we don't get a nonce-updating race.

let tx;
let nonce;
await this.nonceMutex.runExclusive(async () => {
nonce = await this.web3.eth.getTransactionCount(this.ethereumAddress);
nonce += this.txsNotConfirmed; // we need to add the number of transactions not confirmed yet
if (!this.nonce) this.nonce = await this.web3.eth.getTransactionCount(this.ethereumAddress);
let gasPrice = 20000000000;
const gas = (await this.web3.eth.getBlock('latest')).gasLimit;
const blockGasPrice = 2 * Number(await this.web3.eth.getGasPrice());
Expand All@@ -209,8 +211,9 @@ class Nf3 {
value: fee,
gas,
gasPrice,
nonce,
nonce: this.nonce,
};
this.nonce++;
this.txsNotConfirmed++;
});

Expand All@@ -236,6 +239,7 @@ class Nf3 {
})
.on('error', err => {
this.txsNotConfirmed--;
if (err.message.includes('nonce')) this.nonce--;
reject(err);
});
});
Expand Down