From 76a21207bb820818a47117b754d31ff315fc580d Mon Sep 17 00:00:00 2001 From: terence tsao Date: Tue, 14 May 2019 13:44:12 -0700 Subject: [PATCH] Update Shard Helpers for 0.6 (#2497) * ValidatorStatus Estimating Activation RPC Server (#2469) * fix spacing * working on position in queue * fmt * spacing * feedback * tests * rename * Only Perform Initial Sync With a Single Peer (#2471) * fix spacing * use send instead of broadcast in initial sync * Fix Estimation of Deposit Inclusion Slot in ValidatorActivationStatus (#2472) * fix spacing * fix time estimates * correct slot estimation * naming * Update beacon-chain/rpc/validator_server.go Co-Authored-By: rauljordan * SSZ web api for decoding input data (#2473) * first pass ssz server for decoding deposit input data * fix decoding * revert viz change on helper * add image target * use /api prefix, add deployment for cluster * fix lint * standardize slot numbers (#2475) * Add CORS for ssz api (#2476) * first pass ssz server for decoding deposit input data * fix decoding * revert viz change on helper * add image target * use /api prefix, add deployment for cluster * fix lint * needed CORS * Allow Client to Retrieve Multiple Validator Statuses (#2474) * multiple validator statuses * gazelle * context * fixing bugs * remove old way of checking * fix logging * make activation queue more accurate * fix rpc test * add test * fix remaining tests * lint * comment * review comments * Update Prysm README (#2477) * README updated * readme updates * no err throw (#2479) * Fix Status Nil Pointer Error (#2480) * no err throw * nil errors * 3.175 (#2482) * Better Error Message if Failing to Exit Initial Sync (#2483) * no err throw * nil errors * better error on init sync * Only Log Active Balances (#2485) * only log active balance * dont need () * change logging (#2487) * fix chainstart waiting on rpc server (#2488) * shift ticker to after activation (#2489) * Add drain script (#2418) * Add drain script * Fix script to drain contracts from newest to oldest * Add README * remove comments * Only after block 400k, look up by deposit event * issue warn log on disconnecting peer instead of error (#2491) * Display Only Active Validator Data (#2490) * Fix Validator Status Field in RPC Server (#2492) * fix status of key * status test fix * fmt * Estimate the Time Till Follow Distance Is Completed (#2486) * use estimation instead * fix test * fixing another test * fix tests and preston's comments * remove unused var * fix condition * Revert "fix condition" This reverts commit dee0e3112c01f68f30a2e50cd4eb35f29f672e1d. * dont return error * add production config for testnet release (#2493) * Lookup Validator Index in State in Status Check (#2494) * state lookup * refactor duplicate code * refactor with mapping * fix broken tests * finish refactor * merged master * updated EpochCommitteeCount and fixed tests * implemented ShardDelta * test for ShardDelta * implemented EpochStartShard * added epoch out of bound test * test for accurate start shard * lint --- beacon-chain/core/helpers/committee_test.go | 69 +++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/beacon-chain/core/helpers/committee_test.go b/beacon-chain/core/helpers/committee_test.go index 9aa893ce837e..0e1ddb17bcbf 100644 --- a/beacon-chain/core/helpers/committee_test.go +++ b/beacon-chain/core/helpers/committee_test.go @@ -927,3 +927,72 @@ func TestVerifyAttestationBitfield_OK(t *testing.T) { } } + +func TestShardDelta_Ok(t *testing.T) { + validatorsPerEpoch := params.BeaconConfig().SlotsPerEpoch * params.BeaconConfig().TargetCommitteeSize + min := params.BeaconConfig().ShardCount - params.BeaconConfig().ShardCount/params.BeaconConfig().SlotsPerEpoch + tests := []struct { + validatorCount uint64 + shardDelta uint64 + }{ + {0, params.BeaconConfig().SlotsPerEpoch}, + {1000, params.BeaconConfig().SlotsPerEpoch}, + {2 * validatorsPerEpoch, 2 * params.BeaconConfig().SlotsPerEpoch}, + {5 * validatorsPerEpoch, 5 * params.BeaconConfig().SlotsPerEpoch}, + {16 * validatorsPerEpoch, min}, + {32 * validatorsPerEpoch, min}, + } + for _, test := range tests { + validators := make([]*pb.Validator, test.validatorCount) + for i := 0; i < len(validators); i++ { + validators[i] = &pb.Validator{ + ExitEpoch: params.BeaconConfig().FarFutureEpoch, + } + } + state := &pb.BeaconState{ValidatorRegistry: validators} + if test.shardDelta != ShardDelta(state, params.BeaconConfig().GenesisEpoch) { + t.Errorf("wanted: %d, got: %d", + test.shardDelta, ShardDelta(state, params.BeaconConfig().GenesisEpoch)) + } + } +} + +func TestEpochStartShard_EpochOutOfBound(t *testing.T) { + _, err := EpochStartShard(&pb.BeaconState{}, 2) + want := "epoch 2 can't be greater than 1" + if err.Error() != want { + t.Fatalf("Did not generate correct error. Want: %s, got: %s", + err.Error(), want) + } +} + +func TestEpochStartShard_AccurateShard(t *testing.T) { + validatorsPerEpoch := params.BeaconConfig().SlotsPerEpoch * params.BeaconConfig().TargetCommitteeSize + tests := []struct { + validatorCount uint64 + startShard uint64 + }{ + {0, 676}, + {1000, 676}, + {2 * validatorsPerEpoch, 228}, + {5 * validatorsPerEpoch, 932}, + {16 * validatorsPerEpoch, 212}, + {32 * validatorsPerEpoch, 212}, + } + for _, test := range tests { + validators := make([]*pb.Validator, test.validatorCount) + for i := 0; i < len(validators); i++ { + validators[i] = &pb.Validator{ + ExitEpoch: params.BeaconConfig().FarFutureEpoch, + } + } + state := &pb.BeaconState{ValidatorRegistry: validators, LatestStartShard: 100, Slot: 500} + startShard, err := EpochStartShard(state, 0) + if err != nil { + t.Fatal(err) + } + if test.startShard != startShard { + t.Errorf("wanted: %d, got: %d", test.startShard, startShard) + } + } +}