Remove unused Eth1Data-related code from the proposer (#9670)

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Radosław Kapka
2021-09-27 16:29:41 +02:00
committed by GitHub
parent bf41fd854d
commit 3e640fe79f
2 changed files with 0 additions and 161 deletions

View File

@@ -6,7 +6,6 @@ import (
"encoding/hex"
"fmt"
"math/big"
"reflect"
"time"
fastssz "github.com/ferranbt/fastssz"
@@ -469,66 +468,6 @@ func (vs *Server) slotStartTime(slot types.Slot) uint64 {
return core.VotingPeriodStartTime(startTime, slot)
}
func (vs *Server) inRangeVotes(ctx context.Context,
beaconState state.ReadOnlyBeaconState,
firstValidBlockNumber, lastValidBlockNumber *big.Int) ([]eth1DataSingleVote, error) {
currentETH1Data := vs.HeadFetcher.HeadETH1Data()
var inRangeVotes []eth1DataSingleVote
for _, eth1Data := range beaconState.Eth1DataVotes() {
exists, height, err := vs.BlockFetcher.BlockExistsWithCache(ctx, bytesutil.ToBytes32(eth1Data.BlockHash))
if err != nil {
log.Warningf("Could not fetch eth1data height for received eth1data vote: %v", err)
}
// Make sure we don't "undo deposit progress". See https://github.com/ethereum/consensus-specs/pull/1836
if eth1Data.DepositCount < currentETH1Data.DepositCount {
continue
}
// firstValidBlockNumber.Cmp(height) < 1 filters out all blocks before firstValidBlockNumber
// lastValidBlockNumber.Cmp(height) > -1 filters out all blocks after lastValidBlockNumber
// These filters result in the range [firstValidBlockNumber, lastValidBlockNumber]
if exists && firstValidBlockNumber.Cmp(height) < 1 && lastValidBlockNumber.Cmp(height) > -1 {
inRangeVotes = append(inRangeVotes, eth1DataSingleVote{eth1Data: eth1Data, blockHeight: height})
}
}
return inRangeVotes, nil
}
func chosenEth1DataMajorityVote(votes []eth1DataSingleVote) eth1DataAggregatedVote {
var voteCount []eth1DataAggregatedVote
for _, singleVote := range votes {
newVote := true
for i, aggregatedVote := range voteCount {
aggregatedData := aggregatedVote.data
if reflect.DeepEqual(singleVote.eth1Data, aggregatedData.eth1Data) {
voteCount[i].votes++
newVote = false
break
}
}
if newVote {
voteCount = append(voteCount, eth1DataAggregatedVote{data: singleVote, votes: 1})
}
}
if len(voteCount) == 0 {
return eth1DataAggregatedVote{}
}
currentVote := voteCount[0]
for _, aggregatedVote := range voteCount[1:] {
// Choose new eth1data if it has more votes or the same number of votes with a bigger block height.
if aggregatedVote.votes > currentVote.votes ||
(aggregatedVote.votes == currentVote.votes &&
aggregatedVote.data.blockHeight.Cmp(currentVote.data.blockHeight) == 1) {
currentVote = aggregatedVote
}
}
return currentVote
}
func (vs *Server) mockETH1DataVote(ctx context.Context, slot types.Slot) (*ethpb.Eth1Data, error) {
if !eth1DataNotification {
log.Warn("Beacon Node is no longer connected to an ETH1 chain, so ETH1 data votes are now mocked.")
@@ -767,37 +706,6 @@ func (vs *Server) validateDepositTrie(trie *trie.SparseMerkleTrie, canonicalEth1
return true, nil
}
// in case no vote for new eth1data vote considered best vote we
// default into returning the latest deposit root and the block
// hash of eth1 block hash that is FOLLOW_DISTANCE back from its
// latest block.
func (vs *Server) defaultEth1DataResponse(ctx context.Context, currentHeight *big.Int) (*ethpb.Eth1Data, error) {
if ctx.Err() != nil {
return nil, ctx.Err()
}
eth1FollowDistance := int64(params.BeaconConfig().Eth1FollowDistance)
ancestorHeight := big.NewInt(0).Sub(currentHeight, big.NewInt(eth1FollowDistance))
blockHash, err := vs.Eth1BlockFetcher.BlockHashByHeight(ctx, ancestorHeight)
if err != nil {
return nil, errors.Wrap(err, "could not fetch ETH1_FOLLOW_DISTANCE ancestor")
}
// Fetch all historical deposits up to an ancestor height.
depositsTillHeight, depositRoot := vs.DepositFetcher.DepositsNumberAndRootAtHeight(ctx, ancestorHeight)
if depositsTillHeight == 0 {
return vs.ChainStartFetcher.ChainStartEth1Data(), nil
}
// // Make sure we don't "undo deposit progress". See https://github.com/ethereum/consensus-specs/pull/1836
currentETH1Data := vs.HeadFetcher.HeadETH1Data()
if depositsTillHeight < currentETH1Data.DepositCount {
return currentETH1Data, nil
}
return &ethpb.Eth1Data{
DepositRoot: depositRoot[:],
BlockHash: blockHash[:],
DepositCount: depositsTillHeight,
}, nil
}
// This filters the input attestations to return a list of valid attestations to be packaged inside a beacon block.
func (vs *Server) filterAttestationsForBlockInclusion(ctx context.Context, st state.BeaconState, atts []*ethpb.Attestation) ([]*ethpb.Attestation, error) {
ctx, span := trace.StartSpan(ctx, "ProposerServer.filterAttestationsForBlockInclusion")

View File

@@ -1237,75 +1237,6 @@ func TestProposer_ValidateDepositTrie(t *testing.T) {
}
}
func TestProposer_Eth1Data_NoBlockExists(t *testing.T) {
params.SetupTestConfigCleanup(t)
params.UseMinimalConfig()
ctx := context.Background()
height := big.NewInt(int64(params.BeaconConfig().Eth1FollowDistance))
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 := trie.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 {
assert.NoError(t, depositCache.InsertDeposit(context.Background(), dp.Deposit, dp.Eth1BlockHeight, dp.Index, depositTrie.HashTreeRoot()))
}
p := &mockPOW.POWChain{
LatestBlockNumber: height,
HashesByHeight: map[int][]byte{
0: []byte("hash0"),
12: []byte("hash12"),
},
}
proposerServer := &Server{
ChainStartFetcher: p,
Eth1InfoFetcher: p,
Eth1BlockFetcher: p,
DepositFetcher: depositCache,
PendingDepositsFetcher: depositCache,
}
defEth1Data := &ethpb.Eth1Data{
DepositCount: 10,
BlockHash: []byte{'t', 'e', 's', 't'},
DepositRoot: []byte{'r', 'o', 'o', 't'},
}
p.Eth1Data = defEth1Data
result, err := proposerServer.defaultEth1DataResponse(ctx, big.NewInt(16))
require.NoError(t, err)
if !proto.Equal(result, defEth1Data) {
t.Errorf("Did not receive default eth1data. Wanted %v but got %v", defEth1Data, result)
}
}
func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
slot := types.Slot(64)
earliestValidTime, latestValidTime := majorityVoteBoundaryTime(slot)