mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
remove unused funcs and vars (#2214)
This commit is contained in:
@@ -212,14 +212,3 @@ func (c *ChainService) ChainHeadRoot() ([32]byte, error) {
|
||||
}
|
||||
return root, nil
|
||||
}
|
||||
|
||||
// doesPoWBlockExist checks if the referenced PoW block exists.
|
||||
func (c *ChainService) doesPoWBlockExist(hash [32]byte) bool {
|
||||
powBlock, err := c.web3Service.Client().BlockByHash(c.ctx, hash)
|
||||
if err != nil {
|
||||
log.Debugf("fetching PoW block corresponding to mainchain reference failed: %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
return powBlock != nil
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["attestation.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/core/attestations",
|
||||
visibility = ["//beacon-chain:__subpackages__"],
|
||||
deps = [
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["attestation_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["//proto/beacon/p2p/v1:go_default_library"],
|
||||
)
|
||||
@@ -1,48 +0,0 @@
|
||||
// Package attestations tracks the life-cycle of the latest attestations
|
||||
// from each validator. It also contains libraries to create attestation
|
||||
// message, verify attestation correctness and slashing conditions.
|
||||
package attestations
|
||||
|
||||
import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
)
|
||||
|
||||
// IsDoubleVote checks if both of the attestations have been used to vote for the same slot.
|
||||
// Spec:
|
||||
// def is_double_vote(attestation_data_1: AttestationData,
|
||||
// attestation_data_2: AttestationData) -> bool
|
||||
// """
|
||||
// Checks if the two ``AttestationData`` have the same target.
|
||||
// """
|
||||
// target_epoch_1 = slot_to_epoch(attestation_data_1.slot)
|
||||
// target_epoch_2 = slot_to_epoch(attestation_data_2.slot)
|
||||
// return target_epoch_1 == target_epoch_2
|
||||
func IsDoubleVote(attestation1 *pb.AttestationData, attestation2 *pb.AttestationData) bool {
|
||||
targetEpoch1 := helpers.SlotToEpoch(attestation1.Slot)
|
||||
targetEpoch2 := helpers.SlotToEpoch(attestation2.Slot)
|
||||
return targetEpoch1 == targetEpoch2
|
||||
}
|
||||
|
||||
// IsSurroundVote checks if the data provided by the attestations fulfill the conditions for
|
||||
// a surround vote.
|
||||
// Spec:
|
||||
// def is_surround_vote(attestation_data_1: AttestationData,
|
||||
// attestation_data_2: AttestationData) -> bool:
|
||||
// """
|
||||
// Checks if ``attestation_data_1`` surrounds ``attestation_data_2``.
|
||||
// """
|
||||
// source_epoch_1 = attestation_data_1.justified_epoch
|
||||
// source_epoch_2 = attestation_data_2.justified_epoch
|
||||
// target_epoch_1 = slot_to_epoch(attestation_data_1.slot)
|
||||
// target_epoch_2 = slot_to_epoch(attestation_data_2.slot)
|
||||
//
|
||||
// return source_epoch_1 < source_epoch_2 and target_epoch_2 < target_epoch_1
|
||||
func IsSurroundVote(attestation1 *pb.AttestationData, attestation2 *pb.AttestationData) bool {
|
||||
sourceEpoch1 := attestation1.JustifiedEpoch
|
||||
sourceEpoch2 := attestation2.JustifiedEpoch
|
||||
targetEpoch1 := helpers.SlotToEpoch(attestation1.Slot)
|
||||
targetEpoch2 := helpers.SlotToEpoch(attestation2.Slot)
|
||||
|
||||
return sourceEpoch1 < sourceEpoch2 && targetEpoch2 < targetEpoch1
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package attestations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
)
|
||||
|
||||
func TestIsDoubleVote_SameAndDifferentEpochs(t *testing.T) {
|
||||
att1 := &pb.AttestationData{
|
||||
Slot: 0,
|
||||
}
|
||||
|
||||
att2 := &pb.AttestationData{
|
||||
Slot: 64,
|
||||
}
|
||||
|
||||
if IsDoubleVote(att1, att2) {
|
||||
t.Error("It is a double vote despite the attestations being on different epochs")
|
||||
}
|
||||
|
||||
att2.Slot = 1
|
||||
|
||||
if !IsDoubleVote(att1, att2) {
|
||||
t.Error("It is not a double vote despite the attestations being on the same epoch")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsSurroundVote_SameAndDifferentEpochs(t *testing.T) {
|
||||
att1 := &pb.AttestationData{
|
||||
Slot: 0,
|
||||
JustifiedEpoch: 0,
|
||||
}
|
||||
|
||||
att2 := &pb.AttestationData{
|
||||
Slot: 0,
|
||||
JustifiedEpoch: 0,
|
||||
}
|
||||
|
||||
if IsSurroundVote(att1, att2) {
|
||||
t.Error("It is a surround vote despite both attestations having the same epoch")
|
||||
}
|
||||
|
||||
att1.Slot = 192
|
||||
att2.JustifiedEpoch = 1
|
||||
att2.Slot = 128
|
||||
|
||||
if !IsSurroundVote(att1, att2) {
|
||||
t.Error("It is not a surround vote despite all the surround conditions being fulfilled")
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
package blocks
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
@@ -60,23 +59,3 @@ func ProcessBlockRoots(ctx context.Context, state *pb.BeaconState, parentRoot [3
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
// BlockChildren obtains the blocks in a list of observed blocks which have the current
|
||||
// beacon block's hash as their parent root hash.
|
||||
//
|
||||
// Spec pseudocode definition:
|
||||
// Let get_children(store: Store, block: BeaconBlock) ->
|
||||
// List[BeaconBlock] returns the child blocks of the given block.
|
||||
func BlockChildren(block *pb.BeaconBlock, observedBlocks []*pb.BeaconBlock) ([]*pb.BeaconBlock, error) {
|
||||
var children []*pb.BeaconBlock
|
||||
root, err := hashutil.HashBeaconBlock(block)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not hash block: %v", err)
|
||||
}
|
||||
for _, observed := range observedBlocks {
|
||||
if bytes.Equal(observed.ParentRootHash32, root[:]) {
|
||||
children = append(children, observed)
|
||||
}
|
||||
}
|
||||
return children, nil
|
||||
}
|
||||
|
||||
@@ -95,33 +95,6 @@ func PrevAttestations(ctx context.Context, state *pb.BeaconState) []*pb.PendingA
|
||||
return prevEpochAttestations
|
||||
}
|
||||
|
||||
// PrevJustifiedAttestations returns the justified attestations
|
||||
// of the previous 2 epochs.
|
||||
//
|
||||
// Spec pseudocode definition:
|
||||
// return [a for a in current_epoch_attestations + previous_epoch_attestations
|
||||
// if a.data.justified_epoch == state.previous_justified_epoch]
|
||||
func PrevJustifiedAttestations(
|
||||
ctx context.Context,
|
||||
state *pb.BeaconState,
|
||||
currentEpochAttestations []*pb.PendingAttestation,
|
||||
prevEpochAttestations []*pb.PendingAttestation,
|
||||
) []*pb.PendingAttestation {
|
||||
|
||||
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.state.ProcessEpoch.PrevJustifiedAttestations")
|
||||
defer span.End()
|
||||
|
||||
var prevJustifiedAttestations []*pb.PendingAttestation
|
||||
epochAttestations := append(currentEpochAttestations, prevEpochAttestations...)
|
||||
|
||||
for _, attestation := range epochAttestations {
|
||||
if attestation.Data.JustifiedEpoch == state.PreviousJustifiedEpoch {
|
||||
prevJustifiedAttestations = append(prevJustifiedAttestations, attestation)
|
||||
}
|
||||
}
|
||||
return prevJustifiedAttestations
|
||||
}
|
||||
|
||||
// PrevEpochBoundaryAttestations returns the boundary attestations
|
||||
// at the start of the previous epoch.
|
||||
//
|
||||
|
||||
@@ -212,39 +212,6 @@ func TestPrevEpochAttestations_AccurateAttestationSlots(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrevJustifiedAttestations_AccurateShardsAndEpoch(t *testing.T) {
|
||||
prevEpochAttestations := []*pb.PendingAttestation{
|
||||
{Data: &pb.AttestationData{JustifiedEpoch: 0}},
|
||||
{Data: &pb.AttestationData{JustifiedEpoch: 0}},
|
||||
{Data: &pb.AttestationData{JustifiedEpoch: 0}},
|
||||
{Data: &pb.AttestationData{Shard: 2, JustifiedEpoch: 1}},
|
||||
{Data: &pb.AttestationData{Shard: 3, JustifiedEpoch: 1}},
|
||||
{Data: &pb.AttestationData{JustifiedEpoch: 15}},
|
||||
}
|
||||
|
||||
thisEpochAttestations := []*pb.PendingAttestation{
|
||||
{Data: &pb.AttestationData{JustifiedEpoch: 0}},
|
||||
{Data: &pb.AttestationData{JustifiedEpoch: 0}},
|
||||
{Data: &pb.AttestationData{JustifiedEpoch: 0}},
|
||||
{Data: &pb.AttestationData{JustifiedEpoch: 1}},
|
||||
{Data: &pb.AttestationData{Shard: 1, JustifiedEpoch: 1}},
|
||||
{Data: &pb.AttestationData{JustifiedEpoch: 13}},
|
||||
}
|
||||
|
||||
state := &pb.BeaconState{PreviousJustifiedEpoch: 1}
|
||||
|
||||
prevJustifiedAttestations := PrevJustifiedAttestations(context.Background(), state, thisEpochAttestations, prevEpochAttestations)
|
||||
|
||||
for i, attestation := range prevJustifiedAttestations {
|
||||
if attestation.Data.Shard != uint64(i) {
|
||||
t.Errorf("Wanted shard %d, got %d", i, attestation.Data.Shard)
|
||||
}
|
||||
if attestation.Data.JustifiedEpoch != 1 {
|
||||
t.Errorf("Wanted justified epoch 0, got %d", attestation.Data.JustifiedEpoch)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrevEpochBoundaryAttestations_AccurateAttestationData(t *testing.T) {
|
||||
if params.BeaconConfig().SlotsPerEpoch != 64 {
|
||||
t.Errorf("SlotsPerEpoch should be 64 for these tests to pass")
|
||||
|
||||
@@ -56,11 +56,6 @@ func StartSlot(epoch uint64) uint64 {
|
||||
return epoch * params.BeaconConfig().SlotsPerEpoch
|
||||
}
|
||||
|
||||
// AttestationCurrentEpoch returns the current epoch referenced by the attestation.
|
||||
func AttestationCurrentEpoch(att *pb.AttestationData) uint64 {
|
||||
return SlotToEpoch(att.Slot)
|
||||
}
|
||||
|
||||
// IsEpochStart returns true if the given slot number is an epoch starting slot
|
||||
// number.
|
||||
func IsEpochStart(slot uint64) bool {
|
||||
|
||||
@@ -97,23 +97,6 @@ func TestEpochStartSlot_OK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttestationCurrentEpoch_OK(t *testing.T) {
|
||||
tests := []struct {
|
||||
slot uint64
|
||||
epoch uint64
|
||||
}{
|
||||
{slot: 0 * params.BeaconConfig().SlotsPerEpoch, epoch: 0},
|
||||
{slot: 1 * params.BeaconConfig().SlotsPerEpoch, epoch: 1},
|
||||
{slot: 10 * params.BeaconConfig().SlotsPerEpoch, epoch: 10},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
attData := &pb.AttestationData{Slot: tt.slot}
|
||||
if tt.epoch != AttestationCurrentEpoch(attData) {
|
||||
t.Errorf("AttestationEpoch(%d) = %d, wanted: %d", attData.Slot, AttestationCurrentEpoch(attData), tt.epoch)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsEpochStart(t *testing.T) {
|
||||
epochLength := params.BeaconConfig().SlotsPerEpoch
|
||||
|
||||
|
||||
@@ -246,34 +246,6 @@ func (db *BeaconDB) BlockBySlot(ctx context.Context, slot uint64) (*pb.BeaconBlo
|
||||
return block, err
|
||||
}
|
||||
|
||||
// HasBlockBySlot returns a boolean, and if the block exists, it returns the block.
|
||||
func (db *BeaconDB) HasBlockBySlot(slot uint64) (bool, *pb.BeaconBlock, error) {
|
||||
var block *pb.BeaconBlock
|
||||
var exists bool
|
||||
slotEnc := encodeSlotNumber(slot)
|
||||
|
||||
err := db.view(func(tx *bolt.Tx) error {
|
||||
mainChain := tx.Bucket(mainChainBucket)
|
||||
blockBkt := tx.Bucket(blockBucket)
|
||||
|
||||
blockRoot := mainChain.Get(slotEnc)
|
||||
if blockRoot == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
enc := blockBkt.Get(blockRoot)
|
||||
if enc == nil {
|
||||
return nil
|
||||
}
|
||||
exists = true
|
||||
|
||||
var err error
|
||||
block, err = createBlock(enc)
|
||||
return err
|
||||
})
|
||||
return exists, block, err
|
||||
}
|
||||
|
||||
// HighestBlockSlot returns the in-memory value for the highest block we've
|
||||
// seen in the database.
|
||||
func (db *BeaconDB) HighestBlockSlot() uint64 {
|
||||
|
||||
@@ -238,46 +238,6 @@ func TestChainProgress_OK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasBlockBySlot_OK(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
blkSlot := uint64(10)
|
||||
block1 := &pb.BeaconBlock{
|
||||
Slot: blkSlot,
|
||||
}
|
||||
|
||||
exists, _, err := db.HasBlockBySlot(blkSlot)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get block: %v", err)
|
||||
}
|
||||
if exists {
|
||||
t.Error("Block exists despite being not being saved")
|
||||
}
|
||||
|
||||
if err := db.SaveBlock(block1); err != nil {
|
||||
t.Fatalf("save block failed: %v", err)
|
||||
}
|
||||
|
||||
if err := db.UpdateChainHead(ctx, block1, &pb.BeaconState{}); err != nil {
|
||||
t.Fatalf("Unable to save block and state in db %v", err)
|
||||
}
|
||||
|
||||
exists, blk, err := db.HasBlockBySlot(blkSlot)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get block: %v", err)
|
||||
}
|
||||
if !exists {
|
||||
t.Error("Block does not exist in db")
|
||||
}
|
||||
|
||||
if blk.Slot != blkSlot {
|
||||
t.Errorf("Saved block does not have the slot from which it was requested")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestJustifiedBlock_NoneExists(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer teardownDB(t, db)
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@@ -318,19 +316,6 @@ func createState(enc []byte) (*pb.BeaconState, error) {
|
||||
return protoState, nil
|
||||
}
|
||||
|
||||
// GenesisTime returns the genesis timestamp for the state.
|
||||
func (db *BeaconDB) GenesisTime(ctx context.Context) (time.Time, error) {
|
||||
state, err := db.HeadState(ctx)
|
||||
if err != nil {
|
||||
return time.Time{}, fmt.Errorf("could not retrieve state: %v", err)
|
||||
}
|
||||
if state == nil {
|
||||
return time.Time{}, fmt.Errorf("state not found: %v", err)
|
||||
}
|
||||
genesisTime := time.Unix(int64(state.GenesisTime), int64(0))
|
||||
return genesisTime, nil
|
||||
}
|
||||
|
||||
func (db *BeaconDB) deleteHistoricalStates(slot uint64) error {
|
||||
if !featureconfig.FeatureConfig().EnableHistoricalStatePruning {
|
||||
return nil
|
||||
|
||||
@@ -88,35 +88,6 @@ func TestInitializeState_OK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenesisTime_OK(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
genesisTime, err := db.GenesisTime(ctx)
|
||||
if err == nil {
|
||||
t.Fatal("Expected GenesisTime to fail")
|
||||
}
|
||||
|
||||
deposits, _ := setupInitialDeposits(t, 10)
|
||||
if err := db.InitializeState(uint64(genesisTime.Unix()), deposits, &pb.Eth1Data{}); err != nil {
|
||||
t.Fatalf("Failed to initialize state: %v", err)
|
||||
}
|
||||
|
||||
time1, err := db.GenesisTime(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("GenesisTime failed on second attempt: %v", err)
|
||||
}
|
||||
time2, err := db.GenesisTime(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("GenesisTime failed on second attempt: %v", err)
|
||||
}
|
||||
|
||||
if time1 != time2 {
|
||||
t.Fatalf("Expected %v and %v to be equal", time1, time2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFinalizeState_OK(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer teardownDB(t, db)
|
||||
|
||||
Reference in New Issue
Block a user