-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: block.timestamp is not accurate #3398
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
fix: block.timestamp is not accurate #3398
Conversation
|
@slowli PTAL |
slowli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could be worth exploring a slightly differing approach: decoupling setting a new block in the UpdatesManager and in BatchExecutor. Namely, as soon as a new block is added in the current workflow, it is still added in UpdatesManager, but is not sent to BatchExecutor. Instead, it is only sent to BatchExecutor after receiving the first transaction in the block with the updated timestamp (obviously, the timestamp needs to be updated in UpdatesManager as well). IMO, this would make it slightly easier to reason about correctness.
slowli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIU, this implementation is incomplete at least mathematically. Namely, if a node is restarted in the middle of a batch, logic in restore_state will request new block params at the end; i.e., the timestamp of the created new block may be outdated as previously. I think this could be fixed by passing the initial is_sealed / is_last_block_sealed value to process_l1_batch, and creating this new block (if appropriate) inside process_l1_batch.
a801131 to
47f249e
Compare
86e8242 to
d50917c
Compare
44f2a75 to
aac812d
Compare
slowli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than get_next_l2_block_timestamp_as_mut(), looks good, although as I mentioned in a previous reply, I think the fix as-is is incomplete (could be improved in a separate PR).
slowli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job 👍
- Ideally, it'd make sense to unit-test the changes using a mock
StateKeeperIO/ batch executor implementations to check that the L2 block timestamp is indeed updated if there are no transactions, and that the timestamp passed to a VM instance is the updated one. Could wait for a follow-up PR. - Suggest for another review from the platform team (e.g., @perekopskiy or @Deniallugo ), but this isn't absolutely necessary.
…3643) ## What ❔ Add a unit test to ensure that l2 block timestamp is updated upon receiving the first transaction (#3398) ## Why ❔ Missing unit test on a new feature ## Is this a breaking change? - [ ] Yes - [x] No ## Operational changes No ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`.
🤖 I have created a release *beep* *boop* --- ## [26.5.0](core-v26.4.0...core-v26.5.0) (2025-03-03) ### Features * add a flag for stage1->stage2 validium migration ([#3562](#3562)) ([92e7895](92e7895)) * add custom DA support in external node ([#3445](#3445)) ([1a8546d](1a8546d)) * **contract-verifier:** add Etherscan contract verification ([#3609](#3609)) ([a4ea0f2](a4ea0f2)) * **da-clients:** raise Avail blob size to 1mb ([#3624](#3624)) ([0baa7ff](0baa7ff)) * **eigenda:** implement eigenDA client remaining features ([#3243](#3243)) ([88fc971](88fc971)) * preparation for new precompiles ([#3535](#3535)) ([3c1f3fb](3c1f3fb)) * **tee:** add support for recoverable signatures ([#3414](#3414)) ([7241a73](7241a73)) * **zkos:** Implement ZK OS Merkle tree ([#3625](#3625)) ([331e98c](331e98c)) ### Bug Fixes * **api:** Fix pending transactions filter again ([#3630](#3630)) ([7afa20f](7afa20f)) * **api:** lock simultaneous tx insertsion with mutex ([#3616](#3616)) ([644b621](644b621)) * block.timestamp is not accurate ([#3398](#3398)) ([adcb517](adcb517)) * Fflonk versioning ([#3610](#3610)) ([fc80840](fc80840)) * Limit number of connections open for GCS interactions ([#3637](#3637)) ([6b003e2](6b003e2)) ### Performance Improvements * **api:** Use watch channel in values cache updates ([#3663](#3663)) ([3a4bdcf](3a4bdcf)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: zksync-era-bot <[email protected]>
🤖 I have created a release *beep* *boop* --- ## [26.5.0](core-v26.4.0...core-v26.5.0) (2025-03-03) ### Features * add a flag for stage1->stage2 validium migration ([#3562](#3562)) ([92e7895](92e7895)) * add custom DA support in external node ([#3445](#3445)) ([db31e71](db31e71)) * **contract-verifier:** add Etherscan contract verification ([#3609](#3609)) ([f13bd80](f13bd80)) * **da-clients:** raise Avail blob size to 1mb ([#3624](#3624)) ([0baa7ff](0baa7ff)) * **eigenda:** implement eigenDA client remaining features ([#3243](#3243)) ([161da42](161da42)) * preparation for new precompiles ([#3535](#3535)) ([3c1f3fb](3c1f3fb)) * **tee:** add support for recoverable signatures ([#3414](#3414)) ([7241a73](7241a73)) * **zkos:** Implement ZK OS Merkle tree ([#3625](#3625)) ([331e98c](331e98c)) ### Bug Fixes * **api:** Fix pending transactions filter again ([#3630](#3630)) ([7afa20f](7afa20f)) * **api:** lock simultaneous tx insertsion with mutex ([#3616](#3616)) ([644b621](644b621)) * block.timestamp is not accurate ([#3398](#3398)) ([adcb517](adcb517)) * Fflonk versioning ([#3610](#3610)) ([fc80840](fc80840)) * Limit number of connections open for GCS interactions ([#3637](#3637)) ([6b003e2](6b003e2)) ### Performance Improvements * **api:** Use watch channel in values cache updates ([#3663](#3663)) ([3a4bdcf](3a4bdcf)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: zksync-era-bot <[email protected]>
🤖 I have created a release *beep* *boop* --- ## [26.5.0](matter-labs/zksync-era@core-v26.4.0...core-v26.5.0) (2025-03-03) ### Features * add a flag for stage1->stage2 validium migration ([#3562](matter-labs/zksync-era#3562)) ([92e7895](matter-labs/zksync-era@92e7895)) * add custom DA support in external node ([#3445](matter-labs/zksync-era#3445)) ([4ca2e03](matter-labs/zksync-era@4ca2e03)) * **contract-verifier:** add Etherscan contract verification ([#3609](matter-labs/zksync-era#3609)) ([180cd32](matter-labs/zksync-era@180cd32)) * **da-clients:** raise Avail blob size to 1mb ([#3624](matter-labs/zksync-era#3624)) ([0baa7ff](matter-labs/zksync-era@0baa7ff)) * **eigenda:** implement eigenDA client remaining features ([#3243](matter-labs/zksync-era#3243)) ([771e6f0](matter-labs/zksync-era@771e6f0)) * preparation for new precompiles ([#3535](matter-labs/zksync-era#3535)) ([3c1f3fb](matter-labs/zksync-era@3c1f3fb)) * **tee:** add support for recoverable signatures ([#3414](matter-labs/zksync-era#3414)) ([7241a73](matter-labs/zksync-era@7241a73)) * **zkos:** Implement ZK OS Merkle tree ([#3625](matter-labs/zksync-era#3625)) ([331e98c](matter-labs/zksync-era@331e98c)) ### Bug Fixes * **api:** Fix pending transactions filter again ([#3630](matter-labs/zksync-era#3630)) ([7afa20f](matter-labs/zksync-era@7afa20f)) * **api:** lock simultaneous tx insertsion with mutex ([#3616](matter-labs/zksync-era#3616)) ([644b621](matter-labs/zksync-era@644b621)) * block.timestamp is not accurate ([#3398](matter-labs/zksync-era#3398)) ([adcb517](matter-labs/zksync-era@adcb517)) * Fflonk versioning ([#3610](matter-labs/zksync-era#3610)) ([fc80840](matter-labs/zksync-era@fc80840)) * Limit number of connections open for GCS interactions ([#3637](matter-labs/zksync-era#3637)) ([6b003e2](matter-labs/zksync-era@6b003e2)) ### Performance Improvements * **api:** Use watch channel in values cache updates ([#3663](matter-labs/zksync-era#3663)) ([3a4bdcf](matter-labs/zksync-era@3a4bdcf)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: zksync-era-bot <[email protected]>
What ❔
Related to zkSync-Community-Hub/zksync-developers#820
Change the l2 block creation logic to start a new l2 block only when a transaction is ready to be executed.
Why ❔
Current logic starts a new l2 block as soon as the previous one is sealed.
A contract that relies on
block.timestampwould be able to predict the time correctly because if the l2 block goes stale (no transaction), then it will be open indefinitely and the timestamp will not be accurate anymoreSolution has been tested locally but any feedbacks would be appreciated
Checklist
zkstack dev fmtandzkstack dev lint.