Skip to content

get transaction count erigon#2863

Closed
leonardchinonso wants to merge 6 commits into
erigontech:develfrom
leonardchinonso:leonardchinonso_get_transaction_count_erigon
Closed

get transaction count erigon#2863
leonardchinonso wants to merge 6 commits into
erigontech:develfrom
leonardchinonso:leonardchinonso_get_transaction_count_erigon

Conversation

@leonardchinonso

Copy link
Copy Markdown
Contributor

Trying to detect the bug for eth_getTransactionCount as 'pending' returns 0x0 all the time. Meanwhile, Found is true and Nonce is 0.
Also, 'latest' returns the wrong Nonce value as its not consistent with goerli etherscan.

@Giulio2002

Giulio2002 commented Oct 23, 2021

Copy link
Copy Markdown
Contributor

Remove LeonardChinoso from the PR name, just some styling ;-) .

@Giulio2002

Copy link
Copy Markdown
Contributor

Before using the modified dependency of Erigon-Lib, perhaps you should wait until the PR from @AlexeyAkhunov is merged. Also i see it is a draft PR so another reason you should not change it yet. maybe for now mark this as draft :)

@AskAlexSharov

Copy link
Copy Markdown
Collaborator

I thought Alex's PR is just an example.

@leonardchinonso leonardchinonso changed the title Leonardchinonso get transaction count erigon get transaction count erigon Oct 27, 2021
@leonardchinonso

Copy link
Copy Markdown
Contributor Author

Yes its just an example. I followed his example to recreate it on here. However, as you know, I'm still having bugs

@leonardchinonso leonardchinonso deleted the leonardchinonso_get_transaction_count_erigon branch October 29, 2021 10:23
Sahil-4555 pushed a commit to Sahil-4555/erigon that referenced this pull request May 20, 2026
## Summary

Bumps the EEST devnet fixtures from `tests-bal@v7.1.1` to
`tests-bal@v7.2.0` and adapts Erigon to the EIP-8037 spec change that
ships with it.

### What changed in EEST v7.2.0

The only behavioural change in the new fixtures is execution-specs PR
[erigontech#2863](ethereum/execution-specs#2863) —
"EIP-8037 SSTORE/collision clear dynamics":

- Inline `state_gas` refunds (`SSTORE` original-zero reset, `CREATE`
collision/revert) now credit the local frame's `state_gas_left`
**immediately**, instead of being clamped to a per-frame
`state_gas_used` counter and bubbled up as a pending credit.
- `Evm.state_gas_used` becomes a **signed** counter — it goes negative
when refunds in a frame outweigh the frame's own charges (typical for
`DELEGATECALL`/`CALLCODE` callees that clear a slot an ancestor set).
- `incorporate_child_on_success` no longer propagates a pending refund;
`incorporate_child_on_error` restores the parent's reservoir via the
`state_gas_left + state_gas_used` invariant.
- `process_transaction` computes block state gas as `Uint(max(0,
intrinsic_state + state_gas_used − state_refund))`.

Bulk of the rest of the v7.2.0 diff is additional BAL test coverage
synchronised from `forks/amsterdam`.

### Erigon changes

- `test-fixtures.json`: bump `eest_devnet` to `tests-bal@v7.2.0` (sha256
`fc1d9ae1…`, 611 743 632 bytes).
- `execution/protocol/mdgas/md_gas.go`: `MdGasUsage` keeps `Regular
uint64` but `State` becomes `int64`. Adds
`MdGasUsage.PlusIntrinsic(MdGas)`, `MdGasUsage.StateClamped()` (=
`uint64(max(0, State))`), and `MdGasUsage.Total() = Regular +
StateClamped()`. `MdGas` (reservoirs / leftover) keeps both fields
`uint64`.
- `execution/vm/interpreter.go`: `CallContext.frameStateUsed` is now
`int64`. `refundCreditPending` is removed. `creditStateGasRefund` drops
the clamp — it does `stateGas += amount; frameStateUsed -=
int64(amount)` directly.
- `execution/vm/instructions.go`:
`op{Call,CallCode,DelegateCall,StaticCall,execCreate}` drop the
`PendingStateGasCredit` absorption; success path is just
`scope.frameStateUsed += childUsed.State` (signed).
- `execution/vm/evm.go`:
- `evm.call` / `evm.create` use a named return `gasRemaining` (renamed
from `leftOverGas`) and `gas` as the parameter; mutations are visible in
the body.
- `handleFrameRevert(gasRemaining *MdGas, …, stateGasUsed int64)` takes
the signed state usage and restores the parent reservoir via
`gasRemaining.State + stateGasUsed`. Includes a panic on the invariant
violation `state_gas_left + state_gas_used < 0` so any future regression
in the `useMdGas`/`creditStateGasRefund` pairing surfaces loudly rather
than silently wrapping the `uint64` cast.
- The depth-0 defers fold the spec's error semantics into
`gasUsed.State`: CALL error resets it to `0`; CREATE error sets it to
`-StateGasNewAccount` (mirrors the spec's `state_refund +=
STATE_BYTES_PER_NEW_ACCOUNT * COST_PER_STATE_BYTE` on CREATE-tx
failure). `TxnExecutor` then reads `gasUsed.State` directly without an
error-path branch.
- Extracts `deriveFrameRegularGasUsed(inputTotal, gasRemainingTotal
uint64, stateGasUsed int64) uint64` — `Regular = (input − leftover) −
state` in signed `int64` so a refund-heavy frame whose
`gasRemaining.State` grew above the input still yields the correct
positive regular-ops count (a guarded `uint64` subtraction would
mis-skip and return 0).
- `execution/protocol/txn_executor.go`: Amsterdam branches collapse the
spec's `tx_state_gas = intrinsic_state + state_gas_used` +
`block_state_gas_used += max(0, tx_state_gas)` into `combined :=
gasUsed.PlusIntrinsic(imdGas); st.blockStateGasUsed =
combined.StateClamped(); st.txnGasUsedB4Refunds = combined.Total()`.

### Tests

- `execution/vm/evm_test.go` (new): `TestDeriveFrameRegularGasUsed` with
four sub-cases — charges-only, with-spillover, refunds-exceed-charges
(the edge case the old guarded subtraction returned `0` for), and
pure-refund. Worked numeric examples are documented inline.

## Test plan

- [x] `make lint` clean.
- [x] `go test ./execution/vm/... ./execution/protocol/...` — unit tests
green.
- [x] EEST shards on the new fixtures, 0 failures:
  - `statetests-devnet` (65 202 tests)
  - `blocktests-devnet` (82 941 tests)
  - `blocktests-devnet-race-amsterdam` (21 368 tests)
- [x] Regression check against stable fixtures, 0 failures:
  - `statetests-stable` (63 556 tests)
  - `blocktests-stable-{sequential,parallel}` (69 256 tests each)
  - `enginextests-stable-{sequential,parallel}` (63 920 tests each)
- [x] The originally failing variants now pass:
`tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_restoration_refund_credits_local_reservoir[fork_Amsterdam-state_test-depth_{1,3,10}-refund_funds_create]`.
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.

3 participants