Skip to content

Conversation

@thomas-nguy
Copy link
Member

@thomas-nguy thomas-nguy commented Dec 18, 2024

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.timestamp would 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 anymore

Solution has been tested locally but any feedbacks would be appreciated

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • Code has been formatted via zkstack dev fmt and zkstack dev lint.

@thomas-nguy thomas-nguy changed the title Fix: block.timestamp is not accurate fix: block.timestamp is not accurate Dec 18, 2024
@popzxc popzxc requested a review from slowli January 9, 2025 08:07
@popzxc
Copy link
Member

popzxc commented Jan 9, 2025

@slowli PTAL

Copy link
Contributor

@slowli slowli left a 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.

@thomas-nguy thomas-nguy requested a review from slowli January 13, 2025 11:43
Copy link
Contributor

@slowli slowli left a 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.

@thomas-nguy thomas-nguy force-pushed the thomas/fix-bloc-timestamp branch 2 times, most recently from a801131 to 47f249e Compare January 22, 2025 04:03
@thomas-nguy thomas-nguy force-pushed the thomas/fix-bloc-timestamp branch from 86e8242 to d50917c Compare January 29, 2025 02:14
@thomas-nguy thomas-nguy force-pushed the thomas/fix-bloc-timestamp branch from 44f2a75 to aac812d Compare February 7, 2025 09:22
Copy link
Contributor

@slowli slowli left a 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
slowli previously approved these changes Feb 11, 2025
Copy link
Contributor

@slowli slowli left a 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.

@slowli slowli added this pull request to the merge queue Feb 14, 2025
Merged via the queue into matter-labs:main with commit adcb517 Feb 14, 2025
32 of 33 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Mar 4, 2025
…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`.
github-merge-queue bot pushed a commit that referenced this pull request Mar 4, 2025
🤖 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-&gt;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]>
zkzoomer pushed a commit that referenced this pull request Jun 21, 2025
🤖 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-&gt;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]>
dutterbutter pushed a commit to dutterbutter/zkstack-cli that referenced this pull request Jul 3, 2025
🤖 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-&gt;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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants