In a typical Web2 update endpoint, the system date/time of the application server will be used to set a timestamp with the saved record.
Since Internet Computer updates run on all nodes in the subnet to reach a two thirds consensus, and each node may run the function at different times, and the times are not guaranteed to be the same on all nodes, it does not appear that the result of an update function can be deterministic when including the side-effect of a system date/time.
My solution at the moment is as follows:
- Expose a public query function that returns the system epoch time (Time.now()) from the single node/canister that executes the function.
- Call the query function from the front-end to retrieve the nodeâs epoch time.
- Include the epoch time from the query function in the payload to the update function.
- In the update function, validate that the time provided is within n seconds of the current epoch time, since each canister executing the function may differ slightly and some time must be allotted for the network calls.
Note that I do not want to rely on the usersâ system times since those times can be tampered with.
Is this a necessary workflow to include timestamps with saved records or is there a better way? Thanks!