3

I am building a game and want to send multiple move transactions in quick succession. But when I do that I get two transactions with the same hash when the recent block hash didn't change yet and I think then one of the gets just dropped by the RPC or validator.

I see two option to fix this.

  1. I bundle multiple move instructions in the same transaction as long as the block hash is still the same. But i'm not sure how to figure out when it changes.
  2. I add some arbitrary byte somewhere in the instruction data to get another hash, which sounds also stupid.
  3. Maybe there is some other solution to the problem?

1 Answer 1

3

The Problem

You've identified the crux of it -- you need two different recent blockhashes if the rest of your transaction data is the same, otherwise the second one will be rejected.

Currently, that's difficult to do through the RPC, and you just sort of need to wait a slot, but that sounds like a no-go for you due to your stated requirement of rapid succession.

The Workaround

If you must send separate transactions, the most robust way to handle this issue is to append an instruction to your transactions whenever your RPC call to fetch a recent blockhash is the same as your previously fetched blockhash. The memo program will do. This would add thirty-some bytes to your total transaction size. Although yes, it is hacky.

The Possible X-Y Problem

The much simpler approach is put both of the instructions in the same transaction.

One should only need to send transactions in rapid succession if both of these conditions hold true:

  1. Your program just never knows whether it may want to send another transaction milliseconds into the future, and
  2. Latency is extremely important to you and your use case requires the blockchain state to change as soon as possible.
1
  • Thank you very much! I am now waiting for the next block in case its still the same. That works, but i loose some milliseconds. I will try the memo approach and just add it when they are the same. I want to get max possible performance. I also want to try to remove the RPC call if possible because now its rate limiting me sometimes. Are the block hashes deterministic?
    – Jonas H.
    Commented Dec 6, 2022 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.