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

Feature - State Sync manager #1067

Merged
merged 16 commits into from
Jan 3, 2023
Merged

Conversation

ferranbt
Copy link
Contributor

@ferranbt ferranbt commented Dec 21, 2022

Description

Introduced a concept of StateSyncManager, a struct that handles state sync saving workflow, and building and submitting commitments to the StateReceiver contract.

StateSyncManager is one of the building blocks in consensus_runtime, but it encapsulates the state sync logic mentioned above.

This makes testing easier (as we can mock the state sync workflow, in consensus_runtime tests, much more easily), makes code more granular and separates logic to concerning parts.

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)

Checklist

  • I have assigned this PR to myself
  • I have added at least 1 reviewer
  • I have added the relevant labels
  • I have updated the official documentation
  • I have added sufficient documentation in code

Testing

  • I have tested this code with the official test suite
  • I have tested this code manually

@ferranbt ferranbt changed the title initial work Feature - State Sync manager Dec 22, 2022
@ferranbt ferranbt marked this pull request as ready for review December 22, 2022 12:37
consensus/polybft/state_sync_manager.go Outdated Show resolved Hide resolved
consensus/polybft/state_sync_manager.go Outdated Show resolved Hide resolved
Copy link
Contributor

@vcastellm vcastellm left a comment

Choose a reason for hiding this comment

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

I like it overall aside from the comments

@codecov
Copy link

codecov bot commented Dec 23, 2022

Codecov Report

❗ No coverage uploaded for pull request base (feature/v3-parity@a65d2d0). Click here to learn what that means.
The diff coverage is n/a.

@@                 Coverage Diff                  @@
##             feature/v3-parity    #1067   +/-   ##
====================================================
  Coverage                     ?   54.23%           
====================================================
  Files                        ?      173           
  Lines                        ?    22990           
  Branches                     ?        0           
====================================================
  Hits                         ?    12469           
  Misses                       ?     9524           
  Partials                     ?      997           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Stefan-Ethernal
Copy link
Collaborator

This function can be safely removed from consensusRuntime (used only in the unit test)

func validateVote(vote *MessageSignature, epoch *epochMetadata) error {

Copy link
Collaborator

@Stefan-Ethernal Stefan-Ethernal left a comment

Choose a reason for hiding this comment

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

Looking much better 🔥

consensus/polybft/state_sync_manager.go Outdated Show resolved Hide resolved
consensus/polybft/state_sync_manager.go Show resolved Hide resolved
consensus/polybft/state_sync_manager.go Outdated Show resolved Hide resolved
consensus/polybft/state_sync_manager.go Outdated Show resolved Hide resolved
consensus/polybft/state_sync_manager.go Outdated Show resolved Hide resolved
consensus/polybft/state_sync_manager.go Outdated Show resolved Hide resolved
consensus/polybft/state_sync_manager.go Show resolved Hide resolved
consensus/polybft/state_sync_manager.go Show resolved Hide resolved
consensus/polybft/state_sync_manager.go Show resolved Hide resolved
consensus/polybft/consensus_runtime.go Outdated Show resolved Hide resolved
Copy link
Contributor

@vcastellm vcastellm left a comment

Choose a reason for hiding this comment

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

stateSyncCommitmentSize can be moved to the manager

Copy link
Contributor

@vcastellm vcastellm left a comment

Choose a reason for hiding this comment

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

All functions that are not used in the state anymore and are used only in the manager, for example decodeStateSyncEvent, would be great to move them to the manager, so we isolate all statesync things in it.

consensus/polybft/state_sync_manager.go Show resolved Hide resolved
Copy link
Contributor

@vcastellm vcastellm left a comment

Choose a reason for hiding this comment

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

LGTM aside from comment

@goran-ethernal goran-ethernal self-assigned this Dec 28, 2022
)

// StateSyncManager is an interface that defines functions for state sync workflow
type StateSyncManager interface {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not see the use case to do this abstraction here. The only reason would be to put it inside consensus_runtime but even that I think this is lightweight enough to not mock it and use it directly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree, it's really lightweight to mock it. This interface is added only because of the nil implementation of stateSyncManager, which we discuss in comment: #1067 (comment)


c.stateSyncManager = stateSyncManager
} else {
c.stateSyncManager = &dummyStateSyncManager{}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the stateSyncManager is not enabled because the bridge is not enabled, it should never be called. I understand this is a safety measure in case it is ever called. But, I would prefer if we ensure on tests that never happens instead of having extra code to ensure that.

Note that once we have hooks (if we ever do it though) we do not need this check anymore.

Copy link
Collaborator

Choose a reason for hiding this comment

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

While I do understand your point, I must agree with Stefan here. Nullable pattern is a good practice, since it reduces the unnecessary checks and conditions in code, makes testing easier, and it doesn't really add any more complexity (since that nil or dummy implementation doesn't do anything). Plus, as you said, it keeps as out of harms way of nil exceptions. To me it makes sense to have it here, and if we ever implement that hook system, then I would agree, we can remove this nil implementation since we would not need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other option would be to make StateSyncManager aware that he is not active and do nothing when PostEpoch and PostBlock get called.

Copy link
Collaborator

@goran-ethernal goran-ethernal Dec 30, 2022

Choose a reason for hiding this comment

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

Yes, but that means we will just be moving those checks to the stateSyncManager 😕 . That hook system is looking better by the minute 😄 .

Copy link
Contributor Author

@ferranbt ferranbt left a comment

Choose a reason for hiding this comment

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

Cannot Approve because I made the PR. LGTM except for the comments about the abstraction.

@ferranbt ferranbt merged commit 4c5d0d9 into feature/v3-parity Jan 3, 2023
@vcastellm vcastellm deleted the feature/state-sync-manager branch January 3, 2023 09:09
@github-actions github-actions bot locked and limited conversation to collaborators Jan 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New update to Polygon Edge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants