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

Split BEEFY relayer into two separate relayers #1216

Merged
merged 11 commits into from
Jun 4, 2024

Conversation

vgeddes
Copy link
Collaborator

@vgeddes vgeddes commented May 30, 2024

The BEEFY relayer is overly complicated, slow, and brittle as it tries to do too much with a core synchronization algorithm that is inappropriate:

  1. Downloading all block data, including extrinsics, which is hugely wasteful
  2. Syncing mandatory commitments always
  3. Optionally sync non-mandatory commitments, but only if these commitments are near the finalized head, and try to skip every N non-mandatory commitments.

Instead, we should split the relayer into services:

  1. A mandatory commitment relayer, which simply syncs mandatory commitments
  2. A one-shot command which syncs the commitment for the latest non-mandatory finalized BEEFY head, only if the beefy light client is in the same validator session as finalized beefy head on Polkadot.

This PR currently implements (1). We should also implement (2) to allow anyone to sync instantly so they can have their messages relayed.

Suggested design for (2): Use GSRPC beefy_getFinalizedHead to get the latest finalized BEEFY head, then chain_getBlock, which I suspect should contain a beefy justification.

Fixes: SNO-1017

@vgeddes vgeddes requested a review from yrong May 30, 2024 13:17
Comment on lines 165 to 177
func (li *PolkadotListener) queryBeefyNextAuthoritySet(blockHash types.Hash) (types.BeefyNextAuthoritySet, error) {
var nextAuthoritySet types.BeefyNextAuthoritySet
storageKey, err := types.CreateStorageKey(li.conn.Metadata(), "MmrLeaf", "BeefyNextAuthorities", nil, nil)
ok, err := li.conn.API().RPC.State.GetStorage(storageKey, &nextAuthoritySet, blockHash)
if err != nil {
return nextAuthoritySet, err
}
if !ok {
return nextAuthoritySet, fmt.Errorf("beefy nextAuthoritySet not found")
}

return nextAuthoritySet, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I need this function for #1215, but no need to revert here I can address it in that PR.

Copy link
Contributor

@yrong yrong left a comment

Choose a reason for hiding this comment

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

+1

yrong and others added 5 commits June 3, 2024 13:31
* Sync beefy commitment on demand

* Minor fix

* More comments

* More refactoring

* Fix for skip mandatory commitment

* Some refactoring

* Find for next beefy block

* Improve log

* Remove check unrelated
@vgeddes vgeddes merged commit a0c1c47 into main Jun 4, 2024
2 checks passed
@vgeddes vgeddes deleted the vincent/beefy-relay-improvements branch June 4, 2024 21:26
vgeddes added a commit that referenced this pull request Jun 5, 2024
Co-authored-by: ron <yrong1997@gmail.com>
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.

2 participants