Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated fields from attestation data #2892

Merged
merged 5 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion beacon-chain/attestation/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (a *Service) updateAttestation(beaconState *pb.BeaconState, attestation *pb
log.WithFields(
logrus.Fields{
"attestationSlot": slot,
"sourceEpoch": attestation.Data.SourceEpoch,
"sourceEpoch": attestation.Data.Source.Epoch,
},
).Debug("Attestation store updated")

Expand Down
9 changes: 8 additions & 1 deletion beacon-chain/attestation/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func TestUpdateLatestAttestation_UpdatesLatest(t *testing.T) {
Crosslink: &pb.Crosslink{
Shard: 1,
},
Target: &pb.Checkpoint{},
Source: &pb.Checkpoint{},
},
}

Expand Down Expand Up @@ -248,6 +250,8 @@ func TestUpdateLatestAttestation_InvalidIndex(t *testing.T) {
Crosslink: &pb.Crosslink{
Shard: 1,
},
Target: &pb.Checkpoint{},
Source: &pb.Checkpoint{},
},
}

Expand Down Expand Up @@ -299,7 +303,8 @@ func TestBatchUpdate_FromSync(t *testing.T) {
attestation := &pb.Attestation{
AggregationBits: []byte{0x80},
Data: &pb.AttestationData{
TargetEpoch: 2,
Target: &pb.Checkpoint{Epoch: 2},
Source: &pb.Checkpoint{},
Crosslink: &pb.Crosslink{
Shard: 1,
},
Expand Down Expand Up @@ -352,6 +357,8 @@ func TestUpdateLatestAttestation_BatchUpdate(t *testing.T) {
Crosslink: &pb.Crosslink{
Shard: 1,
},
Target: &pb.Checkpoint{},
Source: &pb.Checkpoint{},
},
})
}
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/blockchain/block_processing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func TestReceiveBlock_DeletesBadBlock(t *testing.T) {
RandaoReveal: []byte{},
Attestations: []*pb.Attestation{{
Data: &pb.AttestationData{
TargetEpoch: 5,
Target: &pb.Checkpoint{Epoch: 5},
},
}},
},
Expand Down Expand Up @@ -895,7 +895,7 @@ func TestIsBlockReadyForProcessing_ValidBlock(t *testing.T) {
AggregationBits: []byte{128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Data: &pb.AttestationData{
SourceRoot: parentRoot[:],
Source: &pb.Checkpoint{Root: parentRoot[:]},
Crosslink: &pb.Crosslink{
Shard: 960,
},
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/cache/attestation_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestAttestationCache_RoundTrip(t *testing.T) {
}

res := &pbp2p.AttestationData{
TargetEpoch: 5,
Target: &pbp2p.Checkpoint{Epoch: 5},
}

if err = c.Put(ctx, req, res); err != nil {
Expand Down
26 changes: 13 additions & 13 deletions beacon-chain/core/blocks/block_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ func verifyAttesterSlashing(slashing *pb.AttesterSlashing, verifySignatures bool
// (data_1.source.epoch < data_2.source.epoch and data_2.target.epoch < data_1.target.epoch)
// )
func IsSlashableAttestationData(data1 *pb.AttestationData, data2 *pb.AttestationData) bool {
isDoubleVote := !proto.Equal(data1, data2) && data1.TargetEpoch == data2.TargetEpoch
isSurroundVote := data1.SourceEpoch < data2.SourceEpoch && data2.TargetEpoch < data1.TargetEpoch
isDoubleVote := !proto.Equal(data1, data2) && data1.Target.Epoch == data2.Target.Epoch
isSurroundVote := data1.Source.Epoch < data2.Source.Epoch && data2.Target.Epoch < data1.Target.Epoch
return isDoubleVote || isSurroundVote
}

Expand Down Expand Up @@ -471,10 +471,10 @@ func ProcessAttestation(beaconState *pb.BeaconState, att *pb.Attestation, verify
ProposerIndex: proposerIndex,
}

if !(data.TargetEpoch == helpers.PrevEpoch(beaconState) || data.TargetEpoch == helpers.CurrentEpoch(beaconState)) {
if !(data.Target.Epoch == helpers.PrevEpoch(beaconState) || data.Target.Epoch == helpers.CurrentEpoch(beaconState)) {
return nil, fmt.Errorf(
"expected target epoch %d == %d or %d",
data.TargetEpoch,
data.Target.Epoch,
helpers.PrevEpoch(beaconState),
helpers.CurrentEpoch(beaconState),
)
Expand All @@ -484,7 +484,7 @@ func ProcessAttestation(beaconState *pb.BeaconState, att *pb.Attestation, verify
var ffgSourceRoot []byte
var ffgTargetEpoch uint64
var parentCrosslink *pb.Crosslink
if data.TargetEpoch == helpers.CurrentEpoch(beaconState) {
if data.Target.Epoch == helpers.CurrentEpoch(beaconState) {
ffgSourceEpoch = beaconState.CurrentJustifiedCheckpoint.Epoch
ffgSourceRoot = beaconState.CurrentJustifiedCheckpoint.Root
ffgTargetEpoch = helpers.CurrentEpoch(beaconState)
Expand All @@ -497,18 +497,18 @@ func ProcessAttestation(beaconState *pb.BeaconState, att *pb.Attestation, verify
parentCrosslink = beaconState.PreviousCrosslinks[data.Crosslink.Shard]
beaconState.PreviousEpochAttestations = append(beaconState.PreviousEpochAttestations, pendingAtt)
}
if data.SourceEpoch != ffgSourceEpoch {
return nil, fmt.Errorf("expected source epoch %d, received %d", ffgSourceEpoch, data.SourceEpoch)
if data.Source.Epoch != ffgSourceEpoch {
return nil, fmt.Errorf("expected source epoch %d, received %d", ffgSourceEpoch, data.Source.Epoch)
}
if !bytes.Equal(data.SourceRoot, ffgSourceRoot) {
return nil, fmt.Errorf("expected source root %#x, received %#x", ffgSourceRoot, data.SourceRoot)
if !bytes.Equal(data.Source.Root, ffgSourceRoot) {
return nil, fmt.Errorf("expected source root %#x, received %#x", ffgSourceRoot, data.Source.Root)
}
if data.TargetEpoch != ffgTargetEpoch {
return nil, fmt.Errorf("expected target epoch %d, received %d", ffgTargetEpoch, data.TargetEpoch)
if data.Target.Epoch != ffgTargetEpoch {
return nil, fmt.Errorf("expected target epoch %d, received %d", ffgTargetEpoch, data.Target.Epoch)
}
endEpoch := parentCrosslink.EndEpoch + params.BeaconConfig().MaxEpochsPerCrosslink
if data.TargetEpoch < endEpoch {
endEpoch = data.TargetEpoch
if data.Target.Epoch < endEpoch {
endEpoch = data.Target.Epoch
}
if data.Crosslink.StartEpoch != parentCrosslink.EndEpoch {
return nil, fmt.Errorf("expected crosslink start epoch %d, received %d",
Expand Down
Loading