Hi !
We have observed a very strange behaviour coming up from the RequestedBallBuy
event from this transaction: https://mumbai.polygonscan.com/tx/0x1d6871b6f5171944d34a80f8c4753e9ac112d2847fa4c631bc018564907a5f07#eventlog
Here you can see the entries created from this event:
The first one holds the correct requestId
value, meanwhile the second doesnât. The first one createdAt
is 30 Apr 2022 at 13:09:54 UTC meanwhile the second one is 30 Apr 2022 at 12:56:29 UTC (~15 minutes earlier). The first one is confirmed, the second one is not. This time difference matches an approximate duration of 100 blocks to be minted so a confirmation becomes confirmed on Polygon.
For context, we had a conversation at Unconfirmed events no longer sync on Mumbai (polygon testnet) that gives some insights about this. Since then, we have made our logic able to handle these different cases, however this time around itâs a bit different: the values on each record are different.
The transaction_index
and log_index
are also different. block_hash
and block_number
are the same, however the block_timestamp
is different (the correct requestId
was logged 5 seconds earlier than the wrong one). We are not sure what this means in terms of miners picking the transaction from the mempool and minting the block with a 5 seconds difference, is this chain reorganisation ?
For completeness, the source code that generates this requestId
value (on-chain):
function _getRequestRandomId() private view returns (uint256) {
return
uint256(
keccak256(
abi.encodePacked(
block.timestamp,
_msgSender(),
_requestIdNonce
)
)
) % 1000000000;
}
(where _requestIdNonce is a number starting from 0 and increments 1 by 1 for each request)
Itâs obvious that not using the block.timestamp
as a source of compute could potentially solve the issue, but then the _requestIdNonce
might also be different if the second time the block was created the transactions order is not the same and the contract state does not match. This solution might be flawky, Iâm all ears to listen for a better one that allows callers to have more than one request at a time and more than one request emitted in the same block.
Is this a behaviour that should be handled on our side ? How could we approach it ? If we are given wrong data and only 15 minutes later we receive the right one, I donât see any way to prevent our logic to run with the first one.
In case helpful => Server URL: https://5o8m7xjcginv.usemoralis.com:2053/server
Thank you very much for your support