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 shards and committees #3896

Merged
merged 49 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
ad7c4e8
rm'ed in protobuf
terencechain Oct 28, 2019
6eafe7e
build proto
terencechain Oct 28, 2019
13e05c3
build proto
terencechain Oct 28, 2019
5fadaa9
build proto
terencechain Oct 28, 2019
90c69e7
fix core package
terencechain Oct 28, 2019
10ef95e
Gazelle
terencechain Oct 28, 2019
51729f7
Fixed all the tests
terencechain Oct 28, 2019
c80c822
Fixed static test
terencechain Oct 28, 2019
0008f7e
Comment out spec test for now
terencechain Oct 28, 2019
edbffe6
One more skip
terencechain Oct 28, 2019
094f197
fix-roundRobinSync (#3862)
skillful-alex Oct 28, 2019
297da47
Starting but need new seed function
terencechain Oct 28, 2019
4fec429
Sync with 0.9
terencechain Oct 29, 2019
908cc4d
Revert initial sync
terencechain Oct 29, 2019
b56c0a6
Updated Proposer Slashing
terencechain Oct 29, 2019
b2a6152
Fixed all tests
terencechain Oct 29, 2019
1c319bc
Lint
terencechain Oct 29, 2019
92779ee
Update inclusion reward
terencechain Oct 29, 2019
5161ff1
Fill randao mixes with eth1 data hash
terencechain Oct 29, 2019
51accdf
Test
terencechain Oct 29, 2019
9526dd8
Fixing test part1
terencechain Oct 29, 2019
75ad52a
All tests passing
terencechain Oct 29, 2019
f7ffde9
One last test
terencechain Oct 29, 2019
1ba7733
Updated config
terencechain Oct 29, 2019
98766cc
Build proto
terencechain Oct 29, 2019
2939a1e
Merge branch 'v0.9' of https://github.com/prysmaticlabs/prysm into ro…
terencechain Oct 29, 2019
0519929
Proper skip message
terencechain Oct 29, 2019
8936023
Conflict and fmt
terencechain Oct 29, 2019
02f0165
Merge with roots removal
terencechain Oct 29, 2019
76c5a82
Merge branch 'proposer-fix' into rm-shards-crosslinks-1
terencechain Oct 29, 2019
c3e7a08
Merge branch 'fix-inclusion-reward' into rm-shards-crosslinks-1
terencechain Oct 29, 2019
48992e0
Merge branch 'early-committee-bias' into rm-shards-crosslinks-1
terencechain Oct 29, 2019
7686280
Removed crosslinks and shards. Built
terencechain Oct 30, 2019
6773b52
Format and gazelle
terencechain Oct 30, 2019
8632f36
Fixed all the block package tests
terencechain Oct 30, 2019
0ba13d0
Fixed all the helper tests
terencechain Oct 30, 2019
a0fba37
All epoch package tests pass
terencechain Oct 30, 2019
a203ca3
All core package tests pass
terencechain Oct 30, 2019
871c2f4
Fixed operation tests
terencechain Oct 30, 2019
5e4faf5
Started fixing rpc test
terencechain Oct 30, 2019
bb647e4
RPC tests passed!
terencechain Oct 30, 2019
14abf56
Fixed all init sync tests
terencechain Oct 30, 2019
e4e70c2
All tests pass
terencechain Oct 30, 2019
3be111a
Sync with master
terencechain Oct 30, 2019
b3558c9
Fixed blockchain tests
terencechain Oct 30, 2019
5a754dd
Lint
terencechain Oct 30, 2019
e7300df
Lint
terencechain Oct 30, 2019
cdb7222
Conflict
terencechain Oct 30, 2019
67ab64b
Preston's feedback
terencechain Oct 31, 2019
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
10 changes: 3 additions & 7 deletions beacon-chain/archiver/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,22 @@ func (s *Service) Status() error {
// We archive committee information pertaining to the head state's epoch.
func (s *Service) archiveCommitteeInfo(ctx context.Context, headState *pb.BeaconState) error {
currentEpoch := helpers.SlotToEpoch(headState.Slot)
committeeCount, err := helpers.CommitteeCount(headState, currentEpoch)
committeeCount, err := helpers.CommitteeCountAtSlot(headState, helpers.StartSlot(currentEpoch))
if err != nil {
return errors.Wrap(err, "could not get committee count")
}
seed, err := helpers.Seed(headState, currentEpoch, params.BeaconConfig().DomainBeaconAttester)
if err != nil {
return errors.Wrap(err, "could not generate seed")
}
startShard, err := helpers.StartShard(headState, currentEpoch)
if err != nil {
return errors.Wrap(err, "could not get start shard")
}
proposerIndex, err := helpers.BeaconProposerIndex(headState)
if err != nil {
return errors.Wrap(err, "could not get beacon proposer index")
}

info := &ethpb.ArchivedCommitteeInfo{
Seed: seed[:],
StartShard: startShard,
CommitteeCount: committeeCount,
CommitteeCount: committeeCount * params.BeaconConfig().SlotsPerEpoch,
ProposerIndex: proposerIndex,
}
if err := s.beaconDB.SaveArchivedCommitteeInfo(ctx, currentEpoch, info); err != nil {
Expand Down
19 changes: 3 additions & 16 deletions beacon-chain/archiver/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ func TestArchiverService_SavesCommitteeInfo(t *testing.T) {
triggerNewHeadEvent(t, svc, [32]byte{})

currentEpoch := helpers.CurrentEpoch(headState)
startShard, err := helpers.StartShard(headState, currentEpoch)
if err != nil {
t.Fatal(err)
}
committeeCount, err := helpers.CommitteeCount(headState, currentEpoch)
committeeCount, err := helpers.CommitteeCountAtSlot(headState, helpers.StartSlot(currentEpoch))
if err != nil {
t.Fatal(err)
}
Expand All @@ -146,8 +142,7 @@ func TestArchiverService_SavesCommitteeInfo(t *testing.T) {
}
wanted := &ethpb.ArchivedCommitteeInfo{
Seed: seed[:],
StartShard: startShard,
CommitteeCount: committeeCount,
CommitteeCount: committeeCount * params.BeaconConfig().SlotsPerEpoch,
ProposerIndex: propIdx,
}

Expand Down Expand Up @@ -251,14 +246,7 @@ func setupState(t *testing.T, validatorCount uint64) *pb.BeaconState {
balances[i] = params.BeaconConfig().MaxEffectiveBalance
}

atts := []*pb.PendingAttestation{{Data: &ethpb.AttestationData{Crosslink: &ethpb.Crosslink{Shard: 0}, Target: &ethpb.Checkpoint{}}}}
var crosslinks []*ethpb.Crosslink
for i := uint64(0); i < params.BeaconConfig().ShardCount; i++ {
crosslinks = append(crosslinks, &ethpb.Crosslink{
StartEpoch: 0,
DataRoot: []byte{'A'},
})
}
atts := []*pb.PendingAttestation{{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{}}}}

// We initialize a head state that has attestations from participated
// validators in a simulated fashion.
Expand All @@ -269,7 +257,6 @@ func setupState(t *testing.T, validatorCount uint64) *pb.BeaconState {
BlockRoots: make([][]byte, 128),
Slashings: []uint64{0, 1e9, 1e9},
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
CurrentCrosslinks: crosslinks,
CurrentEpochAttestations: atts,
FinalizedCheckpoint: &ethpb.Checkpoint{},
JustificationBits: bitfield.Bitvector4{0x00},
Expand Down
13 changes: 2 additions & 11 deletions beacon-chain/blockchain/forkchoice/process_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,7 @@ func (s *Store) waitForAttInclDelay(ctx context.Context, a *ethpb.Attestation, t
ctx, span := trace.StartSpan(ctx, "beacon-chain.forkchoice.waitForAttInclDelay")
defer span.End()

slot, err := helpers.AttestationDataSlot(targetState, a.Data)
if err != nil {
return errors.Wrap(err, "could not get attestation slot")
}

nextSlot := slot + 1
nextSlot := a.Data.Slot + 1
duration := time.Duration(nextSlot*params.BeaconConfig().SecondsPerSlot) * time.Second
timeToInclude := time.Unix(int64(targetState.GenesisTime), 0).Add(duration)

Expand Down Expand Up @@ -225,11 +220,7 @@ func (s *Store) aggregateAttestation(ctx context.Context, att *ethpb.Attestation

// verifyAttSlotTime validates input attestation is not from the future.
func (s *Store) verifyAttSlotTime(ctx context.Context, baseState *pb.BeaconState, d *ethpb.AttestationData) error {
aSlot, err := helpers.AttestationDataSlot(baseState, d)
if err != nil {
return errors.Wrap(err, "could not get attestation slot")
}
return helpers.VerifySlotTime(baseState.GenesisTime, aSlot+1)
return helpers.VerifySlotTime(baseState.GenesisTime, d.Slot+1)
}

// verifyAttestation validates input attestation is valid.
Expand Down
23 changes: 7 additions & 16 deletions beacon-chain/blockchain/forkchoice/process_attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,19 @@ func TestStore_SaveCheckpointState(t *testing.T) {

store := NewForkChoiceService(ctx, db)

crosslinks := make([]*ethpb.Crosslink, params.BeaconConfig().ShardCount)
for i := 0; i < len(crosslinks); i++ {
crosslinks[i] = &ethpb.Crosslink{
ParentRoot: make([]byte, 32),
DataRoot: make([]byte, 32),
}
}
s := &pb.BeaconState{
Fork: &pb.Fork{
Epoch: 0,
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
},
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
StateRoots: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot),
LatestBlockHeader: &ethpb.BeaconBlockHeader{},
JustificationBits: []byte{0},
CurrentJustifiedCheckpoint: &ethpb.Checkpoint{},
CurrentCrosslinks: crosslinks,
Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector),
FinalizedCheckpoint: &ethpb.Checkpoint{},
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
StateRoots: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot),
LatestBlockHeader: &ethpb.BeaconBlockHeader{},
JustificationBits: []byte{0},
Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector),
FinalizedCheckpoint: &ethpb.Checkpoint{},
}
if err := store.GenesisStore(ctx, &ethpb.Checkpoint{}, &ethpb.Checkpoint{}); err != nil {
t.Fatal(err)
Expand Down
8 changes: 0 additions & 8 deletions beacon-chain/blockchain/forkchoice/process_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ func TestStore_UpdateBlockAttestationVote(t *testing.T) {
Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
Target: &ethpb.Checkpoint{Epoch: 0, Root: r[:]},
Crosslink: &ethpb.Crosslink{
Shard: 0,
StartEpoch: 0,
},
},
AggregationBits: []byte{255},
CustodyBits: []byte{255},
Expand Down Expand Up @@ -201,10 +197,6 @@ func TestStore_UpdateBlockAttestationsVote(t *testing.T) {
Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
Target: &ethpb.Checkpoint{Epoch: 0, Root: r[:]},
Crosslink: &ethpb.Crosslink{
Shard: uint64(i),
StartEpoch: 0,
},
},
AggregationBits: []byte{255},
CustodyBits: []byte{255},
Expand Down
9 changes: 3 additions & 6 deletions beacon-chain/blockchain/receive_attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ func TestReceiveAttestation_ProcessCorrectly(t *testing.T) {
}

a := &ethpb.Attestation{Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{Root: root[:]},
Crosslink: &ethpb.Crosslink{},
Target: &ethpb.Checkpoint{Root: root[:]},
}}
if err := chainService.ReceiveAttestation(ctx, a); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -70,8 +69,7 @@ func TestReceiveAttestation_SameHead(t *testing.T) {
}

a := &ethpb.Attestation{Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{Root: root[:]},
Crosslink: &ethpb.Crosslink{},
Target: &ethpb.Checkpoint{Root: root[:]},
}}
if err := chainService.ReceiveAttestation(ctx, a); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -104,8 +102,7 @@ func TestReceiveAttestationNoPubsub_ProcessCorrectly(t *testing.T) {
}

a := &ethpb.Attestation{Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{Root: root[:]},
Crosslink: &ethpb.Crosslink{},
Target: &ethpb.Checkpoint{Root: root[:]},
}}
if err := chainService.ReceiveAttestationNoPubsub(ctx, a); err != nil {
t.Fatal(err)
Expand Down
14 changes: 5 additions & 9 deletions beacon-chain/cache/committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/sliceutil"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -66,7 +65,7 @@ func NewCommitteeCache() *CommitteeCache {

// ShuffledIndices fetches the shuffled indices by epoch and shard. Every list of indices
// represent one committee. Returns true if the list exists with epoch and shard. Otherwise returns false, nil.
func (c *CommitteeCache) ShuffledIndices(epoch uint64, shard uint64) ([]uint64, error) {
func (c *CommitteeCache) ShuffledIndices(epoch uint64, index uint64) ([]uint64, error) {
c.lock.RLock()
defer c.lock.RUnlock()
obj, exists, err := c.CommitteeCache.GetByKey(strconv.Itoa(int(epoch)))
Expand All @@ -86,8 +85,7 @@ func (c *CommitteeCache) ShuffledIndices(epoch uint64, shard uint64) ([]uint64,
return nil, ErrNotCommittee
}

start, end := startEndIndices(item, shard)

start, end := startEndIndices(item, index)
return item.Committee[start:end], nil
}

Expand Down Expand Up @@ -208,12 +206,10 @@ func (c *CommitteeCache) ActiveIndices(epoch uint64) ([]uint64, error) {
return item.Committee, nil
}

func startEndIndices(c *Committee, wantedShard uint64) (uint64, uint64) {
shardCount := params.BeaconConfig().ShardCount
currentShard := (wantedShard + shardCount - c.StartShard) % shardCount
func startEndIndices(c *Committee, index uint64) (uint64, uint64) {
validatorCount := uint64(len(c.Committee))
start := sliceutil.SplitOffset(validatorCount, c.CommitteeCount, currentShard)
end := sliceutil.SplitOffset(validatorCount, c.CommitteeCount, currentShard+1)
start := sliceutil.SplitOffset(validatorCount, c.CommitteeCount, index)
end := sliceutil.SplitOffset(validatorCount, c.CommitteeCount, index+1)

return start, end
}
64 changes: 7 additions & 57 deletions beacon-chain/core/blocks/block_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,6 @@ func ProcessAttestationNoVerify(ctx context.Context, beaconState *pb.BeaconState
defer span.End()

data := att.Data

if data.Crosslink.Shard > params.BeaconConfig().ShardCount {
return nil, fmt.Errorf(
"expected crosslink shard %d to be less than SHARD_COUNT %d",
data.Crosslink.Shard,
params.BeaconConfig().ShardCount,
)
}

if data.Target.Epoch != helpers.PrevEpoch(beaconState) && data.Target.Epoch != helpers.CurrentEpoch(beaconState) {
return nil, fmt.Errorf(
"expected target epoch (%d) to be the previous epoch (%d) or the current epoch (%d)",
Expand All @@ -576,16 +567,13 @@ func ProcessAttestationNoVerify(ctx context.Context, beaconState *pb.BeaconState
)
}

attestationSlot, err := helpers.AttestationDataSlot(beaconState, data)
if err != nil {
return nil, errors.Wrap(err, "could not get attestation slot")
}
minInclusionCheck := attestationSlot+params.BeaconConfig().MinAttestationInclusionDelay <= beaconState.Slot
epochInclusionCheck := beaconState.Slot <= attestationSlot+params.BeaconConfig().SlotsPerEpoch
s := att.Data.Slot
minInclusionCheck := s+params.BeaconConfig().MinAttestationInclusionDelay <= beaconState.Slot
epochInclusionCheck := beaconState.Slot <= s+params.BeaconConfig().SlotsPerEpoch
if !minInclusionCheck {
return nil, fmt.Errorf(
"attestation slot %d + inclusion delay %d > state slot %d",
attestationSlot,
s,
params.BeaconConfig().MinAttestationInclusionDelay,
beaconState.Slot,
)
Expand All @@ -594,7 +582,7 @@ func ProcessAttestationNoVerify(ctx context.Context, beaconState *pb.BeaconState
return nil, fmt.Errorf(
"state slot %d > attestation slot %d + SLOTS_PER_EPOCH %d",
beaconState.Slot,
attestationSlot,
s,
params.BeaconConfig().SlotsPerEpoch,
)
}
Expand All @@ -610,34 +598,22 @@ func ProcessAttestationNoVerify(ctx context.Context, beaconState *pb.BeaconState
pendingAtt := &pb.PendingAttestation{
Data: data,
AggregationBits: att.AggregationBits,
InclusionDelay: beaconState.Slot - attestationSlot,
InclusionDelay: beaconState.Slot - s,
ProposerIndex: proposerIndex,
}

var ffgSourceEpoch uint64
var ffgSourceRoot []byte
var ffgTargetEpoch uint64
var parentCrosslink *ethpb.Crosslink
if data.Target.Epoch == helpers.CurrentEpoch(beaconState) {
ffgSourceEpoch = beaconState.CurrentJustifiedCheckpoint.Epoch
ffgSourceRoot = beaconState.CurrentJustifiedCheckpoint.Root
ffgTargetEpoch = helpers.CurrentEpoch(beaconState)
crosslinkShard := data.Crosslink.Shard
if int(crosslinkShard) >= len(beaconState.CurrentCrosslinks) {
return nil, fmt.Errorf("invalid shard given in attestation: %d", crosslinkShard)
}

parentCrosslink = beaconState.CurrentCrosslinks[crosslinkShard]
beaconState.CurrentEpochAttestations = append(beaconState.CurrentEpochAttestations, pendingAtt)
} else {
ffgSourceEpoch = beaconState.PreviousJustifiedCheckpoint.Epoch
ffgSourceRoot = beaconState.PreviousJustifiedCheckpoint.Root
ffgTargetEpoch = helpers.PrevEpoch(beaconState)
crosslinkShard := data.Crosslink.Shard
if int(crosslinkShard) >= len(beaconState.PreviousCrosslinks) {
return nil, fmt.Errorf("invalid shard given in attestation: %d", crosslinkShard)
}
parentCrosslink = beaconState.PreviousCrosslinks[crosslinkShard]
beaconState.PreviousEpochAttestations = append(beaconState.PreviousEpochAttestations, pendingAtt)
}
if data.Source.Epoch != ffgSourceEpoch {
Expand All @@ -649,34 +625,7 @@ func ProcessAttestationNoVerify(ctx context.Context, beaconState *pb.BeaconState
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.Target.Epoch < endEpoch {
endEpoch = data.Target.Epoch
}
if data.Crosslink.StartEpoch != parentCrosslink.EndEpoch {
return nil, fmt.Errorf("expected crosslink start epoch %d, received %d",
parentCrosslink.EndEpoch, data.Crosslink.StartEpoch)
}
if data.Crosslink.EndEpoch != endEpoch {
return nil, fmt.Errorf("expected crosslink end epoch %d, received %d",
endEpoch, data.Crosslink.EndEpoch)
}
crosslinkParentRoot, err := ssz.HashTreeRoot(parentCrosslink)
if err != nil {
return nil, errors.Wrap(err, "could not tree hash parent crosslink")
}
if !bytes.Equal(data.Crosslink.ParentRoot, crosslinkParentRoot[:]) {
return nil, fmt.Errorf(
"mismatched parent crosslink root, expected %#x, received %#x",
crosslinkParentRoot,
data.Crosslink.ParentRoot,
)
}

// To be removed in Phase 1
if !bytes.Equal(data.Crosslink.DataRoot, params.BeaconConfig().ZeroHash[:]) {
return nil, fmt.Errorf("expected data root %#x == ZERO_HASH", data.Crosslink.DataRoot)
}
return beaconState, nil
}

Expand Down Expand Up @@ -706,6 +655,7 @@ func ConvertToIndexed(ctx context.Context, state *pb.BeaconState, attestation *e
if err != nil {
return nil, errors.Wrap(err, "could not get attesting indices")
}

cb1i, err := helpers.AttestingIndices(state, attestation.Data, attestation.CustodyBits)
if err != nil {
return nil, err
Expand Down
Loading