Skip to content
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

block timestamp is older than transaction creation time #24788

Closed
mlesterdampios opened this issue Apr 29, 2022 · 1 comment
Closed

block timestamp is older than transaction creation time #24788

mlesterdampios opened this issue Apr 29, 2022 · 1 comment

Comments

@mlesterdampios
Copy link

I am trying to do some time-sensitive application.
I just noticed that when I created a transaction at let say 12:00:01,
it's block timestamp is showing at 11:59:XX

Correct me if i'm wrong.
I understand that blocks that started mining can contain new transactions that's why my tx falls to the last block.

My main question is, how can I assure that my transaction will fall into the earliest valid block, especially when the condition is block.timestamp >= someDeadline ?

I made some readings here: #24152
But I still got no idea on how to precisely do timers with this.

Thank you so much!

@rjl493456442
Copy link
Member

rjl493456442 commented Apr 29, 2022

The timestamp of block is assigned when the mining block is constructed. In the next ten seconds (because the average block time is around 12 seconds), miner will try to re-generate the mining block with latest pending transaction list every three seconds, with the origin timestamp, to increase the revenue. So it can explain why your transaction is included in a block with smaller timestamp.

My main question is, how can I assure that my transaction will fall into the earliest valid block, especially when the condition is block.timestamp >= someDeadline ?

I will recommend you to set the condition in your contract. Solidity does support to retrieve the timestamp of the current block, so you can compare and control the flow? https://docs.soliditylang.org/en/v0.8.13/units-and-global-variables.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants