Skip to content

Simplex reconfiguration framework - Part IV (Address code review comments for initial draft PR)#366

Open
yacovm wants to merge 24 commits intomainfrom
reconfig-4
Open

Simplex reconfiguration framework - Part IV (Address code review comments for initial draft PR)#366
yacovm wants to merge 24 commits intomainfrom
reconfig-4

Conversation

@yacovm
Copy link
Copy Markdown
Collaborator

@yacovm yacovm commented Apr 16, 2026

No description provided.

yacovm and others added 15 commits April 16, 2026 18:57
This commit adds some helpers for the Simplex reconfiguration framework.

This commit entails:

- README.md changes to align with latest implementation
- misc.go contains helpers which will be removed once we moved the code to avalanchego.
- builds_decision.go contains a wrapper to the mempool that also listens to P-chain changes,
  and returns either when the mempool needs to build a block or re-configuration is in order.
- encoding.go contains the types that encode Simplex metadata and blocks.

Signed-off-by: Yacov Manevich <yacov.manevich@avalabs.org>
…ions)

- Add some structs and interface definitions
- Add some utility methods to be used in the next commit.

Signed-off-by: Yacov Manevich <yacov.manevich@avalabs.org>
- Add block building to msm.go
- Add verification.go which contains logic for block verification
- Add tests that mimic Simplex flow (fake_node_test.go)

Signed-off-by: Yacov Manevich <yacov.manevich@avalabs.org>
Addresses review comment: parameter was threaded through but never read.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: field was only written to, never read.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: the returned VMBlock was unused after
dropping innerChain.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: clarify that act randomly chooses between
finalizing, building, or no-op.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: test names should describe what is being
tested (state machine epoch transitions), not the test fixture.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: the type's purpose is to drive the state
machine across epoch transitions, so a more descriptive name is used.
The file is renamed accordingly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comments: finalized blocks were a prefix of notarized
blocks, so keeping two separate slices was redundant and error prone
(e.g. tryFinalizeNextBlock panicked when the two went out of sync).
Replaces both with a single blocks []blockState slice where each entry
carries a finalized flag.

Also removes the duplicate lookup in the GetBlock test fixture that
would return finalized blocks as non-finalized.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: a zero value should not match a valid variant,
so callers get a clear error if an uninitialized value sneaks through.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: inline the equality loop with slices.EqualFunc
and share the sort comparator.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: the ForEach/SumWeights wrappers added
unnecessary indirection. Inline them with ordinary for loops in
encoding.go, msm.go, and verification.go. Filter predicates no longer
need the unused index parameter, and ForEach/SumWeights themselves are
deleted along with their dedicated tests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: identifyCurrentState didn't belong on
StateMachine and never actually returned an error, so hoist it onto
SimplexEpochInfo and simplify the return. Callers and the existing test
are updated accordingly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@yacovm yacovm marked this pull request as draft April 16, 2026 21:17
yacovm and others added 7 commits April 17, 2026 16:06
Addresses review comment: a lazy-init pattern based on a sticky
'initialized' bool hid the dependency between field assignment and
first-call wiring. Introduces NewStateMachine(config) that eagerly
wires verifiers and returns *StateMachine.

NewStateMachine wires the verifiers through closures over the returned
*StateMachine, so callers (including tests) can keep mutating fields
like sm.GetBlock, sm.GetValidatorSet, and sm.GetPChainHeight after
construction and the verifiers will see the fresh values. Verifier
types are unchanged.

The test helper newStateMachine now returns *StateMachine.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: moves the block-building decider wiring out
of StateMachine.createBlockBuildingDecider into a package-level
newBlockBuildingDecider alongside the decider type itself. This keeps
the decider's initialization next to the decider, not the state machine.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: the childBlock VMBlock parameter was always
nil at the call site and immediately overwritten by BuildBlock. Replace
the blockBuildingDecision value with a plain transitionEpoch bool so the
function signature spells out what actually matters.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: simplexBlacklist doesn't need to be a pointer
to express 'none' — the zero value already does — and the simplex
prefix is redundant because the type itself (simplex.Blacklist) carries
that context. Callers now pass a simplex.Blacklist value, the encoded
bytes are always written to the block (even when empty), and tests use
the emptyBlacklistBytes helper when they expect the no-op encoding.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: both are self-contained and not specifically
about the StateMachine wiring. Relocating them out of msm.go keeps that
file focused on the state machine itself.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: msm_test.go was cluttered with the fakeVMBlock,
blockStore, signatureVerifier/aggregator, validatorSetRetriever,
keyAggregator, blockBuilder stubs plus newStateMachine/testConfig. They
are test plumbing, not test cases, so relocate them to
helpers_test.go to make the actual tests easier to navigate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review comment: buildBlockNormalOp /
buildBlockCollectingApprovals / buildBlockEpochSealed /
buildBlockImpatiently / createSealingBlock / wrapBlock all took
simplexMetadata bytes plus a separately drilled prevBlockSeq. Replace
both with a single simplex.ProtocolMetadata argument; prevBlockSeq is
now derived locally as metadata.Seq - 1, and wrapBlock serialises the
metadata when building the block.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
yacovm added 2 commits April 17, 2026 19:20
Signed-off-by: Yacov Manevich <yacov.manevich@avalabs.org>
Signed-off-by: Yacov Manevich <yacov.manevich@avalabs.org>
@yacovm yacovm marked this pull request as ready for review April 17, 2026 19:08
@yacovm yacovm changed the title Address code review comments Address code review comments for MSM Apr 17, 2026
@yacovm yacovm changed the title Address code review comments for MSM Simplex reconfiguration framework - Part IV (Address code review comments for initial draft PR) Apr 17, 2026
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.

1 participant