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

Intercept Sequential invokes and increment nonce #674

Closed
tabaktoni opened this issue Jul 3, 2023 · 2 comments
Closed

Intercept Sequential invokes and increment nonce #674

tabaktoni opened this issue Jul 3, 2023 · 2 comments
Labels
Type: bug Something isn't working

Comments

@tabaktoni
Copy link
Collaborator

tabaktoni commented Jul 3, 2023

Describe the bug

const tx = await cairo1Contract.array2d_ex(data);
const tx1 = await cairo1Contract.array2d_ex(data);
await account.waitForTransaction(tx.transaction_hash);
await account.waitForTransaction(tx1.transaction_hash);

This would fail because tx is in status (NOT_RECEIVED, RECEIVED) when tx1 start and request nonce, so nonce would be the same as the first one (as it only get updated once tx status is in ACCEPTED_ON_L2).
To resolve this contract class should store local transaction hashes, and when a new invoke is executed check the status of the latest transaction. If the status is NOT_RECEIVED or RECEIVED instead of getNonce request increment local nonce counter, else proceed with getNonce request.

This should be the default configuration, also there could be a flag to disable this behavior and always use getNonce?

To Reproduce
Run Test
https://github.com/0xs34n/starknet.js/blob/e564033273ac49e971bbf1db843fb3de236976c0/__tests__/cairo1v2.test.ts#L281

Expected behavior
To PASS not to FAIL with

GatewayError: Transaction with hash 0x3d04c5a95368cc329ef7444e6e3a49669932bb41716b9712e99b1b032e70aac already exists.

Additional context
@janek26 @dhruvkelawala

@tabaktoni tabaktoni added the Type: bug Something isn't working label Jul 3, 2023
@tabaktoni tabaktoni changed the title Intercept Sequential invokes Intercept Sequential invokes and increment nonce Jul 3, 2023
@PhilippeR26
Copy link
Collaborator

Take care that if tx fail in Starknet,tx1 and all following invokes (with the same account) will fail.
Not sure it has to be managed inside Starknet.js.
Users are responsible of their sequencing, and can use multiCall if they do not want to wait L2 acceptation between each transaction.

@tabaktoni
Copy link
Collaborator Author

Yea true, closing this issue with a note about this in the guides so the dev can expect this behavior

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

No branches or pull requests

2 participants