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

Add functionality to retrieve all pending items from pools #7530

Merged
merged 13 commits into from
Oct 14, 2020

Conversation

0xKiwi
Copy link
Contributor

@0xKiwi 0xKiwi commented Oct 14, 2020

What type of PR is this?
This PR adds functionality to the slashings and exits pools to allow retrieving all pending items, as their only available action prior was to return only the max allowed per block.

This PR is needed for #7525

@0xKiwi 0xKiwi requested a review from a team as a code owner October 14, 2020 14:58
@0xKiwi 0xKiwi changed the title Add all pending Add functionality to retrieve all pending items from pools Oct 14, 2020
@0xKiwi 0xKiwi added Ready For Review A pull request ready for code review and removed Ready For Review A pull request ready for code review labels Oct 14, 2020
func (p *Pool) PendingAttesterSlashings(ctx context.Context, state *beaconstate.BeaconState) []*ethpb.AttesterSlashing {
// This method will return all pending attester slashings unless the `block` parameter is set to true
// to indicate the request is for a block.
func (p *Pool) PendingAttesterSlashings(ctx context.Context, state *beaconstate.BeaconState, block bool) []*ethpb.AttesterSlashing {
Copy link
Contributor

Choose a reason for hiding this comment

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

block bool is ambiguous, it sounds like you want the function to block. Perhaps we can call for forProposal? or forBlockProposal?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can call it noLimit ?

@@ -407,7 +416,7 @@ func TestPool_PendingProposerSlashings_Slashed(t *testing.T) {
p := &Pool{
pendingProposerSlashing: tt.fields.pending,
}
assert.DeepEqual(t, tt.want, p.PendingProposerSlashings(context.Background(), beaconState))
assert.DeepEqual(t, tt.want, p.PendingProposerSlashings(context.Background(), beaconState, false /*block*/))
Copy link
Contributor

Choose a reason for hiding this comment

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

Change comment here if we change the input arg name to something else

if !block {
maxSlashings = uint64(len(p.pendingAttesterSlashing))
}
pending := make([]*ethpb.AttesterSlashing, 0, maxSlashings)
for i := 0; i < len(p.pendingAttesterSlashing); i++ {
slashing := p.pendingAttesterSlashing[i]
Copy link
Member

Choose a reason for hiding this comment

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

Can you move slashing := ... after the break check?

if !block {
maxSlashings = uint64(len(p.pendingProposerSlashing))
}
pending := make([]*ethpb.ProposerSlashing, 0, maxSlashings)
for i := 0; i < len(p.pendingProposerSlashing); i++ {
slashing := p.pendingProposerSlashing[i]
Copy link
Member

Choose a reason for hiding this comment

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

Can you move slashing := ... after the break check?

@@ -26,25 +25,30 @@ func NewPool() *Pool {
}

// PendingAttesterSlashings returns attester slashings that are able to be included into a block.
// This method will not return more than the block enforced MaxAttesterSlashings.
func (p *Pool) PendingAttesterSlashings(ctx context.Context, state *beaconstate.BeaconState) []*ethpb.AttesterSlashing {
p.lock.RLock()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why this was a RLock when this functin mutates.

@0xKiwi 0xKiwi added the Ready For Review A pull request ready for code review label Oct 14, 2020
@prylabs-bulldozer prylabs-bulldozer bot merged commit 803d7c9 into master Oct 14, 2020
@delete-merged-branch delete-merged-branch bot deleted the add-all-pending branch October 14, 2020 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants