Skip to content

Commit

Permalink
More feature flag deletions (#7533)
Browse files Browse the repository at this point in the history
* Delete disable state lock and init sync verbose flags

* Delete disable slashing broadcast

* Remove disable wait for sync, noise, eth1 cache, static subnet

* Remove enable broadcast recovery attemp and make it as default

* Remove disable head update on per attestation

* Revert disable att braodcast discovery attempt

* gazelle

* Fixed an anti pattern

* Add enableAttBroadcastDiscoveryAttempts back

* Add back WaitForSync

* Remove extra lines

* Use DisableDynamicCommitteeSubnets path per @prestonvanloon feedback

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
terencechain and prylabs-bulldozer[bot] authored Oct 14, 2020
1 parent a840fa5 commit 7076a1e
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 490 deletions.
12 changes: 3 additions & 9 deletions beacon-chain/blockchain/receive_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/slotutil"
"github.com/prysmaticlabs/prysm/shared/timeutils"
Expand Down Expand Up @@ -43,14 +42,9 @@ func (s *Service) ReceiveAttestationNoPubsub(ctx context.Context, att *ethpb.Att
return errors.Wrap(err, "could not process attestation")
}

if !featureconfig.Get().DisableUpdateHeadPerAttestation {
// This updates fork choice head, if a new head could not be updated due to
// long range or intermediate forking. It simply logs a warning and returns nil
// as that's more appropriate than returning errors.
if err := s.updateHead(ctx, s.getJustifiedBalances()); err != nil {
log.Warnf("Resolving fork due to new attestation: %v", err)
return nil
}
if err := s.updateHead(ctx, s.getJustifiedBalances()); err != nil {
log.Warnf("Resolving fork due to new attestation: %v", err)
return nil
}

return nil
Expand Down
10 changes: 3 additions & 7 deletions beacon-chain/p2p/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
secio "github.com/libp2p/go-libp2p-secio"
ma "github.com/multiformats/go-multiaddr"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/version"
)

Expand All @@ -37,12 +36,9 @@ func (s *Service) buildOptions(ip net.IP, priKey *ecdsa.PrivateKey) []libp2p.Opt
libp2p.UserAgent(version.GetBuildData()),
libp2p.ConnectionGater(s),
}
if featureconfig.Get().EnableNoise {
// Enable NOISE for the beacon node with secio as a fallback.
options = append(options, libp2p.Security(noise.ID, noise.New), libp2p.Security(secio.ID, secio.New))
} else {
options = append(options, libp2p.Security(secio.ID, secio.New))
}

options = append(options, libp2p.Security(noise.ID, noise.New), libp2p.Security(secio.ID, secio.New))

