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

680: Persist and Fetch GRANDPA Data with Refactoring from Previous Class #681

Merged
merged 7 commits into from
Jan 13, 2025

Conversation

hMitov
Copy link
Collaborator

@hMitov hMitov commented Jan 10, 2025

Description

  • Added new methods to persist and fetch GRANDPA-related data in the database.
  • Refactored the code to eliminate duplicate data by moving relevant fields from SyncState to RoundState (Grandpa state).
  • Refactored WarpSyncMachine.java and WarpSyncState.java to accommodate these changes.

P.S. As part of my task, I conducted research to identify where these persisting and fetching methods are utilized in the current implementation and explored potential use cases for them in upcoming tasks.

Hereby, I place what I have found:
Method: saveAuthorities()
Should be seen in:

  • func newGrandpaStateFromGenesis()
  • func applyScheduledChanges()
  • func applyForcedChanges()
  • func setNextChange()

Method: loadAuthorities()
Should be seen in:

  • func updateAuthorities(): Updates the GRANDPA voter set, increments the setID, and resets the round numbers.
  • func verifyBlockJustification(): Verifies the finality justification for a block and returns the SCALE-encoded justification with any extra bytes removed.

Method: saveCurrentSetID()
Should be seen in:

  • func newGrandpaStateFromGenesis(): Returns a new GrandpaState given the GRANDPA genesis authorities.
  • func incrementSetID(): Increments the set ID.
  • func rewind(): Rewinds the chain to the given block number. If the number of blocks exceeds the chain height, it rewinds to genesis.

Method: loadCurrentSetID()
Should be seen in:

  • func applyForcedChanges(): Checks for scheduled forced changes relative to the imported block and applies them (or does nothing if none are found).
  • func setNextChange(): Sets the next authority change at the given block number (the last block in the current set, not part of the next set).
  • func incrementSetID(): Increments the set ID.
  • func getSetIDByBlockNumber(): Returns the set ID for a given block number.
  • func rewind(): Rewinds the chain to the given block number. If the number of blocks exceeds the chain height, it rewinds to genesis.
  • func newService(): Returns a new GRANDPA Service instance.
  • func updateAuthorities(): Updates the GRANDPA voter set, increments the setID, and resets the round numbers.
  • func reportEquivocation(): Handles equivocation reports.

Method: saveLatestRound()
Should be seen in:

  • func newGrandpaStateFromGenesis(): Returns a new GrandpaState given the GRANDPA genesis authorities.
  • func initiateRound(): Initiates a new round in GRANDPA.
  • func finalise(): Finalizes the round by setting the best final candidate for this round.

Method: loadLatestRound()
Should be seen in:

  • func newService(): Returns a new GRANDPA Service instance.
  • func reportEquivocation(): Handles equivocation reports.

Method: savePrevotes()
Should be seen in:

  • func finalise(): Finalizes the round by setting the best final candidate for this round.
  • func handleCatchUpResponse(): Handles responses during the catch-up process.

Method: loadPrevotes()
Should be seen in:

  • func newCatchUpResponse(): Handles the creation of a new catch-up response.

Method: savePrecommits()
Should be seen in:

  • func finalise(): Finalizes the round.
  • func handleCommitMessage(): Processes commit messages in GRANDPA.
  • func handleCatchUpResponse(): Handles responses during the catch-up process.

Method: loadPrecommits()
Should be seen in:

  • func newCommitMessage(): Handles the creation of a new commit message.
  • func newCatchUpResponse(): Handles the creation of a new catch-up response.

Fixes #680

Hristiyan Mitov added 5 commits January 10, 2025 10:15
Added methods for persisting and fetching of grandpaVoters, setId, roundNumber, precommits and prevotes fields.
…oduced find() for fetching values with default fallback.
…RoundState.java (Grandpa state). Refactored WarpSyncMachine.java and WarpSyncState.java to accommodate these changes.
…e. It is now initialized using genBean.
Copy link

@hMitov hMitov merged commit f80bd9d into dev Jan 13, 2025
3 checks passed
@hMitov hMitov deleted the 680-Store-grandpa-data branch January 13, 2025 12:31
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.

Persist and Fetch GRANDPA Data with Refactoring from Previous Class
3 participants