Skip to content
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

Move statesync to separate package #1759

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

aaronbuchwald
Copy link
Collaborator

This PR separates state sync from the VM package.

vm/vm.go Outdated
vm.genesis.GetStateBranchFactor(),
vm.config.StateSyncMinBlocks,
vm.config.StateSyncParallelism,
)

if err := vm.network.AddHandler(
rangeProofHandlerID,
Copy link
Contributor

Choose a reason for hiding this comment

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

It may use the rangeProofHandlerID from the statesync package?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah good catch!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moving these into the statesync/ package as well

Base automatically changed from stateful-block-to-vm to main November 12, 2024 22:02

var _ block.StateSummary = (*SyncableBlock[StateSummaryContainer])(nil)

type StateSummaryContainer interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Container IIRC is a legacy term form when we supported vertices... should we just call this Block?

Comment on lines +23 to +24
RangeProofHandlerID = 0
ChangeProofHandlerID = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO these handler ids should be defined by the vm - this package has no idea if it's colliding with other handler ids or not.

var _ Accepter[StateSummaryContainer] = (*Client[StateSummaryContainer])(nil)

type ChainClient[T StateSummaryContainer] interface {
LastAcceptedStatefulBlock() T
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming here seems weird because this package doesn't know about StatefulBlocks, as that's the concrete type defined by the consumer of this package. Maybe something like Block would make more sense?

func (b *StatelessBlock) ID() ids.ID { return b.id }
func (b *StatelessBlock) Bytes() []byte { return b.bytes }
func (b *StatelessBlock) Size() int { return len(b.bytes) }
func (b *StatelessBlock) GetStateRoot() ids.ID { return b.StateRoot }
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this function be on the StatefulBlock type since that's the one we care about implementing the statesync interface?

Bytes() []byte
GetStateRoot() ids.ID
MarkAccepted(context.Context)
fmt.Stringer
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Generally embedding is done by composing stuff at the top of the interface/struct as opposed to at the bottom

)

func RegisterHandlers(log logging.Logger, network *p2p.Network, db merkledb.MerkleDB) error {
errs := wrappers.Errs{}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can actually just use the stdlib errors.Join(...) here instead of the avalanchego wrapper


type SyncableBlock[T StateSummaryContainer] struct {
container T
accepter Accepter[T] // accepter is nil if the SyncableBlock is constructed by the server
Copy link
Contributor

Choose a reason for hiding this comment

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

Another idea instead of relying on not ever calling Accept to avoid panic'ing would be to just pass in a no-op implementation of accept so you don't have to document this edge-case at all.

// implements "block.ChainVM.commom.VM.Parser"
// replaces "core.SnowmanVM.ParseBlock"
func (vm *VM) ParseBlock(ctx context.Context, source []byte) (snowman.Block, error) {
func (vm *VM) ParseStatefulBlock(ctx context.Context, source []byte) (*StatefulBlock, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we rename this? Wondering if we need this + the ParseBlock function... I guess this one is nice because it returns the concrete type but it's also not something we're using right now.

Comment on lines +137 to +138
*statesync.Client[*StatefulBlock]
*statesync.Server[*StatefulBlock]
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer not embedding here... it can be annoying because now we can collide across functions/fields that the embedded types have.

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