Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

EthGetTransactionCount ignores input #10357

Closed
arajasek opened this issue Feb 27, 2023 · 3 comments · Fixed by #12520 · May be fixed by #10462
Closed

EthGetTransactionCount ignores input #10357

arajasek opened this issue Feb 27, 2023 · 3 comments · Fixed by #12520 · May be fixed by #10462
Assignees
Labels
area/api area/eth-api kind/bug Kind: Bug P2 P2: Should be resolved

Comments

@arajasek
Copy link
Contributor

The blkParam argument is ignored by EthGetTransactionCount, which instead always returns nonce based on the mempool. We should:

  • only call into the mempool if "pending" is supplied
  • get this value from State otherwise
  • consider dropping the TSK param passed to the mempool's GetNonce method
@virajbhartiya
Copy link
Member

I’ll like to work in this. @aarshkshah1992

@virajbhartiya
Copy link
Member

virajbhartiya commented Sep 27, 2024

@aarshkshah1992, I'd like to share my proposed implementation for handling the "pending" block case:

if blkParam.PredefinedBlock != nil && *blkParam.PredefinedBlock == "pending" {
    nonce, err := a.MpoolAPI.MpoolGetNonce(ctx, addr)
    if err != nil {
        return ethtypes.EthUint64(0), xerrors.Errorf("failed to get nonce from mpool: %w", err)
    }
    return ethtypes.EthUint64(nonce), nil
}
  1. It checks if blkParam.PredefinedBlock is not nil and specifically set to "pending".
  2. If the condition is met, it retrieves the nonce from the mempool using MpoolGetNonce.
  3. The mempool is only queried in this specific "pending" case, optimizing performance for other scenarios.

If it isn't "pending", return ethtypes.EthUint64(actor.Nonce), nil should do the job for non-evm actors.

@virajbhartiya
Copy link
Member

virajbhartiya commented Sep 27, 2024

As far as my understanding of mempool is that it is a temporary holding area for transactions that have been submitted to the network but haven't yet been included in a block. The mempool keeps track of the expected next nonce for each account based on pending transactions. When pending block is encountered, it queries the mempool for the latest nonce to get the most up-to-date state. Since querying the mempool can be more resource-intensive than querying the confirmed blockchain state, that is why we want to do it only for "pending" block requests.

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