Skip to content

Simplex: Find last non-simplex block - #5783

Draft
yacovm wants to merge 1 commit into
ava-labs:masterfrom
yacovm:lastNonSimplexInnerBlock
Draft

Simplex: Find last non-simplex block#5783
yacovm wants to merge 1 commit into
ava-labs:masterfrom
yacovm:lastNonSimplexInnerBlock

Conversation

@yacovm

@yacovm yacovm commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Why this should be merged

Simplex can be activated for the first time either on top of a genesis block (new L1), or on top of a snowman block built by proposerVM (migration from snowman to Simplex).

(And in the future, via state-sync assisted boostrapping).

In any of the above cases, Simplex needs to identity the last block that is not a Simplex block, in order for Simplex to know:

  1. What is the next sequence number / block height to build on (to continue from the next sequence where snowman left off)
  2. Which previous block hash to point to
  3. What is the P-chain height that the Simplex L1 starts with, which is encoded by the proposerVM and not by Simplex.

How this works

This commit adds a function - locateLastNonSimplexBlock() which given the genesis block, the proposerVM, the DB simplex stores finalizations in, and the number of blocks in the L1 chain, returns the last non-simplex block, if applicable.

The function performs a binary search for the simplex block with the lowest sequence, and returns the block before it.

How this was tested

unit tests are included.

Need to be documented in RELEASES.md?

Simplex can be activated for the first time either on top of a genesis block (new L1),
or on top of a snowman block built by proposerVM (migration from snowman to Simplex).

(And in the future, via state-sync assisted boostrapping).

In any of the above cases, Simplex needs to identity the last block that is not a Simplex block,
in order for Simplex to know:

1. What is the next sequence number / block height to build on (to continue from the next sequence where snowman left off)
2. Which previous block hash to point to
3. What is the P-chain height that the Simplex L1 starts with, which is encoded by the proposerVM and not by Simplex.

This commit adds a function - locateLastNonSimplexBlock() which given the genesis block, the proposerVM, the DB simplex stores finalizations in,
and the number of blocks in the L1 chain, returns the last non-simplex block, if applicable.

Signed-off-by: Yacov Manevich <yacov.manevich@avalabs.org>
Copilot AI review requested due to automatic review settings August 6, 2026 20:05
@yacovm
yacovm requested a review from a team as a code owner August 6, 2026 20:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a helper to identify the last pre-Simplex (non-Simplex) block by combining proposerVM height lookups with a DB-backed binary search over stored Simplex finalizations. This supports first-time Simplex activation on a fresh chain, on top of an existing Snowman chain (migration), and scenarios where historical proposerVM blocks may be missing (e.g., state-sync windows).

Changes:

  • Add locateLastNonSimplexBlock and supporting helpers to detect whether the chain tip is pre-Simplex and, if not, find the first Simplex-accepted block via sort.Search over finalization keys.
  • Add comprehensive unit tests covering activation positions, missing proposerVM history, DB failures, and unexpected proposerVM errors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
simplex/storage.go Introduces locateLastNonSimplexBlock with helpers to find the first Simplex finalization and return the preceding non-Simplex block when retrievable.
simplex/storage_test.go Adds unit tests for the locator logic across expected edge cases and error paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@yacovm
yacovm marked this pull request as draft August 7, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants