Skip to content

Commit

Permalink
Rename Shard Block Root to Crosslink Data Root (#1743)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Feb 27, 2019
1 parent 5ab3478 commit 9f95021
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 242 deletions.
8 changes: 4 additions & 4 deletions beacon-chain/core/blocks/block_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ func verifyAttestation(beaconState *pb.BeaconState, att *pb.Attestation, verifyS
// equals state.latest_crosslinks[attestation.data.shard]
shard := att.Data.Shard
crosslink := &pb.Crosslink{
ShardBlockRootHash32: att.Data.ShardBlockRootHash32,
Epoch: helpers.SlotToEpoch(att.Data.Slot),
CrosslinkDataRootHash32: att.Data.CrosslinkDataRootHash32,
Epoch: helpers.SlotToEpoch(att.Data.Slot),
}
crosslinkFromAttestation := att.Data.LatestCrosslink
crosslinkFromState := beaconState.LatestCrosslinks[shard]
Expand All @@ -499,11 +499,11 @@ func verifyAttestation(beaconState *pb.BeaconState, att *pb.Attestation, verifyS
}

// Verify attestation.shard_block_root == ZERO_HASH [TO BE REMOVED IN PHASE 1].
if !bytes.Equal(att.Data.ShardBlockRootHash32, params.BeaconConfig().ZeroHash[:]) {
if !bytes.Equal(att.Data.CrosslinkDataRootHash32, params.BeaconConfig().ZeroHash[:]) {
return fmt.Errorf(
"expected attestation.ShardBlockRoot == %#x, received %#x instead",
params.BeaconConfig().ZeroHash[:],
att.Data.ShardBlockRootHash32,
att.Data.CrosslinkDataRootHash32,
)
}
if verifySignatures {
Expand Down
18 changes: 9 additions & 9 deletions beacon-chain/core/blocks/block_operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ func TestProcessBlockAttestations_CrosslinkRootFailure(t *testing.T) {
// the attestation should be invalid.
stateLatestCrosslinks := []*pb.Crosslink{
{
ShardBlockRootHash32: []byte{1},
CrosslinkDataRootHash32: []byte{1},
},
}
state := &pb.BeaconState{
Expand All @@ -922,8 +922,8 @@ func TestProcessBlockAttestations_CrosslinkRootFailure(t *testing.T) {
Shard: 0,
Slot: params.BeaconConfig().GenesisSlot + 20,
JustifiedBlockRootHash32: blockRoots[0],
LatestCrosslink: &pb.Crosslink{ShardBlockRootHash32: []byte{2}},
ShardBlockRootHash32: params.BeaconConfig().ZeroHash[:],
LatestCrosslink: &pb.Crosslink{CrosslinkDataRootHash32: []byte{2}},
CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:],
JustifiedEpoch: params.BeaconConfig().GenesisEpoch,
},
},
Expand Down Expand Up @@ -953,7 +953,7 @@ func TestProcessBlockAttestations_ShardBlockRootEqualZeroHashFailure(t *testing.
}
stateLatestCrosslinks := []*pb.Crosslink{
{
ShardBlockRootHash32: []byte{1},
CrosslinkDataRootHash32: []byte{1},
},
}
state := &pb.BeaconState{
Expand All @@ -968,8 +968,8 @@ func TestProcessBlockAttestations_ShardBlockRootEqualZeroHashFailure(t *testing.
Shard: 0,
Slot: params.BeaconConfig().GenesisSlot + 20,
JustifiedBlockRootHash32: blockRoots[0],
LatestCrosslink: &pb.Crosslink{ShardBlockRootHash32: []byte{1}},
ShardBlockRootHash32: []byte{1},
LatestCrosslink: &pb.Crosslink{CrosslinkDataRootHash32: []byte{1}},
CrosslinkDataRootHash32: []byte{1},
JustifiedEpoch: params.BeaconConfig().GenesisEpoch,
},
},
Expand Down Expand Up @@ -1000,7 +1000,7 @@ func TestProcessBlockAttestations_CreatePendingAttestations(t *testing.T) {
}
stateLatestCrosslinks := []*pb.Crosslink{
{
ShardBlockRootHash32: []byte{1},
CrosslinkDataRootHash32: []byte{1},
},
}
state := &pb.BeaconState{
Expand All @@ -1014,8 +1014,8 @@ func TestProcessBlockAttestations_CreatePendingAttestations(t *testing.T) {
Shard: 0,
Slot: params.BeaconConfig().GenesisSlot + 20,
JustifiedBlockRootHash32: blockRoots[0],
LatestCrosslink: &pb.Crosslink{ShardBlockRootHash32: []byte{1}},
ShardBlockRootHash32: params.BeaconConfig().ZeroHash[:],
LatestCrosslink: &pb.Crosslink{CrosslinkDataRootHash32: []byte{1}},
CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:],
JustifiedEpoch: params.BeaconConfig().GenesisEpoch,
},
AggregationBitfield: []byte{1},
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/epoch/epoch_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func winningRoot(

for _, attestation := range attestations {
if attestation.Data.Shard == shard {
candidateRoots = append(candidateRoots, attestation.Data.ShardBlockRootHash32)
candidateRoots = append(candidateRoots, attestation.Data.CrosslinkDataRootHash32)
}
}

Expand Down
24 changes: 12 additions & 12 deletions beacon-chain/core/epoch/epoch_operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ func TestWinningRoot_AccurateRoot(t *testing.T) {
for i := 0; i < 10; i++ {
attestation := &pb.PendingAttestation{
Data: &pb.AttestationData{
Slot: params.BeaconConfig().GenesisSlot,
ShardBlockRootHash32: []byte{byte(i + 100)},
Slot: params.BeaconConfig().GenesisSlot,
CrosslinkDataRootHash32: []byte{byte(i + 100)},
},
AggregationBitfield: participationBitfield,
}
Expand All @@ -379,8 +379,8 @@ func TestWinningRoot_EmptyParticipantBitfield(t *testing.T) {

attestations := []*pb.PendingAttestation{
{Data: &pb.AttestationData{
Slot: params.BeaconConfig().GenesisSlot,
ShardBlockRootHash32: []byte{},
Slot: params.BeaconConfig().GenesisSlot,
CrosslinkDataRootHash32: []byte{},
},
AggregationBitfield: []byte{},
},
Expand All @@ -399,8 +399,8 @@ func TestAttestingValidators_MatchActive(t *testing.T) {
for i := 0; i < 10; i++ {
attestation := &pb.PendingAttestation{
Data: &pb.AttestationData{
Slot: params.BeaconConfig().GenesisSlot,
ShardBlockRootHash32: []byte{byte(i + 100)},
Slot: params.BeaconConfig().GenesisSlot,
CrosslinkDataRootHash32: []byte{byte(i + 100)},
},
AggregationBitfield: []byte{0x03},
}
Expand All @@ -427,8 +427,8 @@ func TestAttestingValidators_EmptyWinningRoot(t *testing.T) {

attestation := &pb.PendingAttestation{
Data: &pb.AttestationData{
Slot: params.BeaconConfig().GenesisSlot,
ShardBlockRootHash32: []byte{},
Slot: params.BeaconConfig().GenesisSlot,
CrosslinkDataRootHash32: []byte{},
},
AggregationBitfield: []byte{},
}
Expand All @@ -448,8 +448,8 @@ func TestTotalAttestingBalance_CorrectBalance(t *testing.T) {
for i := 0; i < 10; i++ {
attestation := &pb.PendingAttestation{
Data: &pb.AttestationData{
Slot: params.BeaconConfig().GenesisSlot,
ShardBlockRootHash32: []byte{byte(i + 100)},
Slot: params.BeaconConfig().GenesisSlot,
CrosslinkDataRootHash32: []byte{byte(i + 100)},
},
// All validators attested to the above roots.
AggregationBitfield: []byte{0x03},
Expand All @@ -476,8 +476,8 @@ func TestTotalAttestingBalance_EmptyWinningRoot(t *testing.T) {

attestation := &pb.PendingAttestation{
Data: &pb.AttestationData{
Slot: params.BeaconConfig().GenesisSlot,
ShardBlockRootHash32: []byte{},
Slot: params.BeaconConfig().GenesisSlot,
CrosslinkDataRootHash32: []byte{},
},
AggregationBitfield: []byte{},
}
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/core/epoch/epoch_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ func ProcessCrosslinks(
return nil, fmt.Errorf("could not get winning root: %v", err)
}
state.LatestCrosslinks[shard] = &pb.Crosslink{
Epoch: currentEpoch,
ShardBlockRootHash32: winningRoot,
Epoch: currentEpoch,
CrosslinkDataRootHash32: winningRoot,
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions beacon-chain/core/epoch/epoch_processing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ func TestProcessCrosslinks_CrosslinksCorrectEpoch(t *testing.T) {
for i := 0; i < 10; i++ {
attestation := &pb.PendingAttestation{
Data: &pb.AttestationData{
Slot: state.Slot,
ShardBlockRootHash32: []byte{'A'},
Slot: state.Slot,
CrosslinkDataRootHash32: []byte{'A'},
},
// All validators attested to the above roots.
AggregationBitfield: participationBitfield,
Expand All @@ -279,11 +279,11 @@ func TestProcessCrosslinks_CrosslinksCorrectEpoch(t *testing.T) {
newState.LatestCrosslinks[0].Epoch, +params.BeaconConfig().GenesisSlot)
}
// Verify crosslink for shard 0 was root hashed for []byte{'A'}.
if !bytes.Equal(newState.LatestCrosslinks[0].ShardBlockRootHash32,
attestations[0].Data.ShardBlockRootHash32) {
if !bytes.Equal(newState.LatestCrosslinks[0].CrosslinkDataRootHash32,
attestations[0].Data.CrosslinkDataRootHash32) {
t.Errorf("Shard 0's root hash is %#x, wanted: %#x",
newState.LatestCrosslinks[0].ShardBlockRootHash32,
attestations[0].Data.ShardBlockRootHash32)
newState.LatestCrosslinks[0].CrosslinkDataRootHash32,
attestations[0].Data.CrosslinkDataRootHash32)
}
}

Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/core/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func GenesisBeaconState(
latestCrosslinks := make([]*pb.Crosslink, params.BeaconConfig().ShardCount)
for i := 0; i < len(latestCrosslinks); i++ {
latestCrosslinks[i] = &pb.Crosslink{
Epoch: params.BeaconConfig().GenesisEpoch,
ShardBlockRootHash32: zeroHash,
Epoch: params.BeaconConfig().GenesisEpoch,
CrosslinkDataRootHash32: zeroHash,
}
}

Expand Down
12 changes: 6 additions & 6 deletions beacon-chain/core/state/transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
beaconState.LatestBlockRootHash32S = blockRoots
beaconState.LatestCrosslinks = []*pb.Crosslink{
{
ShardBlockRootHash32: []byte{1},
CrosslinkDataRootHash32: []byte{1},
},
}
beaconState.Slot = params.BeaconConfig().GenesisSlot + 10
Expand All @@ -271,8 +271,8 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
Slot: params.BeaconConfig().GenesisSlot,
JustifiedEpoch: params.BeaconConfig().GenesisEpoch,
JustifiedBlockRootHash32: blockRoots[0],
LatestCrosslink: &pb.Crosslink{ShardBlockRootHash32: []byte{1}},
ShardBlockRootHash32: params.BeaconConfig().ZeroHash[:],
LatestCrosslink: &pb.Crosslink{CrosslinkDataRootHash32: []byte{1}},
CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:],
},
AggregationBitfield: []byte{1},
CustodyBitfield: []byte{1},
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
beaconState.LatestBlockRootHash32S = blockRoots
beaconState.LatestCrosslinks = []*pb.Crosslink{
{
ShardBlockRootHash32: []byte{1},
CrosslinkDataRootHash32: []byte{1},
},
}
beaconState.Slot = params.BeaconConfig().GenesisSlot + 10
Expand All @@ -363,8 +363,8 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
Slot: params.BeaconConfig().GenesisSlot,
JustifiedEpoch: params.BeaconConfig().GenesisEpoch,
JustifiedBlockRootHash32: blockRoots[0],
LatestCrosslink: &pb.Crosslink{ShardBlockRootHash32: []byte{1}},
ShardBlockRootHash32: params.BeaconConfig().ZeroHash[:],
LatestCrosslink: &pb.Crosslink{CrosslinkDataRootHash32: []byte{1}},
CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:],
},
AggregationBitfield: []byte{1},
CustodyBitfield: []byte{1},
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/core/validators/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func ValidatorIndices(
func AttestingValidatorIndices(
state *pb.BeaconState,
shard uint64,
shardBlockRoot []byte,
crosslinkDataRoot []byte,
thisEpochAttestations []*pb.PendingAttestation,
prevEpochAttestations []*pb.PendingAttestation) ([]uint64, error) {

Expand All @@ -64,7 +64,7 @@ func AttestingValidatorIndices(

for _, attestation := range attestations {
if attestation.Data.Shard == shard &&
bytes.Equal(attestation.Data.ShardBlockRootHash32, shardBlockRoot) {
bytes.Equal(attestation.Data.CrosslinkDataRootHash32, crosslinkDataRoot) {

validatorIndicesCommittee, err := helpers.AttestationParticipants(state, attestation.Data, attestation.AggregationBitfield)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions beacon-chain/core/validators/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ func TestAttestingValidatorIndices_OK(t *testing.T) {

prevAttestation := &pb.PendingAttestation{
Data: &pb.AttestationData{
Slot: params.BeaconConfig().GenesisSlot + 3,
Shard: 6,
ShardBlockRootHash32: []byte{'B'},
Slot: params.BeaconConfig().GenesisSlot + 3,
Shard: 6,
CrosslinkDataRootHash32: []byte{'B'},
},
AggregationBitfield: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
}
Expand Down Expand Up @@ -139,9 +139,9 @@ func TestAttestingValidatorIndices_OutOfBound(t *testing.T) {

attestation := &pb.PendingAttestation{
Data: &pb.AttestationData{
Slot: 0,
Shard: 1,
ShardBlockRootHash32: []byte{'B'},
Slot: 0,
Shard: 1,
CrosslinkDataRootHash32: []byte{'B'},
},
AggregationBitfield: []byte{'A'}, // 01000001 = 1,7
}
Expand Down
10 changes: 5 additions & 5 deletions beacon-chain/rpc/attester_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func TestAttestHead_OK(t *testing.T) {
}
req := &pbp2p.Attestation{
Data: &pbp2p.AttestationData{
Slot: 999,
Shard: 1,
ShardBlockRootHash32: []byte{'a'},
Slot: 999,
Shard: 1,
CrosslinkDataRootHash32: []byte{'a'},
},
}
if _, err := attesterServer.AttestHead(context.Background(), req); err != nil {
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestAttestationDataAtSlot_OK(t *testing.T) {
LatestBlockRootHash32S: make([][]byte, params.BeaconConfig().LatestBlockRootsLength),
LatestCrosslinks: []*pbp2p.Crosslink{
{
ShardBlockRootHash32: []byte("A"),
CrosslinkDataRootHash32: []byte("A"),
},
},
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestAttestationDataAtSlot_OK(t *testing.T) {
JustifiedEpoch: 2 + params.BeaconConfig().GenesisEpoch,
JustifiedBlockRootHash32: justifiedBlockRoot[:],
LatestCrosslink: &pbp2p.Crosslink{
ShardBlockRootHash32: []byte("A"),
CrosslinkDataRootHash32: []byte("A"),
},
}

Expand Down
14 changes: 7 additions & 7 deletions beacon-chain/sync/regular_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ func TestProcessBlock_OK(t *testing.T) {
}
attestation := &pb.Attestation{
Data: &pb.AttestationData{
Slot: 0,
Shard: 0,
ShardBlockRootHash32: []byte{'A'},
Slot: 0,
Shard: 0,
CrosslinkDataRootHash32: []byte{'A'},
},
}

Expand Down Expand Up @@ -261,8 +261,8 @@ func TestProcessBlock_MultipleBlocks(t *testing.T) {
Block: data1,
Attestation: &pb.Attestation{
Data: &pb.AttestationData{
ShardBlockRootHash32: []byte{},
Slot: params.BeaconConfig().GenesisSlot,
CrosslinkDataRootHash32: []byte{},
Slot: params.BeaconConfig().GenesisSlot,
},
},
}
Expand All @@ -286,8 +286,8 @@ func TestProcessBlock_MultipleBlocks(t *testing.T) {
Block: data2,
Attestation: &pb.Attestation{
Data: &pb.AttestationData{
ShardBlockRootHash32: []byte{},
Slot: 0,
CrosslinkDataRootHash32: []byte{},
Slot: 0,
},
},
}
Expand Down
Loading

0 comments on commit 9f95021

Please sign in to comment.