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 AttestationPool to aggregate attestations on the go #2679

Merged
merged 4 commits into from
Jun 11, 2021

Conversation

dapplion
Copy link
Contributor

Motivation

See #2415

Description

Substitutes the current disk-persisted attestation repo with a memory-only attestation pool. It pre-aggregates attestations saving memory and reducing disk reads and writes.

Closes #2415

@github-actions github-actions bot added Api scope-networking All issues related to networking, gossip, and libp2p. labels Jun 10, 2021
@codeclimate
Copy link

codeclimate bot commented Jun 10, 2021

Code Climate has analyzed commit 8b20e7c and detected 0 issues on this pull request.

View more on Code Climate.

@@ -336,8 +338,9 @@ export async function onErrorAttestation(this: BeaconChain, err: AttestationErro
this.pendingAttestations.putByBlock(err.type.beaconBlockRoot, err.job);
break;

default:
await this.db.attestation.remove(err.job.attestation);
// TODO: Why is necessary to remove the attestation from the DB on error?
Copy link
Member

Choose a reason for hiding this comment

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

I think this was failsafe since we didn't have api validation before so on some occasion, validator would put some invalid attestation which would prevent all blocks from being processed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How could an invalid attestation prevent all blocks from being processed?

Copy link
Member

Choose a reason for hiding this comment

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

process block failed when processing attestations and attestation was put in every block we were producing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But how could an invalid attestation got included in the attestation pool?

Copy link
Contributor

Choose a reason for hiding this comment

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

this error handler for attestation was for forkchoice, not when we process block.
Since it was for forkchoice, it's not really necessary to remove that attestation from db. The next time we see that same error from that same attestation, we could just throw error and handle the same way but this is rare.

@@ -25,6 +25,18 @@ export async function assembleBody(
blockSlot: Slot,
syncAggregateData: {parentSlot: Slot; parentBlockRoot: Root}
): Promise<allForks.BeaconBlockBody> {
// TODO:
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should, if number of agg attestations is < MAX_ATTESTATIONS, take some attestations from attestations memory pool. Assuming we delete attestation that are aggregated?

Copy link
Contributor Author

@dapplion dapplion Jun 11, 2021

Choose a reason for hiding this comment

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

Right, the logic to do that successfully is tricky. Since we were not doing that previously it should be done in another PR if we decide to.

throw new AttestationPoolError({code: AttestationPoolErrorCode.SLOT_TOO_LOW, slot, lowestPermissibleSlot});
}

const dataRoot = ssz.phase0.AttestationData.hashTreeRoot(attestation.data);
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't more future safe way be getForkTypes(slot).AttestationData?

Copy link
Contributor Author

@dapplion dapplion Jun 11, 2021

Choose a reason for hiding this comment

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

Yes but we should change it everywhere at once in another PR. This logic in unchanged in this PR just moved around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope-networking All issues related to networking, gossip, and libp2p.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pre-aggregate attestations in Aggregation pool
3 participants