if cfg.EnableUPnP {
options = append(options, libp2p.NATPortMap()) //Allow to use UPnP
}
Expand Down
2 changes: 0 additions & 2 deletions beacon-chain/rpc/beacon/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ go_library(
"//shared/bytesutil:go_default_library",
"//shared/cmd:go_default_library",
"//shared/event:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/pagination:go_default_library",
"//shared/params:go_default_library",
"//shared/sliceutil:go_default_library",
Expand Down Expand Up @@ -97,7 +96,6 @@ go_test(
"//shared/attestationutil:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/cmd:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/mock:go_default_library",
"//shared/params:go_default_library",
"//shared/testutil:go_default_library",
Expand Down
15 changes: 6 additions & 9 deletions beacon-chain/rpc/beacon/slashings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/sliceutil"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -24,11 +23,10 @@ func (bs *Server) SubmitProposerSlashing(
if err := bs.SlashingsPool.InsertProposerSlashing(ctx, beaconState, req); err != nil {
return nil, status.Errorf(codes.Internal, "Could not insert proposer slashing into pool: %v", err)
}
if !featureconfig.Get().DisableBroadcastSlashings {
if err := bs.Broadcaster.Broadcast(ctx, req); err != nil {
return nil, err
}
if err := bs.Broadcaster.Broadcast(ctx, req); err != nil {
return nil, err
}

return &ethpb.SubmitSlashingResponse{
SlashedIndices: []uint64{req.Header_1.Header.ProposerIndex},
}, nil
Expand All @@ -48,11 +46,10 @@ func (bs *Server) SubmitAttesterSlashing(
if err := bs.SlashingsPool.InsertAttesterSlashing(ctx, beaconState, req); err != nil {
return nil, status.Errorf(codes.Internal, "Could not insert attester slashing into pool: %v", err)
}
if !featureconfig.Get().DisableBroadcastSlashings {
if err := bs.Broadcaster.Broadcast(ctx, req); err != nil {
return nil, err
}
if err := bs.Broadcaster.Broadcast(ctx, req); err != nil {
return nil, err
}

slashedIndices := sliceutil.IntersectionUint64(req.Attestation_1.AttestingIndices, req.Attestation_2.AttestingIndices)
return &ethpb.SubmitSlashingResponse{
SlashedIndices: slashedIndices,
Expand Down
94 changes: 0 additions & 94 deletions beacon-chain/rpc/beacon/slashings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,14 @@ import (
"context"
"testing"

"github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings"
mockp2p "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)

func TestServer_SubmitProposerSlashing_DontBroadcast(t *testing.T) {
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{DisableBroadcastSlashings: true})
defer resetCfg()
ctx := context.Background()
st, privs := testutil.DeterministicGenesisState(t, 64)
slashedVal, err := st.ValidatorAtIndex(5)
require.NoError(t, err)
// We mark the validator at index 5 as already slashed.
slashedVal.Slashed = true
require.NoError(t, st.UpdateValidatorAtIndex(5, slashedVal))

mb := &mockp2p.MockBroadcaster{}
bs := &Server{
HeadFetcher: &mock.ChainService{
State: st,
},
SlashingsPool: slashings.NewPool(),
Broadcaster: mb,
}

// We want a proposer slashing for validator with index 2 to
// be included in the pool.
wanted := &ethpb.SubmitSlashingResponse{
SlashedIndices: []uint64{2},
}
slashing, err := testutil.GenerateProposerSlashingForValidator(st, privs[2], uint64(2))
require.NoError(t, err)

res, err := bs.SubmitProposerSlashing(ctx, slashing)
require.NoError(t, err)
if !proto.Equal(wanted, res) {
t.Errorf("Wanted %v, received %v", wanted, res)
}

assert.Equal(t, false, mb.BroadcastCalled, "Expected broadcast not to be called by default")

slashing, err = testutil.GenerateProposerSlashingForValidator(st, privs[5], uint64(5))
require.NoError(t, err)

// We do not want a proposer slashing for an already slashed validator
// (the validator at index 5) to be included in the pool.
_, err = bs.SubmitProposerSlashing(ctx, slashing)
require.ErrorContains(t, "Could not insert proposer slashing into pool", err)
}

func TestServer_SubmitProposerSlashing(t *testing.T) {
ctx := context.Background()

Expand Down Expand Up @@ -89,52 +41,6 @@ func TestServer_SubmitProposerSlashing(t *testing.T) {
assert.Equal(t, true, mb.BroadcastCalled, "Expected broadcast to be called")
}

func TestServer_SubmitAttesterSlashing_DontBroadcast(t *testing.T) {
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{DisableBroadcastSlashings: true})
defer resetCfg()
ctx := context.Background()
// We mark the validators at index 5, 6 as already slashed.
st, privs := testutil.DeterministicGenesisState(t, 64)
slashedVal, err := st.ValidatorAtIndex(5)
require.NoError(t, err)

// We mark the validator at index 5 as already slashed.
slashedVal.Slashed = true
require.NoError(t, st.UpdateValidatorAtIndex(5, slashedVal))

mb := &mockp2p.MockBroadcaster{}
bs := &Server{
HeadFetcher: &mock.ChainService{
State: st,
},
SlashingsPool: slashings.NewPool(),
Broadcaster: mb,
}

slashing, err := testutil.GenerateAttesterSlashingForValidator(st, privs[2], uint64(2))
require.NoError(t, err)

// We want the intersection of the slashing attesting indices
// to be slashed, so we expect validators 2 and 3 to be in the response
// slashed indices.
wanted := &ethpb.SubmitSlashingResponse{
SlashedIndices: []uint64{2},
}
res, err := bs.SubmitAttesterSlashing(ctx, slashing)
require.NoError(t, err)
if !proto.Equal(wanted, res) {
t.Errorf("Wanted %v, received %v", wanted, res)
}
assert.Equal(t, false, mb.BroadcastCalled, "Expected broadcast not to be called by default")

slashing, err = testutil.GenerateAttesterSlashingForValidator(st, privs[5], uint64(5))
require.NoError(t, err)
// If any of the attesting indices in the slashing object have already
// been slashed, we should fail to insert properly into the attester slashing pool.
_, err = bs.SubmitAttesterSlashing(ctx, slashing)
assert.NotNil(t, err, "Expected including a attester slashing for an already slashed validator to fail")
}

func TestServer_SubmitAttesterSlashing(t *testing.T) {
ctx := context.Background()
// We mark the validators at index 5, 6 as already slashed.
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/rpc/validator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ go_test(
"//shared/bls:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/mock:go_default_library",
"//shared/params:go_default_library",
Expand Down
34 changes: 6 additions & 28 deletions beacon-chain/rpc/validator/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
fastssz "github.com/ferranbt/fastssz"
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block"
Expand Down Expand Up @@ -538,39 +537,18 @@ func (vs *Server) depositTrie(ctx context.Context, canonicalEth1DataHeight *big.

var depositTrie *trieutil.SparseMerkleTrie

var finalizedDeposits *depositcache.FinalizedDeposits
if featureconfig.Get().EnableFinalizedDepositsCache {
finalizedDeposits = vs.DepositFetcher.FinalizedDeposits(ctx)
depositTrie = finalizedDeposits.Deposits
upToEth1DataDeposits := vs.DepositFetcher.NonFinalizedDeposits(ctx, canonicalEth1DataHeight)
insertIndex := finalizedDeposits.MerkleTrieIndex + 1
finalizedDeposits := vs.DepositFetcher.FinalizedDeposits(ctx)
depositTrie = finalizedDeposits.Deposits
upToEth1DataDeposits := vs.DepositFetcher.NonFinalizedDeposits(ctx, canonicalEth1DataHeight)
insertIndex := finalizedDeposits.MerkleTrieIndex + 1

for _, dep := range upToEth1DataDeposits {
depHash, err := dep.Data.HashTreeRoot()
if err != nil {
return nil, errors.Wrap(err, "could not hash deposit data")
}
depositTrie.Insert(depHash[:], int(insertIndex))
insertIndex++
}

return depositTrie, nil
}

upToEth1DataDeposits := vs.DepositFetcher.AllDeposits(ctx, canonicalEth1DataHeight)
var depositData [][]byte
for _, dep := range upToEth1DataDeposits {
depHash, err := dep.Data.HashTreeRoot()
if err != nil {
return nil, errors.Wrap(err, "could not hash deposit data")
}
depositData = append(depositData, depHash[:])
}

var err error
depositTrie, err = trieutil.GenerateTrieFromItems(depositData, params.BeaconConfig().DepositContractTreeDepth)
if err != nil {
return nil, errors.Wrap(err, "could not generate historical deposit trie from deposits")
depositTrie.Insert(depHash[:], int(insertIndex))
insertIndex++
}

return depositTrie, nil
Expand Down
3 changes: 0 additions & 3 deletions beacon-chain/rpc/validator/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/prysmaticlabs/prysm/shared/attestationutil"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
Expand Down Expand Up @@ -896,8 +895,6 @@ func TestProposer_PendingDeposits_CantReturnMoreThanDepositCount(t *testing.T) {

func TestProposer_DepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) {
ctx := context.Background()
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{EnableFinalizedDepositsCache: true})
defer resetCfg()

height := big.NewInt(int64(params.BeaconConfig().Eth1FollowDistance))
p := &mockPOW.POWChain{
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/state/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ go_library(
"//beacon-chain/state/stateutil:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/htrutils:go_default_library",
"//shared/params:go_default_library",
Expand Down
72 changes: 23 additions & 49 deletions beacon-chain/state/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/prysmaticlabs/go-bitfield"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
)

Expand Down Expand Up @@ -108,55 +107,30 @@ func (b *BeaconState) CloneInnerState() *pbp2p.BeaconState {
return nil
}

if featureconfig.Get().NewBeaconStateLocks {
b.lock.RLock()
defer b.lock.RUnlock()
return &pbp2p.BeaconState{
GenesisTime: b.genesisTime(),
GenesisValidatorsRoot: b.genesisValidatorRoot(),
Slot: b.slot(),
Fork: b.fork(),
LatestBlockHeader: b.latestBlockHeader(),
BlockRoots: b.blockRoots(),
StateRoots: b.stateRoots(),
HistoricalRoots: b.historicalRoots(),
Eth1Data: b.eth1Data(),
Eth1DataVotes: b.eth1DataVotes(),
Eth1DepositIndex: b.eth1DepositIndex(),
Validators: b.validators(),
Balances: b.balances(),
RandaoMixes: b.randaoMixes(),
Slashings: b.slashings(),
PreviousEpochAttestations: b.previousEpochAttestations(),
CurrentEpochAttestations: b.currentEpochAttestations(),
JustificationBits: b.justificationBits(),
PreviousJustifiedCheckpoint: b.previousJustifiedCheckpoint(),
CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint(),
FinalizedCheckpoint: b.finalizedCheckpoint(),
}
}
b.lock.RLock()
defer b.lock.RUnlock()
return &pbp2p.BeaconState{
GenesisTime: b.GenesisTime(),
GenesisValidatorsRoot: b.GenesisValidatorRoot(),
Slot: b.Slot(),
Fork: b.Fork(),
LatestBlockHeader: b.LatestBlockHeader(),
BlockRoots: b.BlockRoots(),
StateRoots: b.StateRoots(),
HistoricalRoots: b.HistoricalRoots(),
Eth1Data: b.Eth1Data(),
Eth1DataVotes: b.Eth1DataVotes(),
Eth1DepositIndex: b.Eth1DepositIndex(),
Validators: b.Validators(),
Balances: b.Balances(),
RandaoMixes: b.RandaoMixes(),
Slashings: b.Slashings(),
PreviousEpochAttestations: b.PreviousEpochAttestations(),
CurrentEpochAttestations: b.CurrentEpochAttestations(),
JustificationBits: b.JustificationBits(),
PreviousJustifiedCheckpoint: b.PreviousJustifiedCheckpoint(),
CurrentJustifiedCheckpoint: b.CurrentJustifiedCheckpoint(),
FinalizedCheckpoint: b.FinalizedCheckpoint(),
GenesisTime: b.genesisTime(),
GenesisValidatorsRoot: b.genesisValidatorRoot(),
Slot: b.slot(),
Fork: b.fork(),
LatestBlockHeader: b.latestBlockHeader(),
BlockRoots: b.blockRoots(),
StateRoots: b.stateRoots(),
HistoricalRoots: b.historicalRoots(),
Eth1Data: b.eth1Data(),
Eth1DataVotes: b.eth1DataVotes(),
Eth1DepositIndex: b.eth1DepositIndex(),
Validators: b.validators(),
Balances: b.balances(),
RandaoMixes: b.randaoMixes(),
Slashings: b.slashings(),
PreviousEpochAttestations: b.previousEpochAttestations(),
CurrentEpochAttestations: b.currentEpochAttestations(),
JustificationBits: b.justificationBits(),
PreviousJustifiedCheckpoint: b.previousJustifiedCheckpoint(),
CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint(),
FinalizedCheckpoint: b.finalizedCheckpoint(),
}
}

Expand Down
Loading

0 comments on commit 7076a1e

Please sign in to comment.