Refactor eth tx nonce subsystem and enforce linear growth #1617
Refactor eth tx nonce subsystem and enforce linear growth #1617libotony wants to merge 8 commits into
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
e364bad to
b86998f
Compare
| 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 | ||
| } |
There was a problem hiding this comment.
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) ?
Summary
Builds on
eth-equivalence(which already has on-state nonce wiring from #1616 with two changes:Refactor
state.Account.Nonce:[]uint64withrlp:"tail"→uint64withrlp:"optional"(same byte-encoding, simpler in-memory shape).runtime/statedb: struct-with-txType-field →StateDBinterface with V1 (no-op SetNonce) and V2 (write-through SetNonce). Dispatched bytxCtx.TypeinRuntime.newStateDB.PrepareTransaction(post-clause) toPrepareClause(pre-evm.Call). Mirrors Ethereum's nonce-write-outside-EVM-snapshot pattern; on VMErr, eth tx skips the outerstate.RevertToso the increment survives.Add
<reject,>queue/defer/invalid,==admit.Checklist: