-
Notifications
You must be signed in to change notification settings - Fork 997
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete attestation pool for run time (#4286)
* Added subscribers * Fixed conflict * Delete atts in pool in validate pipeline * Moved it to subscriber * Test * Fixed test * New curl for forkchoice attestations * Starting att pool service for fork choice * Update pool interface * Update pool interface * Update sync and node * Lint * Gazelle * Updated servers, filled in missing functionalities * RPC working with 1 beacon node 64 validators * Started writing tests. Yay * Test to aggregate and save multiple fork choice atts * Tests for BatchAttestations for fork choice * Fixed exisiting tests * Minor fixes * Fmt * Added batch saves * Lint * Mo tests yay * Delete test * Fmt * Update interval * Fixed aggregation broadcast * Clean up based on design review comment * Fixed setupBeaconChain * Raul's feedback. s/error/err
- Loading branch information
1 parent
f181362
commit 718bf3d
Showing
35 changed files
with
1,007 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package kv | ||
|
||
import ( | ||
"github.com/patrickmn/go-cache" | ||
"github.com/pkg/errors" | ||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" | ||
"github.com/prysmaticlabs/go-ssz" | ||
) | ||
|
||
// SaveBlockAttestation saves an block attestation in cache. | ||
func (p *AttCaches) SaveBlockAttestation(att *ethpb.Attestation) error { | ||
r, err := ssz.HashTreeRoot(att) | ||
if err != nil { | ||
return errors.Wrap(err, "could not tree hash attestation") | ||
} | ||
|
||
// DefaultExpiration is set to what was given to New(). In this case | ||
// it's one epoch. | ||
p.blockAtt.Set(string(r[:]), att, cache.DefaultExpiration) | ||
|
||
return nil | ||
} | ||
|
||
// SaveBlockAttestations saves a list of block attestations in cache. | ||
func (p *AttCaches) SaveBlockAttestations(atts []*ethpb.Attestation) error { | ||
for _, att := range atts { | ||
if err := p.SaveBlockAttestation(att); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// BlockAttestations returns the block attestations in cache. | ||
func (p *AttCaches) BlockAttestations() []*ethpb.Attestation { | ||
atts := make([]*ethpb.Attestation, 0, p.blockAtt.ItemCount()) | ||
for s, i := range p.blockAtt.Items() { | ||
// Type assertion for the worst case. This shouldn't happen. | ||
att, ok := i.Object.(*ethpb.Attestation) | ||
if !ok { | ||
p.blockAtt.Delete(s) | ||
} | ||
atts = append(atts, att) | ||
} | ||
|
||
return atts | ||
} | ||
|
||
// DeleteBlockAttestation deletes a block attestation in cache. | ||
func (p *AttCaches) DeleteBlockAttestation(att *ethpb.Attestation) error { | ||
r, err := ssz.HashTreeRoot(att) | ||
if err != nil { | ||
return errors.Wrap(err, "could not tree hash attestation") | ||
} | ||
|
||
p.blockAtt.Delete(string(r[:])) | ||
|
||
return nil | ||
} |
Oops, something went wrong.