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

Map nonce of transaction when creating contracts #20

Open
Agusx1211 opened this issue Jun 15, 2020 · 3 comments
Open

Map nonce of transaction when creating contracts #20

Agusx1211 opened this issue Jun 15, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@Agusx1211
Copy link
Member

Ether.js obtains the address of a deployed contract by computing it using the sender address + nonce, on EOAs this nonce is globally shared and increases with any transaction, but on Sequence the nonce is exclusive to contract creations.

One possible fix would be to modify the contract creation transaction receipts in such a way that their nonce matches the contract creation nonce. This could be difficult to achieve because the 'contract creation nonce' it's not easily trackeable.

A simpler alternative would be to use a different nonce space for contract creations

@Agusx1211 Agusx1211 added the bug Something isn't working label Jun 15, 2020
@d-mariano
Copy link

Hello, my name is Dave Mariano. I am fascinated with what Horizon is doing and want to learn more. I'm interested in tackling this issue for you. I have forked your repo and have been poking around.

I think the contract creation nonce could be tracked in a different space, as you suggested, by incrementing the current nonce only if the transaction receipt's contractAddress value is populated, which should be a clear indicator that a contract was created.

My plan is to test this and the behaviour of nonces and transaction counts vs number of contracts created locally. Any advice for maintaining a consistent environment is appreciated. Also please see issue #23 as the contribution guidelines are missing.

I have a few questions/confirmations to make sure I am understanding the problem correctly. Please forgive my ignorance, I'm eager to contribute and even join the team:

  1. When you mention "on Sequence", do you simply mean when a contract account is creating contracts in sequence? I'm only asking because Sequence is capitalized and I'm not sure if this is another provider or package that I'm unaware of. Again, pease forgive my ignorance.
  2. The documentation for web3 always suggest using the transaction count to get the nonce, even though (as you have mentioned) contract accounts only increment their nonce when a contract is created. I just want to confirm this is the use case we're covering here?
  3. It looks like we're getting the transaction count from the Arcadeum API through GetMetaTxnNonce. Please correct me here, I just followed through the code and noticed the relayer is doing this through ChaindService. Would this consider pending transactions as well? From what I have been reading web3 does not do this by default, it instead uses the head of the blockchain. We can overwrite this to use the currently mined block and include pending transactions: i.e: getTransactionCount(address, 'pending')
  4. In addition to the above, would I be able to view the source for this API, would love to see how this is implemented. Please direct me to the correct spot if this is already available.
    4.Are we at the point where a nonce manager is required? I have read that the nonce can get out of sync for a few reasons, like having multiple wallets or something of that nature, but I don't know if that even applies here.

@Agusx1211
Copy link
Member Author

Hi @d-mariano, first and foremost thanks for your help, we really appreciate it! 😄

  1. Sequence refers to this project itself, sorry for the confusion with that, we are working on the names of the products and I mixed them up.

  2. You got it exactly right, EOAs nonces are used during contract creation but those nonces are increased with every kind of transactions, but when creating a contract using another contract there is another "hidden" nonce that's only increased when a contract is created.

  3. Ideally Arcadem.js should be able to work with and without the hosted relayer, we created a common interface for the relayers and right now we have two implementations that should work almost the same (LocalRelayer and RpcRelayer). Getting the latests nonce for the wallet is easy, we can use the getNonce method of the interface, but getting the nonce for a confirmed meta-transaction is going to be more difficult using the LocalRelayer.

  4. The api code is private at the moment, but we have plans to release the code soon. I will ask the team and maybe we can open-source it already or at least give you access.

@d-mariano
Copy link

@Agusx1211 I appreciate the quick response! Happy Canada Day, by the way! I'm sorry to bother you on a holiday. :)

It's good to hear I'm on the right track. I'll try working through this with the LocalRelayer.

Thank you for offering to bring the request to the team, that would be awesome. If you need to contact me directly feel free to do so @ [email protected]. I have reached out to Horizon a few days ago so maybe my name and email are familiar!

Thanks again,

Dave

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants