Skip to content

Refactor eth tx nonce subsystem and enforce linear growth #1617

Open
libotony wants to merge 8 commits into
eth-equivalencefrom
tony/feat/eth-tx-v2-nonce
Open

Refactor eth tx nonce subsystem and enforce linear growth #1617
libotony wants to merge 8 commits into
eth-equivalencefrom
tony/feat/eth-tx-v2-nonce

Conversation

@libotony
Copy link
Copy Markdown
Member

Summary

Builds on eth-equivalence (which already has on-state nonce wiring from #1616 with two changes:

Refactor

  • state.Account.Nonce: []uint64 with rlp:"tail"uint64 with rlp:"optional" (same byte-encoding, simpler in-memory shape).
  • runtime/statedb: struct-with-txType-field → StateDB interface with V1 (no-op SetNonce) and V2 (write-through SetNonce). Dispatched by txCtx.Type in Runtime.newStateDB.
  • Nonce CALL-path inc moved from PrepareTransaction (post-clause) to PrepareClause (pre-evm.Call). Mirrors Ethereum's nonce-write-outside-EVM-snapshot pattern; on VMErr, eth tx skips the outer state.RevertTo so the increment survives.

Add

  • Linear nonce growth enforcement across txpool / packer / consensus. < reject, > queue/defer/invalid, == admit.
  • End-to-end eth tx execution tests (transfer / creation / revert preserves nonce / sponsored / fee floor / insufficient balance).
  • Multi-clause revert regression test.
  • Cross-coverage with evm-upgrades EIPs (7825 gas cap, 1153 transient storage isolation, 6780 same-tx + pre-existing selfdestruct)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • New and existing E2E tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have not added any vulnerable dependencies to my code

@libotony libotony requested a review from a team as a code owner May 11, 2026 10:06
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 11, 2026

@libotony libotony force-pushed the tony/feat/eth-tx-v2-nonce branch from e364bad to b86998f Compare May 11, 2026 12:40
Comment thread consensus/validator.go
Comment thread vm/evm.go
Comment thread runtime/runtime.go
Comment on lines -143 to -152
func (s *StateDB) GetNonce(addr common.Address) uint64 {
if s.txType != tx.TypeEthDynamicFee {
return 0
}
n, err := s.state.GetNonce(thor.Address(addr))
if err != nil {
panic(err)
}
return n
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Catalogging this for a chat later -

I like the approach, it pushes the logic upstream of wether the account should or should not have a Nonce.

This allows for a performance enhancement, no state -> cache pulling for accounts that can't possibly have a nonce.
(unless there's a hash colision, but even if that's the case, the nonce should not be updated because it would be going via the VechainTx path)

My concerns is that it's starting to look like all of this for one if statement.

What if these there was one statedb.New(), but with an optional param?

Something like:
New(state *state.State, nonceEnabled bool) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants