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

Check BLS changes when requesting from pool #11718

Merged
merged 6 commits into from
Dec 9, 2022

Conversation

potuz
Copy link
Contributor

@potuz potuz commented Dec 2, 2022

This PR checks BLS changes when requesting them from the pool (this is performed when proposing a block). |

It checks the validity of the operation individually (except signatures)
If any is found invalid it's removed from the pool
Then it checks the signatures in batch
If the batch is found invalid it checks signatures individually
If any signature is found invalid it removes it from the pool.

If a change is invalid then we continue scanning until filling the block or exhausting the pool. If a signature is invalid we do not rescan.

@potuz potuz requested a review from a team as a code owner December 2, 2022 13:37
Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

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

I have some questions

ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/sirupsen/logrus"
)

// PoolManager maintains pending and seen BLS-to-execution-change objects.
// This pool is used by proposers to insert BLS-to-execution-change objects into new blocks.
type PoolManager interface {
PendingBLSToExecChanges() ([]*ethpb.SignedBLSToExecutionChange, error)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't you apply this for PendingBLSToExecChanges or we just simply care less for that?

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 can see the value in returning the full list, someone may be interested in knowing what are all changes in the node. No one uses this endpoint yet so I am not sure what are the applications yet. Also, performing a linear scan with signature verification in an unbounded list scares me, so I'd rather have the caller making these checks.

Copy link
Member

Choose a reason for hiding this comment

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

That's fair. I don't know whether beacon API explicitly calls this out. We can add this behavior to the commentary if it doesn't

if err != nil {
logrus.Warning("removing invalid BLSToExecutionChange from pool")
// MarkIncluded removes the invalid change from the pool
p.lock.RUnlock()
Copy link
Member

Choose a reason for hiding this comment

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

These lock/unlock scares me. Any reason to pick this over defer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MarkIncluded needs a lock, so we can't defer.

return nil, err
}
_, err = blocks.ValidateBLSToExecutionChange(st, change)
if err != nil {
logrus.Warning("removing invalid BLSToExecutionChange from pool")
Copy link
Member

Choose a reason for hiding this comment

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

Should we include the err in this warning log?

// We now verify the signatures in batches
cSet, err := blocks.BLSChangesSignatureBatch(st, result)
if err != nil {
return nil, errors.Wrap(err, "could not get BLSToExecutionChanges signatures")
Copy link
Member

Choose a reason for hiding this comment

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

Optional: I think you can continue here and check signatures individually

}
ok, err := cSet.Verify()
if err != nil {
return nil, errors.Wrap(err, "could not batch verify BLSToExecutionChanges signatures")
Copy link
Member

Choose a reason for hiding this comment

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

Optional: I think you can continue here and check signatures individually

terencechain
terencechain previously approved these changes Dec 5, 2022
Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

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

lgtm

@terencechain terencechain added Blocked Blocked by research or external factors and removed Ready For Review labels Dec 6, 2022
@terencechain
Copy link
Member

Please don't merge it. A few more changes are coming

@potuz potuz added Ready For Review and removed Blocked Blocked by research or external factors labels Dec 6, 2022
logrus.WithError(err).Warning("could not batch verify BLSToExecutionChanges signatures")
} else if ok {
return result, nil

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

beacon-chain/operations/blstoexec/pool.go Show resolved Hide resolved
@prylabs-bulldozer prylabs-bulldozer bot merged commit babfc66 into develop Dec 9, 2022
@delete-merged-branch delete-merged-branch bot deleted the check_bls_changes branch December 9, 2022 14:41
roberto-bayardo pushed a commit to roberto-bayardo/prysm that referenced this pull request Dec 17, 2022
* Check BLS changes when requesting from pool

* Terence's suggestions

* Radek's suggestion

Co-authored-by: terencechain <terence@prysmaticlabs.com>
Co-authored-by: Raul Jordan <raul@prysmaticlabs.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.

4 participants