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

Invalid Sequence Error #45

Closed
touhonoob opened this issue Jul 5, 2019 · 4 comments
Closed

Invalid Sequence Error #45

touhonoob opened this issue Jul 5, 2019 · 4 comments

Comments

@touhonoob
Copy link

Got the following error when trying to send multiple orders simultaneously

bad response, status code 403, response: {\"code\":403,\"failed_tx_index\":0,\"message\":\"Invalid sequence. Got 40, expected 41\",\"success_tx_results\":[]}\n"
@unclezoro
Copy link
Contributor

Hi, send the transaction of the same address simultaneously will indeed cause Invalid sequence error.
To defend the replay attack, the sequence of an address should increase in order. But if send transaction too fast(use async/sync) or simultaneously, the previous transaction haven't included in block yet, go-sdk will fetch the current sequence and sign new transaction, cause sequence discontinuous.
Because there is no guarantee the previous transaction will be included in block, so we get account sequence each time before send the transaction instead of increase it automatically.

@touhonoob
Copy link
Author

@guagualvcha Is it possible to allow users to assign sequence number for each transaction manually? For applications like market making bot it's fatal to send both bid & ask orders at the same time.

@unclezoro
Copy link
Contributor

make sense. I will submit a PR soon.

@unclezoro
Copy link
Contributor

@touhonoob hi, go-sdk have updated to support custom sequence.
example:

acc,err:=client.GetAccount(client.GetKeyManager().GetAddr().String())
_, err = client.CreateOrder(tradeSymbol, nativeSymbol, msg.OrderSide.BUY, 100000000, 100000000, true, transaction.WithAcNumAndSequence(acc.Number,acc.Sequence))
_, err = client.CreateOrder(tradeSymbol, nativeSymbol, msg.OrderSide.BUY, 100000000, 100000000, true, transaction.WithAcNumAndSequence(acc.Number,acc.Sequence+1))
_, err = client.CreateOrder(tradeSymbol, nativeSymbol, msg.OrderSide.BUY, 100000000, 100000000, true, transaction.WithAcNumAndSequence(acc.Number,acc.Sequence+2))

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

2 participants