Skip to content

Refactor instance: extract util helpers, split BlockDeserializer, rework epoch transitions - #505

Draft
samliok wants to merge 3 commits into
extract-block-deserializerfrom
instance-refactor
Draft

Refactor instance: extract util helpers, split BlockDeserializer, rework epoch transitions#505
samliok wants to merge 3 commits into
extract-block-deserializerfrom
instance-refactor

Conversation

@samliok

@samliok samliok commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

First PR of the cleanup-instance stack (1/4).

  • Extract LastBlock and the epoch/validator-set derivation out of instance.go into util.go, with unit tests.
  • Split ParseBlock out of the VM interface into a BlockDeserializer interface, and move ICM epoch computation from the VM to a Config.ICMETransition field.
  • Replace EpochAwareStorage with InstanceStorage, which skips Telocks by block type instead of epoch counting and exposes a generic onIndex hook (a no-op here, consumed by the transition listener later in the stack).
  • Signal epoch changes through simplex.EpochConfig.OnSealingBlockIndex for validators and nonvalidator.Config.TransitionToValidator for non-validators instead of the storage wrapper. The non-validator trigger now checks membership in the highest replicated epoch's validator set rather than the P-chain tip.
  • Rework processEpochChange to hold the lock for the whole transition and honor Stop for validators too, and make notifyEpochChange keep only the newest pending change instead of blocking the indexing thread.
  • Remove the nodeRole dispatch, export testutil.TestControlledBlockBuilder, add an errAlreadyStarted sentinel.

The existing instance tests are kept with mechanical adjustments; the full test refactor lands at the top of the stack.

Comment thread simplex/epoch.go
e.broadcast(finalizationMsg)

e.epochSealed.Store(true)
if e.OnSealingBlockIndex != nil {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

can we add a test that ensures the OnSealingBlockIndex function is called?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

updated by claude d02a4a6

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

now 508e9a8 after rebasing onto #512

Comment thread testutil/controlled.go Outdated
type ControlledNode struct {
*BasicNode
bb *testControlledBlockBuilder
bb *TestControlledBlockBuilder

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

can we separate this out into another pr?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

updated by claude c2b0c10

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

moved to #511, the revert here is 6841c66 after rebasing onto #512

Comment thread config.go Outdated
ParseBlock(context.Context, []byte) (avalanchego.VMBlock, error)

// ComputeICMEpoch computes the ICM epoch transition given the input parameters.
ComputeICMEpoch(input metadata.ICMEpochInput) metadata.ICMEpochInfo

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

can we separate this out into a separate PR?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

split into #512, this PR is now rebased on it

… VM, rework epoch transitions

Extract LastBlock and epoch/validator-set derivation into util.go with tests.
Split ParseBlock into a BlockDeserializer interface and move ICM epoch
computation to a Config field. Replace EpochAwareStorage with InstanceStorage,
which skips Telocks by block type and exposes an onIndex hook. Signal epoch
changes via EpochConfig.OnSealingBlockIndex for validators and
nonvalidator.Config.TransitionToValidator for non-validators instead of the
storage wrapper. Rework processEpochChange to honor Stop for validators and
notifyEpochChange to keep only the newest pending change.
@samliok
samliok force-pushed the instance-refactor branch from d02a4a6 to 508e9a8 Compare August 13, 2026 23:11
@samliok
samliok changed the base branch from main to extract-block-deserializer August 13, 2026 23:11
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