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

Merged
merged 5 commits into from
Nov 19, 2024
Merged

Move statesync to separate package #1759

merged 5 commits into from
Nov 19, 2024

Conversation

aaronbuchwald
Copy link
Collaborator

This PR separates state sync from the VM package.

vm/vm.go Outdated Show resolved Hide resolved
Base automatically changed from stateful-block-to-vm to main November 12, 2024 22:02
statesync/block.go Outdated Show resolved Hide resolved
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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved back

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This needs to match the function signature defined in vm/resolutions.go and return the stateful block, so can't conflict with the other functions present there

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will need to change this in the future when we support multiple block types, but for now all of these functions are implemented on StatefulBlock via embedding

statesync/block.go Outdated Show resolved Hide resolved
)

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will use this here since it's a limited case. I think we should keep using wrappers.Errs{} where there's a large number of errors and a string concatenation of all of them would create a worse error message than returning the first error.


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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We should never call Accept on the server side, so I think we should log an error rather than pass a no-op if we change this.

// 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To provide a parse function that returns our own concrete type. We use this in the state sync client.

vm/vm.go Outdated
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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will do

@joshua-kim joshua-kim enabled auto-merge (squash) November 18, 2024 19:07
@aaronbuchwald aaronbuchwald merged commit 35fc59b into main Nov 19, 2024
17 checks passed
@aaronbuchwald aaronbuchwald deleted the repackage-state-sync branch November 19, 2024 13:35
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.

4 participants