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

Implement ListBeaconCommittees RPC Method #3977

Merged
merged 108 commits into from
Nov 13, 2019
Merged

Conversation

rauljordan
Copy link
Contributor

@rauljordan rauljordan commented Nov 11, 2019

Resolves #3969 and #3938


Description

Write why you are making the changes in this pull request

This PR implements the ListBeaconCommittees method in our RPC package, allowing for easy retrieval of all committees in an epoch for the usage of slashing detection. Thanks @shayzluf for suggesting this feature. It fetches all beacon committees, paginated by default, based on input parameters of epoch as a query filter.

Using this functionality and an attestation's bitfield, we can convert attestations into indexed form, allowing for easier slashing detection!

Link anything that would be helpful or relevant to the reviewers

  • Needs tests
  • Needs to be tested at runtime with archival on/off

The request/response type protobuf messages are given below:

message ListCommitteesRequest {
    oneof query_filter {
        // Optional criteria to retrieve data at a specific epoch.
        uint64 epoch = 1;

        // Optional criteria to retrieve genesis data.
        bool genesis = 2;
    }

    // The maximum number of Validators to return in the response.
    // This field is optional.
    int32 page_size = 3;

    // A pagination token returned from a previous call to `GetValidators`
    // that indicates where this listing should continue from.
    // This field is optional.
    string page_token = 4;
}

message BeaconCommittees {
    message CommitteeItem {
        // A committee of validator indices that need to attest to beacon blocks.
        repeated uint64 committee = 1;

        // The slot at which the committee is assigned to.
        uint64 slot = 2;
    }
    // The epoch for which the committees in the response belong to.
    uint64 epoch = 1;

    // A list of committees of validators for given  epoch.
    repeated CommitteeItem committees = 2;

    // The number of active validators at the given epoch.
    uint64 active_validator_count = 3;

    // A pagination token returned from a previous call
    // that indicates from where the listing should continue.
    string next_page_token = 4;

    // Total count of committees matching the request filter.
    int32 total_size = 5;
}

terencechain and others added 30 commits October 29, 2019 08:44
* rm'ed in protobuf

* build proto

* build proto

* build proto

* fix core package

* Gazelle

* Fixed all the tests

* Fixed static test

* Comment out spec test for now

* One more skip

* fix-roundRobinSync (#3862)

* Starting but need new seed function

* Revert initial sync

* Updated Proposer Slashing

* Fixed all tests

* Lint

* Update inclusion reward

* Fill randao mixes with eth1 data hash

* Test

* Fixing test part1

* All tests passing

* One last test

* Updated config

* Build proto

* Proper skip message

* Conflict and fmt

* Removed crosslinks and shards. Built

* Format and gazelle

* Fixed all the block package tests

* Fixed all the helper tests

* All epoch package tests pass

* All core package tests pass

* Fixed operation tests

* Started fixing rpc test

* RPC tests passed!

* Fixed all init sync tests

* All tests pass

* Fixed blockchain tests

* Lint

* Lint

* Preston's feedback

* Starting

* Remove container

* Fixed block spec tests

* All passing except for block_processing test

* Failing block processing test

* Starting

* Add AggregateAndProof

* All mainnet test passes
* Starting

* Add AggregateAndProof
* rm'ed in protobuf

* build proto

* build proto

* build proto

* fix core package

* Gazelle

* Fixed all the tests

* Fixed static test

* Comment out spec test for now

* One more skip

* fix-roundRobinSync (#3862)

* Starting but need new seed function

* Revert initial sync

* Updated Proposer Slashing

* Fixed all tests

* Lint

* Update inclusion reward

* Fill randao mixes with eth1 data hash

* Test

* Fixing test part1

* All tests passing

* One last test

* Updated config

* Build proto

* Proper skip message

* Conflict and fmt

* Removed crosslinks and shards. Built

* Format and gazelle

* Fixed all the block package tests

* Fixed all the helper tests

* All epoch package tests pass

* All core package tests pass

* Fixed operation tests

* Started fixing rpc test

* RPC tests passed!

* Fixed all init sync tests

* All tests pass

* Fixed blockchain tests

* Lint

* Lint

* Preston's feedback

* Starting

* Remove container

* Fixed block spec tests

* All passing except for block_processing test

* Failing block processing test

* Starting

* Add AggregateAndProof

* All mainnet test passes

* Unskip block util tests
* Starting

* Add AggregateAndProof

* Unskip slot processing mainnet test
* Rm outdated interop tests

* Rm test runner

* Gazelle
* Updated committee cache

* Removed shuffled indices cache

* Started testing run time

* Lint

* Fixed test
@@ -69,10 +69,6 @@ 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.CommitteeCountAtSlot(headState, helpers.StartSlot(currentEpoch))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, we shouldn't store this because it can change on a slot by slot basis

ProposerSeed: proposerSeed[:],
AttesterSeed: attesterSeed[:],
CommitteeCount: committeeCount * params.BeaconConfig().SlotsPerEpoch,
ProposerSeed: proposerSeed[:],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two seeds are really all we need to determine historical assignments alongside historical balances

beacon-chain/archiver/service.go Outdated Show resolved Hide resolved
var attesterSeed [32]byte
var activeIndices []uint64
var err error
if requestingGenesis || helpers.SlotToEpoch(startSlot) < helpers.SlotToEpoch(headState.Slot) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the archival condition

)
}
attesterSeed = bytesutil.ToBytes32(archivedCommitteeInfo.AttesterSeed)
} else if !requestingGenesis && helpers.SlotToEpoch(startSlot) == helpers.SlotToEpoch(headState.Slot) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise if requesting current epoch, return current results

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add these as comments? it seems helpful

beacon-chain/rpc/beacon/committees.go Outdated Show resolved Hide resolved
0xKiwi
0xKiwi previously approved these changes Nov 12, 2019
@@ -42,30 +42,6 @@ func TestLifecycle_OK(t *testing.T) {

}

func TestRPC_BadEndpoint(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unrelated, but it was so flaky and annoying that I support removing it in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also wasn't really testing much - it wasn't really behavior we cared about testing in the first place

)
}
attesterSeed = bytesutil.ToBytes32(archivedCommitteeInfo.AttesterSeed)
} else if !requestingGenesis && helpers.SlotToEpoch(startSlot) == helpers.SlotToEpoch(headState.Slot) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add these as comments? it seems helpful

//
// If no filter criteria is specified, the response returns
// all beacon committees for the current epoch. The results are paginated by default.
func (bs *Server) ListBeaconCommittees(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this we might need more options for the req *ethpb.ListCommitteesRequest. Along with epoch we also need to give a query option, where we can provide the state root.

In the event of a fork in the network, you could have two chains with different committees at the same epoch. To differentiate on the two sets of committees we would need to be able to identify committees from forked chains, so the state root is a good way to identify them. @shayzluf and I discussed this offline, in the event of a fork in the network , we need to be able to get the appropriate committees from each forked chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, that's a neat suggestion. So what happens if you provide a state root that doesnt match head state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can do this in a follow-up PR as that will increase the diff quite a lot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it would mean we are asking for the committees from a forked chain :) This would be important for the slasher, as it needs to be able to detect malicious attestations in the event of a fork. Sounds good, we can do it in a follow up PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: High High priority item Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement GetCommittees RPC Endpoint
7 participants