Nonces for user inputs to an underlying chain are calculated using [blockHeight] + [userAddress] + [game input]
Nonces from a batcher perspective are calculated using [millisecondTimestamp] + [userAddress] + [game input]
scheduledTxHash which gives the underlying tx hash for primitives
However, this is incomplete as it doesn't handle all 4 cases.
Additionally, a better tx hash than these nonces could be something like hash(caip2 prefix + underlying tx hash + idx) where idx is because one tx in the underlying chain can trigger multiple STF calls (ex: trigger multiple primitives). This would handle all cases except for timers though. Note: idx here is not a global counter or a per-block counter, but rather a per-tx counter. This means that idx can be computer on the client side theoretically (if they know how many STF calls their transaction will trigger, or if they just query for idx=0 from the node and check if any with higher IDs exist later)
For timers, we can do something like blockNumber + contents, but perhaps a different way to do it that is more tooling-friendly is to implement #387 first, then make that timers need a "percompile name" as an argument to set the address of these timers. This would allow us to do something like address + blockNumber + idx for the hash
Right now, transactions in Paima don't have a globally unique hash.
If we want a globally unique tx hash system, we have to consider the following cases for how the STF gets called:
We do have some similar concepts though:
[blockHeight] + [userAddress] + [game input]
[millisecondTimestamp] + [userAddress] + [game input]
scheduledTxHash
which gives the underlying tx hash for primitivesHowever, this is incomplete as it doesn't handle all 4 cases.
Additionally, a better tx hash than these nonces could be something like
hash(caip2 prefix + underlying tx hash + idx)
whereidx
is because one tx in the underlying chain can trigger multiple STF calls (ex: trigger multiple primitives). This would handle all cases except for timers though. Note:idx
here is not a global counter or a per-block counter, but rather a per-tx counter. This means thatidx
can be computer on the client side theoretically (if they know how many STF calls their transaction will trigger, or if they just query foridx=0
from the node and check if any with higher IDs exist later)For timers, we can do something like
blockNumber + contents
, but perhaps a different way to do it that is more tooling-friendly is to implement #387 first, then make that timers need a "percompile name" as an argument to set the address of these timers. This would allow us to do something likeaddress + blockNumber + idx
for the hash