Skip to content

Commit

Permalink
squash commits
Browse files Browse the repository at this point in the history
 fix tests and getter implementations
 remove usage of CopySignedBeaconBlock from ReceiveBlockNoVerify
  • Loading branch information
garyschulteog committed Feb 12, 2020
1 parent f6d5ef8 commit 974e369
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 189 deletions.
1 change: 1 addition & 0 deletions beacon-chain/blockchain/BUILD.bazel
Expand Up @@ -46,6 +46,7 @@ go_library(
"//shared/traceutil:go_default_library",
"@com_github_emicklei_dot//:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
Expand Down
16 changes: 8 additions & 8 deletions beacon-chain/blockchain/process_attestation_test.go
Expand Up @@ -155,12 +155,12 @@ func TestStore_SaveCheckpointState(t *testing.T) {
if err := service.beaconDB.SaveState(ctx, s, r); err != nil {
t.Fatal(err)
}
service.justifiedCheckpt = stateTrie.CopyCheckpoint(&ethpb.Checkpoint{Root: r[:]})
service.bestJustifiedCheckpt = stateTrie.CopyCheckpoint(&ethpb.Checkpoint{Root: r[:]})
service.finalizedCheckpt = stateTrie.CopyCheckpoint(&ethpb.Checkpoint{Root: r[:]})
service.prevFinalizedCheckpt = stateTrie.CopyCheckpoint(&ethpb.Checkpoint{Root: r[:]})
service.justifiedCheckpt = &ethpb.Checkpoint{Root: r[:]}
service.bestJustifiedCheckpt = &ethpb.Checkpoint{Root: r[:]}
service.finalizedCheckpt = &ethpb.Checkpoint{Root: r[:]}
service.prevFinalizedCheckpt = &ethpb.Checkpoint{Root: r[:]}

cp1 := stateTrie.CopyCheckpoint(&ethpb.Checkpoint{Epoch: 1, Root: []byte{'A'}})
cp1 := &ethpb.Checkpoint{Epoch: 1, Root: []byte{'A'}}
service.beaconDB.SaveState(ctx, s, bytesutil.ToBytes32([]byte{'A'}))
s1, err := service.getAttPreState(ctx, cp1)
if err != nil {
Expand All @@ -170,7 +170,7 @@ func TestStore_SaveCheckpointState(t *testing.T) {
t.Errorf("Wanted state slot: %d, got: %d", 1*params.BeaconConfig().SlotsPerEpoch, s1.Slot())
}

cp2 := stateTrie.CopyCheckpoint(&ethpb.Checkpoint{Epoch: 2, Root: []byte{'B'}})
cp2 := &ethpb.Checkpoint{Epoch: 2, Root: []byte{'B'}}
service.beaconDB.SaveState(ctx, s, bytesutil.ToBytes32([]byte{'B'}))
s2, err := service.getAttPreState(ctx, cp2)
if err != nil {
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestStore_UpdateCheckpointState(t *testing.T) {
epoch := uint64(1)
baseState, _ := testutil.DeterministicGenesisState(t, 1)
baseState.SetSlot(epoch * params.BeaconConfig().SlotsPerEpoch)
checkpoint := stateTrie.CopyCheckpoint(&ethpb.Checkpoint{Epoch: epoch})
checkpoint := &ethpb.Checkpoint{Epoch: epoch}
service.beaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(checkpoint.Root))
returned, err := service.getAttPreState(ctx, checkpoint)
if err != nil {
Expand All @@ -253,7 +253,7 @@ func TestStore_UpdateCheckpointState(t *testing.T) {
}

epoch = uint64(2)
newCheckpoint := stateTrie.CopyCheckpoint(&ethpb.Checkpoint{Epoch: epoch})
newCheckpoint := &ethpb.Checkpoint{Epoch: epoch}
service.beaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(newCheckpoint.Root))
returned, err = service.getAttPreState(ctx, newCheckpoint)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion beacon-chain/blockchain/receive_block.go
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/hex"
"github.com/golang/protobuf/proto"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"

"github.com/pkg/errors"
Expand Down Expand Up @@ -183,7 +184,7 @@ func (s *Service) ReceiveBlockNoPubsubForkchoice(ctx context.Context, block *eth
func (s *Service) ReceiveBlockNoVerify(ctx context.Context, block *ethpb.SignedBeaconBlock) error {
ctx, span := trace.StartSpan(ctx, "beacon-chain.blockchain.ReceiveBlockNoVerify")
defer span.End()
blockCopy := stateTrie.CopySignedBeaconBlock(block)
blockCopy := proto.Clone(block).(*ethpb.SignedBeaconBlock) //stateTrie.CopySignedBeaconBlock(block)

// Apply state transition on the incoming newly received blockCopy without verifying its BLS contents.
if err := s.onBlockInitialSyncStateTransition(ctx, blockCopy); err != nil {
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/cache/BUILD.bazel
Expand Up @@ -18,7 +18,6 @@ go_library(
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"//shared/sliceutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_hashicorp_golang_lru//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/cache/checkpoint_state_test.go
Expand Up @@ -45,7 +45,7 @@ func TestCheckpointStateCacheKeyFn_InvalidObj(t *testing.T) {
func TestCheckpointStateCache_StateByCheckpoint(t *testing.T) {
cache := NewCheckpointStateCache()

cp1 := stateTrie.CopyCheckpoint(&ethpb.Checkpoint{Epoch: 1, Root: []byte{'A'}})
cp1 := &ethpb.Checkpoint{Epoch: 1, Root: []byte{'A'}}
st, err := stateTrie.InitializeFromProto(&pb.BeaconState{
Slot: 64,
})
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestCheckpointStateCache_StateByCheckpoint(t *testing.T) {
t.Error("incorrectly cached state")
}

cp2 := stateTrie.CopyCheckpoint(&ethpb.Checkpoint{Epoch: 2, Root: []byte{'B'}})
cp2 := &ethpb.Checkpoint{Epoch: 2, Root: []byte{'B'}}
st2, err := stateTrie.InitializeFromProto(&pb.BeaconState{
Slot: 128,
})
Expand Down
18 changes: 9 additions & 9 deletions beacon-chain/core/helpers/attestation_test.go
Expand Up @@ -23,15 +23,15 @@ func TestAggregateAttestation(t *testing.T) {
a2 *ethpb.Attestation
want *ethpb.Attestation
}{
{a1: beaconstate.CopyAttestation(&ethpb.Attestation{AggregationBits: []byte{}}),
a2: beaconstate.CopyAttestation(&ethpb.Attestation{AggregationBits: []byte{}}),
want: beaconstate.CopyAttestation(&ethpb.Attestation{AggregationBits: []byte{}})},
{a1: beaconstate.CopyAttestation(&ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x03}}),
a2: beaconstate.CopyAttestation(&ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x02}}),
want: beaconstate.CopyAttestation(&ethpb.Attestation{AggregationBits: []byte{0x03}})},
{a1: beaconstate.CopyAttestation(&ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x02}}),
a2: beaconstate.CopyAttestation(&ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x03}}),
want: beaconstate.CopyAttestation(&ethpb.Attestation{AggregationBits: []byte{0x03}})},
{a1: &ethpb.Attestation{AggregationBits: []byte{}},
a2: &ethpb.Attestation{AggregationBits: []byte{}},
want: &ethpb.Attestation{AggregationBits: []byte{}}},
{a1: &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x03}},
a2: &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x02}},
want: &ethpb.Attestation{AggregationBits: []byte{0x03}}},
{a1: &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x02}},
a2: &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x03}},
want: &ethpb.Attestation{AggregationBits: []byte{0x03}}},
}
for _, tt := range tests {
got, err := helpers.AggregateAttestation(tt.a1, tt.a2)
Expand Down
Expand Up @@ -138,8 +138,6 @@ func TestBatchAttestations_Single(t *testing.T) {
sig := sk.Sign([]byte("dummy_test_data"), 0 /*domain*/)
mockRoot := [32]byte{}
d := &ethpb.AttestationData{
Slot: 0,
CommitteeIndex: 0,
BeaconBlockRoot: mockRoot[:],
Source: &ethpb.Checkpoint{Root: mockRoot[:]},
Target: &ethpb.Checkpoint{Root: mockRoot[:]},
Expand Down Expand Up @@ -185,7 +183,7 @@ func TestBatchAttestations_Single(t *testing.T) {
}

if !reflect.DeepEqual(wanted, s.pool.ForkchoiceAttestations()) {
t.Error("Did not aggregation and save for batch")
t.Error("Did not aggregate and save for batch")
}
}

Expand Down
14 changes: 13 additions & 1 deletion beacon-chain/p2p/peers/status_test.go
Expand Up @@ -341,31 +341,43 @@ func TestTrimmedOrderedPeers(t *testing.T) {

expectedTarget := uint64(2)
maxPeers := 3

mockroot2 := [32]byte{}
mockroot3 := [32]byte{}
mockroot4 := [32]byte{}
mockroot5 := [32]byte{}
copy(mockroot2[:], "two")
copy(mockroot3[:], "three")
copy(mockroot4[:], "four")
copy(mockroot5[:], "five")
// Peer 1
pid1 := addPeer(t, p, peers.PeerConnected)
p.SetChainState(pid1, &pb.Status{
FinalizedEpoch: 3,
FinalizedRoot: mockroot3[:],
})
// Peer 2
pid2 := addPeer(t, p, peers.PeerConnected)
p.SetChainState(pid2, &pb.Status{
FinalizedEpoch: 4,
FinalizedRoot: mockroot4[:],
})
// Peer 3
pid3 := addPeer(t, p, peers.PeerConnected)
p.SetChainState(pid3, &pb.Status{
FinalizedEpoch: 5,
FinalizedRoot: mockroot5[:],
})
// Peer 4
pid4 := addPeer(t, p, peers.PeerConnected)
p.SetChainState(pid4, &pb.Status{
FinalizedEpoch: 2,
FinalizedRoot: mockroot2[:],
})
// Peer 5
pid5 := addPeer(t, p, peers.PeerConnected)
p.SetChainState(pid5, &pb.Status{
FinalizedEpoch: 2,
FinalizedRoot: mockroot2[:],
})

_, target, pids := p.BestFinalized(maxPeers, 0)
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/rpc/validator/BUILD.bazel
Expand Up @@ -42,7 +42,6 @@ go_library(
"//shared/slotutil:go_default_library",
"//shared/traceutil:go_default_library",
"//shared/trieutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_gogo_protobuf//types:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
Expand Down

0 comments on commit 974e369

Please sign in to comment.