Deprecate Uneeded Flags (#8455)

* remove disable pruning flag

* deprecate disable majority vote flag

* remove eth1dataVoteCache

* remove outdated methods

* gaz
This commit is contained in:
Nishant Das
2021-02-16 23:27:37 +08:00
committed by GitHub
parent bf7425bae4
commit fe27ca359c
9 changed files with 16 additions and 328 deletions

View File

@@ -422,11 +422,9 @@ func (s *Service) insertFinalizedDeposits(ctx context.Context, fRoot [32]byte) e
// because the Eth1 follow distance makes such long-range reorgs extremely unlikely.
eth1DepositIndex := int64(finalizedState.Eth1Data().DepositCount - 1)
s.depositCache.InsertFinalizedDeposits(ctx, eth1DepositIndex)
if featureconfig.Get().EnablePruningDepositProofs {
// Deposit proofs are only used during state transition and can be safely removed to save space.
if err = s.depositCache.PruneProofs(ctx, eth1DepositIndex); err != nil {
return errors.Wrap(err, "could not prune deposit proofs")
}
// Deposit proofs are only used during state transition and can be safely removed to save space.
if err = s.depositCache.PruneProofs(ctx, eth1DepositIndex); err != nil {
return errors.Wrap(err, "could not prune deposit proofs")
}
return nil
}

View File

@@ -22,7 +22,6 @@ import (
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/attestationutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
@@ -953,11 +952,6 @@ func TestOnBlock_CanFinalize(t *testing.T) {
}
func TestInsertFinalizedDeposits(t *testing.T) {
flags := featureconfig.Get()
flags.EnablePruningDepositProofs = true
reset := featureconfig.InitWithReset(flags)
defer reset()
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
depositCache, err := depositcache.New()

View File

@@ -2,12 +2,8 @@ package cache
import (
"testing"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
)
func TestMain(m *testing.M) {
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{EnableEth1DataVoteCache: true})
defer resetCfg()
m.Run()
}

View File

@@ -103,7 +103,6 @@ go_test(
"//shared/bls:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/mock:go_default_library",
"//shared/params:go_default_library",
"//shared/testutil:go_default_library",
@@ -111,7 +110,6 @@ go_test(
"//shared/testutil/require:go_default_library",
"//shared/timeutils:go_default_library",
"//shared/trieutil:go_default_library",
"@com_github_ferranbt_fastssz//:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_gogo_protobuf//types:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",

View File

@@ -82,12 +82,7 @@ func (vs *Server) GetBlock(ctx context.Context, req *ethpb.BlockRequest) (*ethpb
}
}
var eth1Data *ethpb.Eth1Data
if featureconfig.Get().EnableEth1DataMajorityVote {
eth1Data, err = vs.eth1DataMajorityVote(ctx, head)
} else {
eth1Data, err = vs.eth1Data(ctx, req.Slot)
}
eth1Data, err := vs.eth1DataMajorityVote(ctx, head)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not get ETH1 data: %v", err)
}
@@ -178,41 +173,6 @@ func (vs *Server) ProposeBlock(ctx context.Context, blk *ethpb.SignedBeaconBlock
}, nil
}
// eth1Data determines the appropriate eth1data for a block proposal. The algorithm for this method
// is as follows:
// - Determine the timestamp for the start slot for the eth1 voting period.
// - Determine the most recent eth1 block before that timestamp.
// - Subtract that eth1block.number by ETH1_FOLLOW_DISTANCE.
// - This is the eth1block to use for the block proposal.
func (vs *Server) eth1Data(ctx context.Context, slot types.Slot) (*ethpb.Eth1Data, error) {
ctx, cancel := context.WithTimeout(ctx, eth1dataTimeout)
defer cancel()
if vs.MockEth1Votes {
return vs.mockETH1DataVote(ctx, slot)
}
if !vs.Eth1InfoFetcher.IsConnectedToETH1() {
return vs.randomETH1DataVote(ctx)
}
eth1DataNotification = false
eth1VotingPeriodStartTime := vs.slotStartTime(slot)
// Look up most recent block up to timestamp
blockNumber, err := vs.Eth1BlockFetcher.BlockByTimestamp(ctx, eth1VotingPeriodStartTime)
if err != nil {
log.WithError(err).Error("Could not get block number from timestamp")
return vs.randomETH1DataVote(ctx)
}
eth1Data, err := vs.defaultEth1DataResponse(ctx, blockNumber.Number)
if err != nil {
log.WithError(err).Error("Could not get eth1 data from block number")
return vs.randomETH1DataVote(ctx)
}
return eth1Data, nil
}
// eth1DataMajorityVote determines the appropriate eth1data for a block proposal using
// an algorithm called Voting with the Majority. The algorithm works as follows:
// - Determine the timestamp for the start slot for the eth1 voting period.

View File

@@ -5,7 +5,6 @@ import (
"math/big"
"testing"
fastssz "github.com/ferranbt/fastssz"
"github.com/gogo/protobuf/proto"
types "github.com/prysmaticlabs/eth2-types"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
@@ -29,7 +28,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/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
@@ -1006,28 +1004,6 @@ func TestProposer_DepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) {
assert.Equal(t, expectedRoot, actualRoot, "Incorrect deposit trie root")
}
func TestProposer_Eth1Data_EmptyVotesFetchBlockHashFailure(t *testing.T) {
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
Eth1Data: &ethpb.Eth1Data{
BlockHash: []byte{'a'},
},
Eth1DataVotes: []*ethpb.Eth1Data{},
})
require.NoError(t, err)
p := &mockPOW.FaultyMockPOWChain{
HashesByHeight: make(map[int][]byte),
}
proposerServer := &Server{
ChainStartFetcher: p,
Eth1InfoFetcher: p,
Eth1BlockFetcher: p,
BlockReceiver: &mock.ChainService{State: beaconState},
HeadFetcher: &mock.ChainService{State: beaconState},
}
_, err = proposerServer.eth1Data(context.Background(), beaconState.Slot()+1)
assert.NoError(t, err, "A failed request should not have returned an error, got %v")
}
func TestProposer_Eth1Data_NoBlockExists(t *testing.T) {
ctx := context.Background()
@@ -1095,146 +1071,6 @@ func TestProposer_Eth1Data_NoBlockExists(t *testing.T) {
}
}
func TestProposer_Eth1Data(t *testing.T) {
slot := types.Slot(20000)
p := &mockPOW.POWChain{
BlockNumberByTime: map[uint64]*big.Int{
uint64(slot.Mul(params.BeaconConfig().SecondsPerSlot)): big.NewInt(8196),
},
HashesByHeight: map[int][]byte{
8180: []byte("8180"),
},
Eth1Data: &ethpb.Eth1Data{
DepositCount: 55,
},
}
headState, err := testutil.NewBeaconState()
require.NoError(t, err)
require.NoError(t, headState.SetEth1Data(&ethpb.Eth1Data{DepositCount: 55}))
depositCache, err := depositcache.New()
require.NoError(t, err)
ps := &Server{
ChainStartFetcher: p,
Eth1InfoFetcher: p,
Eth1BlockFetcher: p,
DepositFetcher: depositCache,
HeadFetcher: &mock.ChainService{State: headState},
}
ctx := context.Background()
eth1Data, err := ps.eth1Data(ctx, slot)
require.NoError(t, err)
assert.Equal(t, uint64(55), eth1Data.DepositCount)
}
func TestProposer_Eth1Data_SmallerDepositCount(t *testing.T) {
slot := types.Slot(20000)
deps := []*dbpb.DepositContainer{
{
Index: 0,
Eth1BlockHeight: 8,
Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{
PublicKey: bytesutil.PadTo([]byte("a"), 48),
Signature: make([]byte, 96),
WithdrawalCredentials: make([]byte, 32),
}},
},
{
Index: 1,
Eth1BlockHeight: 14,
Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{
PublicKey: bytesutil.PadTo([]byte("b"), 48),
Signature: make([]byte, 96),
WithdrawalCredentials: make([]byte, 32),
}},
},
}
depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New()
require.NoError(t, err)
for _, dp := range deps {
depositCache.InsertDeposit(context.Background(), dp.Deposit, dp.Eth1BlockHeight, dp.Index, depositTrie.Root())
}
p := &mockPOW.POWChain{
BlockNumberByTime: map[uint64]*big.Int{
uint64(slot.Mul(params.BeaconConfig().SecondsPerSlot)): big.NewInt(4096),
},
HashesByHeight: map[int][]byte{
4080: []byte("4080"),
},
Eth1Data: &ethpb.Eth1Data{
DepositCount: 55,
},
}
ps := &Server{
ChainStartFetcher: p,
Eth1InfoFetcher: p,
Eth1BlockFetcher: p,
HeadFetcher: &mock.ChainService{ETH1Data: &ethpb.Eth1Data{DepositCount: 10}},
DepositFetcher: depositCache,
}
ctx := context.Background()
eth1Data, err := ps.eth1Data(ctx, slot)
require.NoError(t, err)
// Will default to 10 as the current deposit count in the
// cache is only 2.
assert.Equal(t, uint64(10), eth1Data.DepositCount)
}
func TestProposer_Eth1Data_MockEnabled(t *testing.T) {
db := dbutil.SetupDB(t)
// If a mock eth1 data votes is specified, we use the following for the
// eth1data we provide to every proposer based on https://github.com/ethereum/eth2.0-pm/issues/62:
//
// slot_in_voting_period = current_slot % SLOTS_PER_ETH1_VOTING_PERIOD
// Eth1Data(
// DepositRoot = hash(current_epoch + slot_in_voting_period),
// DepositCount = state.eth1_deposit_index,
// BlockHash = hash(hash(current_epoch + slot_in_voting_period)),
// )
ctx := context.Background()
headState, err := testutil.NewBeaconState()
require.NoError(t, err)
require.NoError(t, headState.SetEth1DepositIndex(64))
ps := &Server{
HeadFetcher: &mock.ChainService{State: headState},
BeaconDB: db,
MockEth1Votes: true,
}
headBlockRoot := [32]byte{1, 2, 3}
require.NoError(t, db.SaveState(ctx, headState, headBlockRoot))
require.NoError(t, db.SaveHeadBlockRoot(ctx, headBlockRoot))
eth1Data, err := ps.eth1Data(ctx, 100)
require.NoError(t, err)
period := uint64(params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().EpochsPerEth1VotingPeriod)))
wantedSlot := types.Slot(100).Mod(period)
currentEpoch := helpers.SlotToEpoch(100)
var enc []byte
enc = fastssz.MarshalUint64(enc, uint64(currentEpoch)+uint64(wantedSlot))
depRoot := hashutil.Hash(enc)
blockHash := hashutil.Hash(depRoot[:])
want := &ethpb.Eth1Data{
DepositRoot: depRoot[:],
BlockHash: blockHash[:],
DepositCount: 64,
}
if !proto.Equal(eth1Data, want) {
t.Errorf("Wanted %v, received %v", want, eth1Data)
}
}
func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
slot := types.Slot(64)
earliestValidTime, latestValidTime := majorityVoteBoundaryTime(slot)
@@ -1882,88 +1718,6 @@ func TestProposer_FilterAttestation(t *testing.T) {
}
}
func Benchmark_Eth1Data(b *testing.B) {
ctx := context.Background()
hashesByHeight := make(map[int][]byte)
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
Eth1DataVotes: []*ethpb.Eth1Data{},
Eth1Data: &ethpb.Eth1Data{
BlockHash: []byte("stub"),
},
})
require.NoError(b, err)
var mockSig [96]byte
var mockCreds [32]byte
deposits := []*dbpb.DepositContainer{
{
Index: 0,
Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{
PublicKey: bytesutil.PadTo([]byte("a"), 48),
Signature: mockSig[:],
WithdrawalCredentials: mockCreds[:],
}},
},
{
Index: 1,
Deposit: &ethpb.Deposit{
Data: &ethpb.Deposit_Data{
PublicKey: bytesutil.PadTo([]byte("b"), 48),
Signature: mockSig[:],
WithdrawalCredentials: mockCreds[:],
}},
},
}
depositCache, err := depositcache.New()
require.NoError(b, err)
for i, dp := range deposits {
var root [32]byte
copy(root[:], []byte{'d', 'e', 'p', 'o', 's', 'i', 't', byte(i)})
depositCache.InsertDeposit(ctx, dp.Deposit, uint64(dp.Index), dp.Index, root)
}
numOfVotes := 1000
for i := 0; i < numOfVotes; i++ {
blockhash := []byte{'b', 'l', 'o', 'c', 'k', byte(i)}
deposit := []byte{'d', 'e', 'p', 'o', 's', 'i', 't', byte(i)}
err := beaconState.SetEth1DataVotes(append(beaconState.Eth1DataVotes(), &ethpb.Eth1Data{
BlockHash: blockhash,
DepositRoot: deposit,
}))
require.NoError(b, err)
hashesByHeight[i] = blockhash
}
hashesByHeight[numOfVotes+1] = []byte("stub")
blk := testutil.NewBeaconBlock()
blk.Block.Slot = beaconState.Slot()
blkRoot, err := blk.HashTreeRoot()
require.NoError(b, err)
currentHeight := params.BeaconConfig().Eth1FollowDistance + 5
p := &mockPOW.POWChain{
LatestBlockNumber: big.NewInt(int64(currentHeight)),
HashesByHeight: hashesByHeight,
}
proposerServer := &Server{
BlockReceiver: &mock.ChainService{State: beaconState, Root: blkRoot[:]},
HeadFetcher: &mock.ChainService{State: beaconState, Root: blkRoot[:]},
ChainStartFetcher: p,
Eth1InfoFetcher: p,
Eth1BlockFetcher: p,
DepositFetcher: depositCache,
PendingDepositsFetcher: depositCache,
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := proposerServer.eth1Data(context.Background(), beaconState.Slot()+1)
require.NoError(b, err)
}
}
func TestProposer_Deposits_ReturnsEmptyList_IfLatestEth1DataEqGenesisEth1Block(t *testing.T) {
ctx := context.Background()

View File

@@ -41,9 +41,7 @@ type Flags struct {
SkipBLSVerify bool // Skips BLS verification across the runtime.
EnableBlst bool // Enables new BLS library from supranational.
SlasherProtection bool // SlasherProtection protects validator fron sending over a slashable offense over the network using external slasher.
EnableEth1DataMajorityVote bool // EnableEth1DataMajorityVote uses the Voting With The Majority algorithm to vote for eth1data.
EnablePeerScorer bool // EnablePeerScorer enables experimental peer scoring in p2p.
EnablePruningDepositProofs bool // EnablePruningDepositProofs enables pruning deposit proofs which significantly reduces the size of a deposit
EnableLargerGossipHistory bool // EnableLargerGossipHistory increases the gossip history we store in our caches.
WriteWalletPasswordOnWebOnboarding bool // WriteWalletPasswordOnWebOnboarding writes the password to disk after Prysm web signup.
DisableAttestingHistoryDBCache bool // DisableAttestingHistoryDBCache for the validator client increases disk reads/writes.
@@ -58,7 +56,6 @@ type Flags struct {
// Cache toggles.
EnableSSZCache bool // EnableSSZCache see https://github.com/prysmaticlabs/prysm/pull/4558.
EnableEth1DataVoteCache bool // EnableEth1DataVoteCache; see https://github.com/prysmaticlabs/prysm/issues/3106.
EnableNextSlotStateCache bool // EnableNextSlotStateCache enables next slot state cache to improve validator performance.
// Bug fixes related flags.
@@ -158,11 +155,6 @@ func ConfigureBeaconChain(ctx *cli.Context) {
}
log.Infof("Using %q strategy on attestation aggregation", cfg.AttestationAggregationStrategy)
cfg.EnableEth1DataMajorityVote = true
if ctx.Bool(disableEth1DataMajorityVote.Name) {
log.Warn("Disabling eth1data majority vote")
cfg.EnableEth1DataMajorityVote = false
}
if ctx.Bool(enablePeerScorer.Name) {
log.Warn("Enabling peer scoring in P2P")
cfg.EnablePeerScorer = true
@@ -175,11 +167,6 @@ func ConfigureBeaconChain(ctx *cli.Context) {
log.Warn("Disabling new BLS library blst")
cfg.EnableBlst = false
}
cfg.EnablePruningDepositProofs = true
if ctx.Bool(disablePruningDepositProofs.Name) {
log.Warn("Disabling pruning deposit proofs")
cfg.EnablePruningDepositProofs = false
}
if ctx.Bool(enableLargerGossipHistory.Name) {
log.Warn("Using a larger gossip history for the node")
cfg.EnableLargerGossipHistory = true

View File

@@ -22,10 +22,22 @@ var (
Usage: deprecatedUsage,
Hidden: true,
}
deprecatedDisablePruningDepositProofs = &cli.BoolFlag{
Name: "disable-pruning-deposit-proofs",
Usage: deprecatedUsage,
Hidden: true,
}
deprecatedDisableEth1DataMajorityVote = &cli.BoolFlag{
Name: "disable-eth1-data-majority-vote",
Usage: deprecatedUsage,
Hidden: true,
}
)
var deprecatedFlags = []cli.Flag{
exampleDeprecatedFeatureFlag,
deprecatedEnableSyncBacktracking,
deprecatedDisableSyncBacktracking,
deprecatedDisablePruningDepositProofs,
deprecatedDisableEth1DataMajorityVote,
}

View File

@@ -61,10 +61,6 @@ var (
Name: "disable-blst",
Usage: "Disables the new BLS library, blst, from Supranational",
}
disableEth1DataMajorityVote = &cli.BoolFlag{
Name: "disable-eth1-data-majority-vote",
Usage: "Disables the Voting With The Majority algorithm when voting for eth1data.",
}
disableAccountsV2 = &cli.BoolFlag{
Name: "disable-accounts-v2",
Usage: "Disables usage of v2 for Prysm validator accounts",
@@ -77,11 +73,6 @@ var (
Name: "use-check-point-cache",
Usage: "Enables check point info caching",
}
disablePruningDepositProofs = &cli.BoolFlag{
Name: "disable-pruning-deposit-proofs",
Usage: "Disables pruning deposit proofs when they are no longer needed." +
"This will probably significantly increase the amount of memory taken up by deposits.",
}
enableLargerGossipHistory = &cli.BoolFlag{
Name: "enable-larger-gossip-history",
Usage: "Enables the node to store a larger amount of gossip messages in its cache.",
@@ -164,11 +155,9 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{
PyrmontTestnet,
Mainnet,
disableBlst,
disableEth1DataMajorityVote,
enablePeerScorer,
enableLargerGossipHistory,
checkPtInfoCache,
disablePruningDepositProofs,
disableBroadcastSlashingFlag,
enableNextSlotStateCache,
forceOptMaxCoverAggregationStategy,