Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nervous-bees-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/l2geth': patch
---

Return a better error message for when the nonce is too high. Previously it would return `nonce too low` for even when the nonce was too high. Now it will return `nonce too high` to the user
5 changes: 5 additions & 0 deletions .changeset/yellow-yaks-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/integration-tests': patch
---

Add tests for nonce too low and too high
26 changes: 26 additions & 0 deletions integration-tests/test/rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ describe('Basic RPC tests', () => {
expect(result.data).to.equal(tx.data)
})

it('should reject a transaction with a too low of nonce', async () => {
const tx = {
...defaultTransactionFactory(),
gasPrice: await gasPriceForL2(env),
nonce: (await wallet.getTransactionCount()) - 1,
}

const signed = await wallet.signTransaction(tx)
await expect(provider.sendTransaction(signed)).to.be.rejectedWith(
'invalid transaction: nonce too low'
)
})

it('should reject a transaction with a too high of a nonce', async () => {
const tx = {
...defaultTransactionFactory(),
gasPrice: await gasPriceForL2(env),
nonce: (await wallet.getTransactionCount()) + 10,
}

const signed = await wallet.signTransaction(tx)
await expect(provider.sendTransaction(signed)).to.be.rejectedWith(
'invalid transaction: nonce too high'
)
})

it('should not accept a transaction with the wrong chain ID', async () => {
const tx = {
...defaultTransactionFactory(),
Expand Down
5 changes: 4 additions & 1 deletion l2geth/core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,11 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
}
// Ensure the transaction adheres to nonce ordering
if rcfg.UsingOVM {
if pool.currentState.GetNonce(from) != tx.Nonce() {
nonce := pool.currentState.GetNonce(from)
if nonce > tx.Nonce() {
return ErrNonceTooLow
} else if nonce < tx.Nonce() {
return errors.New("nonce too high")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use the concrete ErrNonceTooHigh error:

ErrNonceTooHigh = errors.New("nonce too high")

}
} else {
if pool.currentState.GetNonce(from) > tx.Nonce() {
Expand Down