-
Notifications
You must be signed in to change notification settings - Fork 375
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
Feature request: Unique time.Now() per transaction #1709
Comments
Just to make sure that we're aligned, here is what I expect: TX1 func CallMe() {
t1 := time.Now()
t2 := time.Now()
fmt.Println(t1.String())
fmt.Println(t2.String())
}
// Output:
// 2024-02-29 14:05:33.265165 +0100 CET m=+0.000095043
// 2024-02-29 14:05:33.265165 +0100 CET m=+0.000095043 TX2: func CallMe() {
t1 := time.Now()
t2 := time.Now()
fmt.Println(t1.String())
fmt.Println(t2.String())
}
// Output:
// 2024-02-29 14:05:33.265165 +0100 CET m=+0.000095126
// 2024-02-29 14:05:33.265165 +0100 CET m=+0.000095126 The key is not within a single TX but between independent TXs. Within a single TX, consistency is currently preferred. |
6 tasks
6 tasks
We won't be handling this feature request before the mainnet launch, primarily due to the bandwidth issues. Will keep open and possibly revisit in the future. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
I understand that
time.Now()
returns the same value for every call within a transaction (the block time). But there can be multiple transactions in a block. It would be useful fortime.Now()
to return different values for each transaction. (For example each call to r/demo/boards to post a message would give a unique message timestamp.) I tried the following goland code which callstime.Now()
twice in quick succession:It prints:
As you can see, even this returns unique values. Go developers may expect this to some extent.
Possible implementation
On a dev call, @moul suggested making each transaction offset the value of
time.Now()
using the transaction index within the block. For example, timestamp + tx.index * 100us . (The example value of 100us should be configured based on block time and max transactions per block so that atime.Now()
value won't overlap with the next block.)The text was updated successfully, but these errors were encountered: