Skip to content

move syncers to atomic vm #1009

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

Merged
merged 2 commits into from
Jun 6, 2025
Merged

move syncers to atomic vm #1009

merged 2 commits into from
Jun 6, 2025

Conversation

ceyonur
Copy link
Collaborator

@ceyonur ceyonur commented Jun 6, 2025

Replaces: #985

Why this should be merged

This moves initialization of atomic syncers and sync extender to atomic/vm pkg

How this works

This pull request introduces changes to improve the initialization and configuration flexibility of multiple components in the EVM plugin. The key updates involve refactoring constructors to support deferred initialization, enhancing extensibility in the VM configuration, and updating state sync logic to better integrate with the new extension framework.

Refactoring Constructors for Deferred Initialization:

  • plugin/evm/atomic/sync/extender.go: Refactored the NewExtender function to return an uninitialized extender instance and added an Initialize method for deferred setup.
  • plugin/evm/atomic/sync/leaf_handler.go: Introduced an uninitializedHandler type to handle uninitialized leaf requests, refactored NewLeafHandler to return an uninitialized leafHandler, and added an Initialize method for setup.
  • plugin/evm/atomic/sync/summary_provider.go: Refactored NewSummaryProvider to return an uninitialized summaryProvider and added an Initialize method for deferred initialization.

Enhancements to VM Configuration:

  • plugin/evm/extension/config.go: Extended the Config struct to include new fields for SyncSummaryProvider, SyncExtender, SyncableParser, and ExtraSyncLeafHandlerConfig. Added validation for required fields and support for an optional Clock.
  • plugin/evm/vm.go: Updated the VM struct and initialization logic to integrate the extended configuration, including support for custom sync handlers and parsers. [1] [2]

State Sync Logic Updates:

  • plugin/evm/vm.go: Refactored state sync initialization to leverage the new extension configuration for handlers, parser, and extender, ensuring better modularity and flexibility. [1] [2]

How this was tested

Existing tests

Need to be documented?

No

Need to update RELEASES.md?

No

@ceyonur ceyonur marked this pull request as ready for review June 6, 2025 19:53
@ceyonur ceyonur requested a review from a team as a code owner June 6, 2025 19:53
Copy link
Contributor

@alarso16 alarso16 left a comment

Choose a reason for hiding this comment

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

I left some small comments, but I don't think they should block

@ceyonur ceyonur enabled auto-merge June 6, 2025 22:24
@ceyonur ceyonur disabled auto-merge June 6, 2025 22:24
@ceyonur ceyonur enabled auto-merge June 6, 2025 22:26
@ceyonur ceyonur added this pull request to the merge queue Jun 6, 2025
Merged via the queue into master with commit dab5d35 Jun 6, 2025
9 checks passed
@ceyonur ceyonur deleted the atomic-vm-sync branch June 6, 2025 22:47
trie: trie,
requestSize: requestSize,
}
func NewExtender() *extender {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is there a constructor if it doesn't do anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

bc it was using an unexported struct

requestSize: requestSize,
}
func NewExtender() *extender {
return &extender{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Returning non-exported types can cause problems at the call sites as they're really only useable as interfaces, but because they're not exported there's no way to check the documentation to see if they implement the interface of interest.

Comment on lines +33 to +35
a.backend = backend
a.trie = trie
a.requestSize = requestSize
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is just a constructor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In fact yes, but we need to initialize this after calling the innerVM.Initialize() (see #998)

Comment on lines +23 to +28
func NewSummaryProvider() *summaryProvider {
return &summaryProvider{}
}

func (a *summaryProvider) Initialize(trie *state.AtomicTrie) {
a.trie = trie
Copy link
Collaborator

Choose a reason for hiding this comment

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

All my comments on *extender apply here. Non-exported type, no-op constructor, and an initialiser that's just a constructor.

// Initialize initializes the leafHandler with the provided atomicTrieDB, trieKeyLength, and networkCodec
func NewLeafHandler(atomicTrieDB *triedb.Database, trieKeyLength int, networkCodec codec.Manager) *leafHandler {
handlerStats := stats.GetOrRegisterHandlerStats(metrics.Enabled)
// NewAtomicLeafHandler returns a new uninitialzied atomicLeafHandler that can be later initialized
Copy link
Collaborator

Choose a reason for hiding this comment

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

that can be later initialized

It can't be. It always returns errUninitialized.

EDIT: looking at the code below, I think you mean "can be later replaced".

Comment on lines +128 to +131
syncProvider.Initialize(vm.AtomicBackend().AtomicTrie())
syncExtender.Initialize(vm.AtomicBackend(), vm.AtomicBackend().AtomicTrie(), vm.Config().StateSyncRequestSize)
leafHandler.Initialize(vm.AtomicBackend().AtomicTrie().TrieDB(), state.TrieKeyLength, message.Codec)

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is confusing because of the embedded InnerVM and took me about 10 minutes to figure out, including opening the code locally. As it was merged it suggests to the reader that there was no need to already initialise the InnerVM; I suggest making explicit that you are using the InnerVM's method.

atomicBE := vm.InnerVM.AtomicBackend()
atomicTrie := atomicBE.AtomicTrie()
syncProvider.Initialize(atomicTrie)
syncExtender.Initialize(atomicBE, atomicTrie, vm.Config().StateSyncRequestSize)
leafHandler.Initialize(atomicTrie.TrieDB(), state.TrieKeyLength, message.Codec)

I appreciate that this is a means to an end, but I'm still really concerned about this pattern. The PR chain needs to eventually simplify construction and initialisation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In one of the previous PRs it was suggested to call InnerVM methods implicitly to reduce the complexity, but I agree it's easier to figure them out if they were explicit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On the other hand atomicBackend will be moved to atomic/VM in #1011

@ceyonur
Copy link
Collaborator Author

ceyonur commented Jun 16, 2025

Responded reviews here in #1015

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.

3 participants