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

fix: fetch contributions only if there are aggregator duties #251

Merged
merged 1 commit into from
Jun 6, 2023

Conversation

moshe-blox
Copy link
Contributor

@moshe-blox moshe-blox commented May 21, 2023

This PR addresses a situation in the SyncCommitteeAggregatorRunner's ProcessPreConsensus method where attempts were made to fetch SyncCommitteeContributions even when there were no aggregator duties assigned. These attempts were unnecessary and resulted in inefficiencies in the code execution.

Previously, the code was structured such that after checking for aggregators, it proceeded to GetSyncCommitteeContribution even when no aggregator duties were present. This resulted in failure since the GetSyncCommitteeContribution method couldn't process without aggregator duties (Beacon node recognizes this), and the subsequent check for anyIsAggregator was never reached.

The changes in this PR include:

  1. The code now only appends signatures to selectionProofs when an aggregator duty is identified, eliminating the need for the anyIsAggregator check.

  2. The ProcessPreConsensus method will exit early if no aggregator duties are identified, before attempting to call GetSyncCommitteeContribution.

This way, the code is prevented from attempting to fetch SyncCommitteeContribution when no aggregator duties are assigned, simplifying the flow and reducing unnecessary operations.

Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

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

Besides my question we probably need to add some tests.
Also the PR description and title is a bit unclear to me...

Comment on lines +101 to +102
if len(selectionProofs) == 0 {
// there aren't any aggregators
Copy link
Contributor

Choose a reason for hiding this comment

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

as far as I understand we hit this code as long len(roots) == 0.
Else, even if an empty sig is created, we will still have a non-empty selectionProofs slice...

But this can only happen if we don't have quorum...
So nothing makes sense to me...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@GalRogozinski
We hit this code if none of the duties are aggregator duties:

		if !aggregator {
			continue
		}

return errors.Wrap(err, "can't start new duty runner instance for duty")
}
} else {
r.BaseRunner.State.Finished = true
Copy link
Contributor

Choose a reason for hiding this comment

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

this is the fix right?
So we don't mark it as finished too early?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix is to not call GetSyncCommitteeContribution when you have no aggregator duties.

So the "if no aggregators, set Finished to true" is moved up before that call.

@moshe-blox moshe-blox changed the title fix: only fetch contributions if there are aggregators fix: fetch contributions only if there are aggregator duties May 23, 2023
@moshe-blox moshe-blox requested a review from GalRogozinski May 23, 2023 08:47
@moshe-blox
Copy link
Contributor Author

Besides my question we probably need to add some tests. Also the PR description and title is a bit unclear to me...

Background:
ProcessPreConsensus is trying to check if any of the sync committee duties are aggregator duties, and only if they are, it fetches the contributions (sync committee aggregations) and starts a consensus flow to sign them.

Before this PR, it tried to fetch contributions even if the duties aren't aggregator duties, which was pointless.

Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

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

Ok,

I fail to see how we can add spec tests for this, since it is just an optimization to my understanding

@alonmuroch
Copy link
Contributor

Not sure I understand, we do check if aggregator

@GalRogozinski
Copy link
Contributor

@alonmuroch
#251 (comment)

@moshe-blox
Copy link
Contributor Author

moshe-blox commented May 28, 2023

Not sure I understand, we do check if aggregator

Indeed, while we do check for an aggregator, in the current implementation we still proceed to call GetSyncCommitteeContribution even when there are no aggregators identified.

Updated PR description with help from GPT-4, I think it's much better now 😅

@liorrutenberg liorrutenberg merged commit 4bb9266 into ssvlabs:main Jun 6, 2023
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.

4 participants