Skip to content

Commit

Permalink
Save attestation to DB gated by archival flag (prysmaticlabs#4776)
Browse files Browse the repository at this point in the history
* Gated by flag
* Gaz
* Merge branch 'master' into archival-saves-att
  • Loading branch information
terencechain authored and cryptomental committed Feb 28, 2020
1 parent 0f1f4f5 commit 7008f8f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions beacon-chain/blockchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ go_library(
"//beacon-chain/core/state:go_default_library",
"//beacon-chain/db:go_default_library",
"//beacon-chain/db/filters:go_default_library",
"//beacon-chain/flags:go_default_library",
"//beacon-chain/forkchoice:go_default_library",
"//beacon-chain/forkchoice/protoarray:go_default_library",
"//beacon-chain/operations/attestations:go_default_library",
Expand Down
8 changes: 6 additions & 2 deletions beacon-chain/blockchain/forkchoice/process_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/attestationutil"
Expand Down Expand Up @@ -130,8 +131,11 @@ func (s *Store) OnAttestation(ctx context.Context, a *ethpb.Attestation) ([]uint
return nil, err
}

if err := s.db.SaveAttestation(ctx, a); err != nil {
return nil, err
// Only save attestation in DB for archival node.
if flags.Get().EnableArchive {
if err := s.db.SaveAttestation(ctx, a); err != nil {
return nil, err
}
}

log := log.WithFields(logrus.Fields{
Expand Down
7 changes: 5 additions & 2 deletions beacon-chain/blockchain/forkchoice/process_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ func (s *Store) OnBlock(ctx context.Context, signed *ethpb.SignedBeaconBlock) (*
return nil, errors.Wrap(err, "could not save finalized checkpoint")
}
// Save the unseen attestations from block to db.
if err := s.saveNewBlockAttestations(ctx, b.Body.Attestations); err != nil {
return nil, errors.Wrap(err, "could not save attestations")
// Only save attestation in DB for archival node.
if flags.Get().EnableArchive {
if err := s.saveNewBlockAttestations(ctx, b.Body.Attestations); err != nil {
return nil, errors.Wrap(err, "could not save attestations")
}
}

// Epoch boundary bookkeeping such as logging epoch summaries.
Expand Down
8 changes: 6 additions & 2 deletions beacon-chain/blockchain/process_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"go.opencensus.io/trace"
)
Expand Down Expand Up @@ -117,8 +118,11 @@ func (s *Service) onAttestation(ctx context.Context, a *ethpb.Attestation) ([]ui
return nil, err
}

if err := s.beaconDB.SaveAttestation(ctx, a); err != nil {
return nil, err
// Only save attestation in DB for archival node.
if flags.Get().EnableArchive {
if err := s.beaconDB.SaveAttestation(ctx, a); err != nil {
return nil, err
}
}

return indexedAtt.AttestingIndices, nil
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/state/references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestStateReferenceSharing_Finalizer(t *testing.T) {
t.Error("Expected a single reference for Randao mixes")
}

func () {
func() {
// Create object in a different scope for GC
b := a.Copy()
if a.sharedFieldReferences[randaoMixes].refs != 2 {
Expand Down

0 comments on commit 7008f8f

Please sign in to comment.