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

eth_getTransactionCount does not include pending transactions when 'pending' qualifier given for a deployed contract #19103

Closed
icetr8 opened this issue Feb 15, 2019 · 6 comments

Comments

@icetr8
Copy link

icetr8 commented Feb 15, 2019

Hi!

Similar issue with #2880 but in this issue I want to get the transaction count of a deployed contract.

eth_getTransactionCount does not include pending transactions when 'pending' qualifier is given for a deployed contract

web3.eth.getTransactionCount(myDeployedContract, "pending");

For example my contract, named as ContractCreator, has a createContract function that when executed will deploy another contract. In order to determine what is the address that been deployed by the ContractCreator. I will use ethereumjs-util generateAddress function

ethereumjs-util.generateAddress(ContractCreatorAddress, transactionCount)

System information

Geth and OS version: Geth/v1.8.22-omnibus-260f7fbd/linux-amd64/go1.11.1 using a public node ropsten.infura.io

Expected behaviour

Return the transactionCount including pending transaction

Actual behaviour

> let contractCreatorAddress = "0x123..."
> web3.eth.getTransactionCount(contractCreatorAddress, "pending");
215
> web3.eth.sendTransaction({to: contractCreatorAddress, data: "<a-function-that-deploys-another-contract>" })

> web3.eth.getTransactionCount(contractCreatorAddress, "pending");
215 (should be 216)
@karalabe
Copy link
Member

This is an interesting corner case (ping @fjl @holiman). A while ago we changes the pending nonce API to return the nonce from the txpool, not from the pending state. The reason is that the pending state just contains a few txs (that fit in the next block) vs. the txpool contains all the txs. However, the txpool obviously cannot figure out the nonce of a contract, since it doesn't execute code.

The issue with your use case is that the only way to accurately return the pending nonce of a contract is to execute all the transactions. With thousands of txs queued up, that's not feasible. I think the practical answer is that you should try to not depend on pending contract state, as it's unreliable.

@holiman
Copy link
Contributor

holiman commented Feb 18, 2019

I think the practical answer is that you should try to not depend on pending contract state, as it's unreliable.

I agree.

@icetr8
Copy link
Author

icetr8 commented Feb 20, 2019

@karalabe Is this the pull request #15794 you are talking about, that changes the pending nonce API from the pending state to the txpool.

@karalabe
Copy link
Member

@angelosuinan yes

@stale
Copy link

stale bot commented Feb 21, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@karalabe
Copy link
Member

karalabe commented Apr 9, 2020

Unfortunately we cannot fix this issue. Retrieving pending contract state is not meaningfully possible, since it would entail executing all the transactions in the pool (20 blocks' worth).

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

No branches or pull requests

5 participants