Align Protobuf Type Names (#2825)

This commit is contained in:
terence tsao
2019-06-18 17:22:39 -07:00
committed by GitHub
parent 06d1161bd2
commit 882d067144
54 changed files with 807 additions and 1056 deletions

View File

@@ -101,10 +101,10 @@ func (a *Service) IncomingAttestationFeed() *event.Feed {
// BeaconBlock` be the target block in the attestation
// `get_latest_attestation(store, validator_index)`.
func (a *Service) LatestAttestationTarget(beaconState *pb.BeaconState, index uint64) (*pb.AttestationTarget, error) {
if index >= uint64(len(beaconState.ValidatorRegistry)) {
if index >= uint64(len(beaconState.Validators)) {
return nil, fmt.Errorf("invalid validator index %d", index)
}
validator := beaconState.ValidatorRegistry[index]
validator := beaconState.Validators[index]
pubKey := bytesutil.ToBytes48(validator.Pubkey)
a.store.RLock()
@@ -262,14 +262,14 @@ func (a *Service) updateAttestation(beaconState *pb.BeaconState, attestation *pb
return nil
}
if int(committee[i]) >= len(beaconState.ValidatorRegistry) {
if int(committee[i]) >= len(beaconState.Validators) {
log.Debugf("index doesn't exist in validator registry: index %d", committee[i])
return nil
}
// If the attestation came from this attester. We use the slot committee to find the
// validator's actual index.
pubkey := bytesutil.ToBytes48(beaconState.ValidatorRegistry[committee[i]].Pubkey)
pubkey := bytesutil.ToBytes48(beaconState.Validators[committee[i]].Pubkey)
newAttestationSlot := slot
currentAttestationSlot := uint64(0)
a.store.Lock()

View File

@@ -39,9 +39,9 @@ func TestUpdateLatestAttestation_UpdatesLatest(t *testing.T) {
beaconState := &pb.BeaconState{
Slot: 1,
ValidatorRegistry: validators,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
block := &pb.BeaconBlock{
Slot: 1,
@@ -66,7 +66,7 @@ func TestUpdateLatestAttestation_UpdatesLatest(t *testing.T) {
if err := service.UpdateLatestAttestation(ctx, attestation); err != nil {
t.Fatalf("could not update latest attestation: %v", err)
}
pubkey := bytesutil.ToBytes48(beaconState.ValidatorRegistry[10].Pubkey)
pubkey := bytesutil.ToBytes48(beaconState.Validators[10].Pubkey)
if service.store.m[pubkey].Data.Crosslink.Shard !=
attestation.Data.Crosslink.Shard {
t.Errorf("Incorrect shard stored, wanted: %d, got: %d",
@@ -75,9 +75,9 @@ func TestUpdateLatestAttestation_UpdatesLatest(t *testing.T) {
beaconState = &pb.BeaconState{
Slot: 36,
ValidatorRegistry: validators,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
if err := beaconDB.UpdateChainHead(ctx, block, beaconState); err != nil {
t.Fatalf("could not save state: %v", err)
@@ -109,7 +109,7 @@ func TestAttestationPool_UpdatesAttestationPool(t *testing.T) {
}
beaconState := &pb.BeaconState{
Slot: 1,
ValidatorRegistry: validators,
Validators: validators,
}
block := &pb.BeaconBlock{
Slot: 1,
@@ -142,7 +142,7 @@ func TestLatestAttestationTarget_CantGetAttestation(t *testing.T) {
ctx := context.Background()
if err := beaconDB.SaveState(ctx, &pb.BeaconState{
ValidatorRegistry: []*pb.Validator{{}},
Validators: []*pb.Validator{{}},
}); err != nil {
t.Fatalf("could not save state: %v", err)
}
@@ -166,7 +166,7 @@ func TestLatestAttestationTarget_ReturnsLatestAttestedBlock(t *testing.T) {
pubKey := []byte{'A'}
if err := beaconDB.SaveState(ctx, &pb.BeaconState{
ValidatorRegistry: []*pb.Validator{{Pubkey: pubKey}},
Validators: []*pb.Validator{{Pubkey: pubKey}},
}); err != nil {
t.Fatalf("could not save state: %v", err)
}
@@ -228,9 +228,9 @@ func TestUpdateLatestAttestation_InvalidIndex(t *testing.T) {
beaconState := &pb.BeaconState{
Slot: 1,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
ValidatorRegistry: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
Validators: validators,
}
block := &pb.BeaconBlock{
Slot: 1,
@@ -280,9 +280,9 @@ func TestBatchUpdate_FromSync(t *testing.T) {
beaconState := &pb.BeaconState{
Slot: 1,
ValidatorRegistry: validators,
LatestRandaoMixes: latestRandaoMixes,
LatestActiveIndexRoots: latestActiveIndexRoots,
Validators: validators,
RandaoMixes: latestRandaoMixes,
ActiveIndexRoots: latestActiveIndexRoots,
}
block := &pb.BeaconBlock{
Slot: 1,
@@ -330,9 +330,9 @@ func TestUpdateLatestAttestation_BatchUpdate(t *testing.T) {
beaconState := &pb.BeaconState{
Slot: 1,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
ValidatorRegistry: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
Validators: validators,
}
block := &pb.BeaconBlock{
Slot: 1,

View File

@@ -279,11 +279,11 @@ func (c *ChainService) saveValidatorIdx(state *pb.BeaconState) error {
for _, idx := range activatedValidators {
// If for some reason the activated validator indices is not in state,
// we skip them and save them to process for next epoch.
if int(idx) >= len(state.ValidatorRegistry) {
if int(idx) >= len(state.Validators) {
idxNotInState = append(idxNotInState, idx)
continue
}
pubKey := state.ValidatorRegistry[idx].Pubkey
pubKey := state.Validators[idx].Pubkey
if err := c.beaconDB.SaveValidatorIndex(pubKey, int(idx)); err != nil {
return fmt.Errorf("could not save validator index: %v", err)
}
@@ -301,7 +301,7 @@ func (c *ChainService) saveValidatorIdx(state *pb.BeaconState) error {
func (c *ChainService) deleteValidatorIdx(state *pb.BeaconState) error {
exitedValidators := validators.ExitedValFromEpoch(helpers.CurrentEpoch(state) + 1)
for _, idx := range exitedValidators {
pubKey := state.ValidatorRegistry[idx].Pubkey
pubKey := state.Validators[idx].Pubkey
if err := c.beaconDB.DeleteValidatorIndex(pubKey); err != nil {
return fmt.Errorf("could not delete validator index: %v", err)
}

View File

@@ -116,7 +116,7 @@ func TestReceiveBlock_ProcessCorrectly(t *testing.T) {
if err != nil {
t.Fatalf("Can't generate genesis state: %v", err)
}
beaconState.LatestStateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.StateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
genesis := b.NewGenesisBlock([]byte{})
bodyRoot, err := ssz.HashTreeRoot(genesis.Body)
if err != nil {
@@ -193,7 +193,7 @@ func TestReceiveBlock_UsesParentBlockState(t *testing.T) {
if err != nil {
t.Fatalf("Can't generate genesis state: %v", err)
}
beaconState.LatestStateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.StateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
genesis := b.NewGenesisBlock([]byte{})
bodyRoot, err := ssz.HashTreeRoot(genesis.Body)
if err != nil {
@@ -256,7 +256,7 @@ func TestReceiveBlock_DeletesBadBlock(t *testing.T) {
if err != nil {
t.Fatalf("Can't generate genesis state: %v", err)
}
beaconState.LatestStateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.StateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
genesis := b.NewGenesisBlock([]byte{})
bodyRoot, err := ssz.HashTreeRoot(genesis.Body)
if err != nil {
@@ -349,7 +349,7 @@ func TestReceiveBlock_CheckBlockStateRoot_GoodState(t *testing.T) {
if err != nil {
t.Fatal(err)
}
beaconState.LatestStateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.StateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.LatestBlockHeader = &pb.BeaconBlockHeader{
Slot: genesis.Slot,
ParentRoot: genesis.ParentRoot,
@@ -412,7 +412,7 @@ func TestReceiveBlock_CheckBlockStateRoot_BadState(t *testing.T) {
if err != nil {
t.Fatal(err)
}
beaconState.LatestStateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.StateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.LatestBlockHeader = &pb.BeaconBlockHeader{
Slot: genesis.Slot,
ParentRoot: genesis.ParentRoot,
@@ -478,7 +478,7 @@ func TestReceiveBlock_RemovesPendingDeposits(t *testing.T) {
if err != nil {
t.Fatal(err)
}
beaconState.LatestStateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.StateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.LatestBlockHeader = &pb.BeaconBlockHeader{
Slot: genesis.Slot,
ParentRoot: genesis.ParentRoot,
@@ -510,7 +510,7 @@ func TestReceiveBlock_RemovesPendingDeposits(t *testing.T) {
}
pendingDeposits := []*pb.Deposit{
createPreChainStartDeposit([]byte{'F'}, beaconState.DepositIndex),
createPreChainStartDeposit([]byte{'F'}, beaconState.Eth1DepositIndex),
}
pendingDepositsData := make([][]byte, len(pendingDeposits))
for i, pd := range pendingDeposits {
@@ -533,7 +533,7 @@ func TestReceiveBlock_RemovesPendingDeposits(t *testing.T) {
pendingDeposits[i].Proof = proof
}
depositRoot := depositTrie.Root()
beaconState.LatestEth1Data.DepositRoot = depositRoot[:]
beaconState.Eth1Data.DepositRoot = depositRoot[:]
if err := db.SaveHistoricalState(context.Background(), beaconState, parentHash); err != nil {
t.Fatal(err)
}
@@ -557,7 +557,7 @@ func TestReceiveBlock_RemovesPendingDeposits(t *testing.T) {
}
beaconState.Slot--
beaconState.DepositIndex = 0
beaconState.Eth1DepositIndex = 0
if err := chainService.beaconDB.SaveState(ctx, beaconState); err != nil {
t.Fatal(err)
}
@@ -594,8 +594,8 @@ func TestReceiveBlock_RemovesPendingDeposits(t *testing.T) {
if err != nil {
t.Fatal(err)
}
for i := 0; i < len(beaconState.ValidatorRegistry); i++ {
pubKey := bytesutil.ToBytes48(beaconState.ValidatorRegistry[i].Pubkey)
for i := 0; i < len(beaconState.Validators); i++ {
pubKey := bytesutil.ToBytes48(beaconState.Validators[i].Pubkey)
attsService.InsertAttestationIntoStore(pubKey, &pb.Attestation{
Data: &pb.AttestationData{
BeaconBlockRoot: blockRoot[:],
@@ -660,7 +660,7 @@ func TestReceiveBlock_OnChainSplit(t *testing.T) {
if err != nil {
t.Fatal(err)
}
beaconState.LatestStateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.StateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.LatestBlockHeader = &pb.BeaconBlockHeader{
Slot: genesis.Slot,
ParentRoot: genesis.ParentRoot,
@@ -831,7 +831,7 @@ func TestIsBlockReadyForProcessing_ValidBlock(t *testing.T) {
if err != nil {
t.Fatal(err)
}
beaconState.LatestStateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.StateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.LatestBlockHeader = &pb.BeaconBlockHeader{
Slot: genesis.Slot,
ParentRoot: genesis.ParentRoot,
@@ -859,7 +859,7 @@ func TestIsBlockReadyForProcessing_ValidBlock(t *testing.T) {
t.Fatalf("unable to get root of canonical head: %v", err)
}
beaconState.LatestEth1Data = &pb.Eth1Data{
beaconState.Eth1Data = &pb.Eth1Data{
DepositRoot: []byte{2},
BlockHash: []byte{3},
}
@@ -916,7 +916,7 @@ func TestDeleteValidatorIdx_DeleteWorks(t *testing.T) {
})
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: epoch * params.BeaconConfig().SlotsPerEpoch,
}
chainService := setupBeaconChain(t, db, nil)
@@ -958,7 +958,7 @@ func TestSaveValidatorIdx_SaveRetrieveWorks(t *testing.T) {
})
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: epoch * params.BeaconConfig().SlotsPerEpoch,
}
chainService := setupBeaconChain(t, db, nil)
@@ -996,7 +996,7 @@ func TestSaveValidatorIdx_IdxNotInState(t *testing.T) {
})
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: epoch * params.BeaconConfig().SlotsPerEpoch,
}
chainService := setupBeaconChain(t, db, nil)

View File

@@ -420,7 +420,7 @@ func VoteCount(block *pb.BeaconBlock, state *pb.BeaconState, targets map[uint64]
}
if bytes.Equal(blockRoot[:], ancestorRoot) {
balances += int(state.ValidatorRegistry[validatorIndex].EffectiveBalance)
balances += int(state.Validators[validatorIndex].EffectiveBalance)
}
}
return balances, nil

View File

@@ -39,7 +39,7 @@ func TestApplyForkChoice_ChainSplitReorg(t *testing.T) {
if err != nil {
t.Fatalf("Can't generate genesis state: %v", err)
}
justifiedState.LatestStateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
justifiedState.StateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
justifiedState.LatestBlockHeader = &pb.BeaconBlockHeader{
StateRoot: []byte{},
}

View File

@@ -203,7 +203,7 @@ func TestVoteCount_IncreaseCountCorrectly(t *testing.T) {
if err := beaconDB.SaveBlock(potentialHead2); err != nil {
t.Fatal(err)
}
beaconState := &pb.BeaconState{ValidatorRegistry: []*pb.Validator{{EffectiveBalance: 1e9}, {EffectiveBalance: 1e9}}}
beaconState := &pb.BeaconState{Validators: []*pb.Validator{{EffectiveBalance: 1e9}, {EffectiveBalance: 1e9}}}
voteTargets := make(map[uint64]*pb.AttestationTarget)
voteTargets[0] = &pb.AttestationTarget{
Slot: potentialHead.Slot,
@@ -233,7 +233,7 @@ func TestAttestationTargets_RetrieveWorks(t *testing.T) {
pubKey := []byte{'A'}
beaconState := &pb.BeaconState{
ValidatorRegistry: []*pb.Validator{{
Validators: []*pb.Validator{{
Pubkey: pubKey,
ExitEpoch: params.BeaconConfig().FarFutureEpoch}},
}
@@ -502,7 +502,7 @@ func TestLMDGhost_TrivialHeadUpdate(t *testing.T) {
beaconState := &pb.BeaconState{
Slot: 10,
Balances: []uint64{params.BeaconConfig().MaxDepositAmount},
ValidatorRegistry: []*pb.Validator{{}},
Validators: []*pb.Validator{{}},
}
chainService := setupBeaconChain(t, beaconDB, nil)
@@ -571,7 +571,7 @@ func TestLMDGhost_3WayChainSplitsSameHeight(t *testing.T) {
params.BeaconConfig().MaxDepositAmount,
params.BeaconConfig().MaxDepositAmount,
params.BeaconConfig().MaxDepositAmount},
ValidatorRegistry: []*pb.Validator{{EffectiveBalance: params.BeaconConfig().MaxDepositAmount},
Validators: []*pb.Validator{{EffectiveBalance: params.BeaconConfig().MaxDepositAmount},
{EffectiveBalance: params.BeaconConfig().MaxDepositAmount},
{EffectiveBalance: params.BeaconConfig().MaxDepositAmount},
{EffectiveBalance: params.BeaconConfig().MaxDepositAmount}},
@@ -776,7 +776,7 @@ func TestLMDGhost_2WayChainSplitsDiffHeight(t *testing.T) {
beaconState := &pb.BeaconState{
Slot: 10,
ValidatorRegistry: []*pb.Validator{
Validators: []*pb.Validator{
{EffectiveBalance: params.BeaconConfig().MaxDepositAmount},
{EffectiveBalance: params.BeaconConfig().MaxDepositAmount},
{EffectiveBalance: params.BeaconConfig().MaxDepositAmount},
@@ -1506,7 +1506,7 @@ func setupFFGTest(t *testing.T) ([32]byte, *pb.BeaconBlock, *pb.BeaconState, []*
}
latestRandaoMixes := make(
[][]byte,
params.BeaconConfig().LatestRandaoMixesLength,
params.BeaconConfig().RandaoMixesLength,
)
for i := 0; i < len(latestRandaoMixes); i++ {
latestRandaoMixes[i] = make([]byte, 32)
@@ -1538,12 +1538,12 @@ func setupFFGTest(t *testing.T) ([32]byte, *pb.BeaconBlock, *pb.BeaconState, []*
}
gState := &pb.BeaconState{
Slot: genesisSlot,
LatestBlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot),
LatestRandaoMixes: latestRandaoMixes,
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
LatestSlashedBalances: make([]uint64, params.BeaconConfig().LatestSlashedExitLength),
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot),
RandaoMixes: latestRandaoMixes,
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
SlashedBalances: make([]uint64, params.BeaconConfig().SlashedExitLength),
CurrentCrosslinks: crosslinks,
ValidatorRegistry: validatorRegistry,
Validators: validatorRegistry,
Balances: validatorBalances,
Fork: &pb.Fork{
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
@@ -1590,7 +1590,7 @@ func TestVoteCount_CacheEnabledAndMiss(t *testing.T) {
if err := beaconDB.SaveBlock(potentialHead2); err != nil {
t.Fatal(err)
}
beaconState := &pb.BeaconState{ValidatorRegistry: []*pb.Validator{{EffectiveBalance: 1e9}, {EffectiveBalance: 1e9}}}
beaconState := &pb.BeaconState{Validators: []*pb.Validator{{EffectiveBalance: 1e9}, {EffectiveBalance: 1e9}}}
voteTargets := make(map[uint64]*pb.AttestationTarget)
voteTargets[0] = &pb.AttestationTarget{
Slot: potentialHead.Slot,
@@ -1655,7 +1655,7 @@ func TestVoteCount_CacheEnabledAndHit(t *testing.T) {
beaconState := &pb.BeaconState{
Balances: []uint64{1e9, 1e9},
ValidatorRegistry: []*pb.Validator{
Validators: []*pb.Validator{
{EffectiveBalance: 1e9},
{EffectiveBalance: 1e9},
},

View File

@@ -64,7 +64,7 @@ func TestSeedCache_SeedByEpoch(t *testing.T) {
func TestSeed_MaxSize(t *testing.T) {
cache := NewSeedCache()
for i := uint64(0); i < params.BeaconConfig().LatestRandaoMixesLength+100; i++ {
for i := uint64(0); i < params.BeaconConfig().RandaoMixesLength+100; i++ {
tInfo := &SeedByEpoch{
Epoch: i,
}

View File

@@ -64,7 +64,7 @@ func TestTotalBalanceCache_TotalBalanceByEpoch(t *testing.T) {
func TestTotalBalance_MaxSize(t *testing.T) {
cache := NewTotalBalanceCache()
for i := uint64(0); i < params.BeaconConfig().LatestRandaoMixesLength+100; i++ {
for i := uint64(0); i < params.BeaconConfig().RandaoMixesLength+100; i++ {
tInfo := &TotalBalanceByEpoch{
Epoch: i,
}

View File

@@ -46,6 +46,6 @@ type TestBlock struct {
// TestAttestation --
type TestAttestation struct {
Block string `yaml:"block"`
ValidatorRegistry string `yaml:"validators"`
Validators string `yaml:"validators"`
CommitteeSlot uint64 `yaml:"committee_slot"`
}

View File

@@ -103,7 +103,7 @@ func (sb *SimulatedBackend) GenerateBlockAndAdvanceChain(objects *SimulatedObjec
return fmt.Errorf("could not generate simulated beacon block %v", err)
}
newState := sb.state
newState.LatestEth1Data = newBlock.Body.Eth1Data
newState.Eth1Data = newBlock.Body.Eth1Data
newState, err = state.ExecuteStateTransition(
context.Background(),
sb.state,
@@ -263,7 +263,7 @@ func (sb *SimulatedBackend) setupBeaconStateAndGenesisBlock(initialDeposits []*p
if err != nil {
return fmt.Errorf("could not initialize simulated beacon state: %v", err)
}
sb.state.LatestStateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
sb.state.StateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
sb.historicalDeposits = initialDeposits
// We do not expect hashing initial beacon state and genesis block to
@@ -345,47 +345,47 @@ func (sb *SimulatedBackend) compareTestCase(testCase *StateTestCase) error {
testCase.Results.Slot,
)
}
if len(sb.state.ValidatorRegistry) != testCase.Results.NumValidators {
if len(sb.state.Validators) != testCase.Results.NumValidators {
return fmt.Errorf(
"incorrect num validators after %d state transitions without blocks, wanted %d, received %d",
testCase.Config.NumSlots,
testCase.Results.NumValidators,
len(sb.state.ValidatorRegistry),
len(sb.state.Validators),
)
}
for _, slashed := range testCase.Results.SlashedValidators {
if !sb.state.ValidatorRegistry[slashed].Slashed {
if !sb.state.Validators[slashed].Slashed {
return fmt.Errorf(
"expected validator at index %d to have been slashed",
slashed,
)
}
if sb.state.ValidatorRegistry[slashed].ExitEpoch != params.BeaconConfig().FarFutureEpoch {
if sb.state.Validators[slashed].ExitEpoch != params.BeaconConfig().FarFutureEpoch {
return fmt.Errorf(
"expected validator at index %d to have exited",
slashed,
)
}
if sb.state.ValidatorRegistry[slashed].WithdrawableEpoch != params.BeaconConfig().FarFutureEpoch {
if sb.state.Validators[slashed].WithdrawableEpoch != params.BeaconConfig().FarFutureEpoch {
return fmt.Errorf(
"expected validator at index %d withdrawable epoch to have been changed, received: %d",
slashed,
sb.state.ValidatorRegistry[slashed].WithdrawableEpoch,
sb.state.Validators[slashed].WithdrawableEpoch,
)
}
}
for _, exited := range testCase.Results.ExitedValidators {
if sb.state.ValidatorRegistry[exited].ExitEpoch != params.BeaconConfig().FarFutureEpoch {
if sb.state.Validators[exited].ExitEpoch != params.BeaconConfig().FarFutureEpoch {
return fmt.Errorf(
"expected validator at index %d to have exited",
exited,
)
}
if sb.state.ValidatorRegistry[exited].WithdrawableEpoch != params.BeaconConfig().FarFutureEpoch {
if sb.state.Validators[exited].WithdrawableEpoch != params.BeaconConfig().FarFutureEpoch {
return fmt.Errorf(
"expected validator at index %d withdrawable epoch to have been changed, received: %d",
exited,
sb.state.ValidatorRegistry[exited].WithdrawableEpoch,
sb.state.Validators[exited].WithdrawableEpoch,
)
}
}

View File

@@ -70,7 +70,7 @@ func ProcessEth1DataInBlock(beaconState *pb.BeaconState, block *pb.BeaconBlock)
}
if voteCount*2 > params.BeaconConfig().SlotsPerEth1VotingPeriod {
beaconState.LatestEth1Data = block.Body.Eth1Data
beaconState.Eth1Data = block.Body.Eth1Data
}
return beaconState, nil
@@ -127,7 +127,7 @@ func ProcessBlockHeader(
if err != nil {
return nil, err
}
proposer := beaconState.ValidatorRegistry[idx]
proposer := beaconState.Validators[idx]
if proposer.Slashed {
return nil, fmt.Errorf("proposer at index %d was previously slashed", idx)
}
@@ -172,21 +172,21 @@ func ProcessRandao(
}
// If block randao passed verification, we XOR the state's latest randao mix with the block's
// randao and update the state's corresponding latest randao mix value.
latestMixesLength := params.BeaconConfig().LatestRandaoMixesLength
latestMixesLength := params.BeaconConfig().RandaoMixesLength
currentEpoch := helpers.CurrentEpoch(beaconState)
latestMixSlice := beaconState.LatestRandaoMixes[currentEpoch%latestMixesLength]
latestMixSlice := beaconState.RandaoMixes[currentEpoch%latestMixesLength]
blockRandaoReveal := hashutil.Hash(body.RandaoReveal)
for i, x := range blockRandaoReveal {
latestMixSlice[i] ^= x
}
beaconState.LatestRandaoMixes[currentEpoch%latestMixesLength] = latestMixSlice
beaconState.RandaoMixes[currentEpoch%latestMixesLength] = latestMixSlice
return beaconState, nil
}
// Verify that bls_verify(proposer.pubkey, hash_tree_root(get_current_epoch(state)),
// block.body.randao_reveal, domain=get_domain(state.fork, get_current_epoch(state), DOMAIN_RANDAO))
func verifyBlockRandao(beaconState *pb.BeaconState, body *pb.BeaconBlockBody, proposerIdx uint64, enableLogging bool) error {
proposer := beaconState.ValidatorRegistry[proposerIdx]
proposer := beaconState.Validators[proposerIdx]
pub, err := bls.PublicKeyFromBytes(proposer.Pubkey)
if err != nil {
return fmt.Errorf("could not deserialize proposer public key: %v", err)
@@ -239,7 +239,7 @@ func ProcessProposerSlashings(
verifySignatures bool,
) (*pb.BeaconState, error) {
body := block.Body
registry := beaconState.ValidatorRegistry
registry := beaconState.Validators
if uint64(len(body.ProposerSlashings)) > params.BeaconConfig().MaxProposerSlashings {
return nil, fmt.Errorf(
"number of proposer slashings (%d) exceeds allowed threshold of %d",
@@ -333,7 +333,7 @@ func ProcessAttesterSlashings(
var err error
var slashedAny bool
for _, validatorIndex := range slashableIndices {
if helpers.IsSlashableValidator(beaconState.ValidatorRegistry[validatorIndex], currentEpoch) {
if helpers.IsSlashableValidator(beaconState.Validators[validatorIndex], currentEpoch) {
beaconState, err = v.SlashValidator(beaconState, validatorIndex, 0)
if err != nil {
return nil, fmt.Errorf("could not slash validator index %d: %v",
@@ -677,7 +677,7 @@ func ProcessValidatorDeposits(
var err error
deposits := block.Body.Deposits
// Verify that outstanding deposits are processed up to the maximum number of deposits.
maxDeposits := beaconState.LatestEth1Data.DepositCount - beaconState.DepositIndex
maxDeposits := beaconState.Eth1Data.DepositCount - beaconState.Eth1DepositIndex
if params.BeaconConfig().MaxDepositAmount < maxDeposits {
maxDeposits = params.BeaconConfig().MaxDepositAmount
}
@@ -754,7 +754,7 @@ func ProcessDeposit(
if err := verifyDeposit(beaconState, deposit, verifyTree); err != nil {
return nil, fmt.Errorf("could not verify deposit #%d: %v", deposit.Index, err)
}
beaconState.DepositIndex++
beaconState.Eth1DepositIndex++
pubKey := deposit.Data.Pubkey
amount := deposit.Data.Amount
index, ok := valIndexMap[bytesutil.ToBytes32(pubKey)]
@@ -766,7 +766,7 @@ func ProcessDeposit(
if params.BeaconConfig().MaxEffectiveBalance < effectiveBalance {
effectiveBalance = params.BeaconConfig().MaxEffectiveBalance
}
beaconState.ValidatorRegistry = append(beaconState.ValidatorRegistry, &pb.Validator{
beaconState.Validators = append(beaconState.Validators, &pb.Validator{
Pubkey: pubKey,
WithdrawalCredentials: deposit.Data.WithdrawalCredentials,
ActivationEligibilityEpoch: params.BeaconConfig().FarFutureEpoch,
@@ -786,7 +786,7 @@ func ProcessDeposit(
func verifyDeposit(beaconState *pb.BeaconState, deposit *pb.Deposit, verifyTree bool) error {
if verifyTree {
// Verify Merkle proof of deposit and deposit trie root.
receiptRoot := beaconState.LatestEth1Data.DepositRoot
receiptRoot := beaconState.Eth1Data.DepositRoot
leaf, err := ssz.HashTreeRoot(deposit.Data)
if err != nil {
return fmt.Errorf("could not tree hash deposit data: %v", err)
@@ -805,10 +805,10 @@ func verifyDeposit(beaconState *pb.BeaconState, deposit *pb.Deposit, verifyTree
}
// Deposits must be processed in order
if deposit.Index != beaconState.DepositIndex {
if deposit.Index != beaconState.Eth1DepositIndex {
return fmt.Errorf(
"expected deposit merkle tree index to match beacon state deposit index, wanted: %d, received: %d",
beaconState.DepositIndex,
beaconState.Eth1DepositIndex,
deposit.Index,
)
}
@@ -867,7 +867,7 @@ func ProcessValidatorExits(
}
func verifyExit(beaconState *pb.BeaconState, exit *pb.VoluntaryExit, verifySignatures bool) error {
validator := beaconState.ValidatorRegistry[exit.ValidatorIndex]
validator := beaconState.Validators[exit.ValidatorIndex]
currentEpoch := helpers.CurrentEpoch(beaconState)
// Verify the validator is active.
if !helpers.IsActiveValidator(validator, currentEpoch) {
@@ -992,7 +992,7 @@ func verifyTransfer(beaconState *pb.BeaconState, transfer *pb.Transfer, verifySi
if transfer.Amount > maxVal {
maxVal = transfer.Amount
}
sender := beaconState.ValidatorRegistry[transfer.Sender]
sender := beaconState.Validators[transfer.Sender]
senderBalance := beaconState.Balances[transfer.Sender]
// Verify the amount and fee are not individually too big (for anti-overflow purposes).
if senderBalance < maxVal {

View File

@@ -46,15 +46,15 @@ func TestProcessBlockHeader_WrongProposerSig(t *testing.T) {
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: 0,
LatestBlockHeader: &pb.BeaconBlockHeader{Slot: 9},
Fork: &pb.Fork{
PreviousVersion: []byte{0, 0, 0, 0},
CurrentVersion: []byte{0, 0, 0, 0},
},
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
validators[5896].Slashed = false
@@ -106,15 +106,15 @@ func TestProcessBlockHeader_DifferentSlots(t *testing.T) {
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: 0,
LatestBlockHeader: &pb.BeaconBlockHeader{Slot: 9},
Fork: &pb.Fork{
PreviousVersion: []byte{0, 0, 0, 0},
CurrentVersion: []byte{0, 0, 0, 0},
},
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
lbhsr, err := ssz.HashTreeRoot(state.LatestBlockHeader)
@@ -159,15 +159,15 @@ func TestProcessBlockHeader_PreviousBlockRootNotSignedRoot(t *testing.T) {
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: 0,
LatestBlockHeader: &pb.BeaconBlockHeader{Slot: 9},
Fork: &pb.Fork{
PreviousVersion: []byte{0, 0, 0, 0},
CurrentVersion: []byte{0, 0, 0, 0},
},
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
currentEpoch := helpers.CurrentEpoch(state)
@@ -208,15 +208,15 @@ func TestProcessBlockHeader_SlashedProposer(t *testing.T) {
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: 0,
LatestBlockHeader: &pb.BeaconBlockHeader{Slot: 9},
Fork: &pb.Fork{
PreviousVersion: []byte{0, 0, 0, 0},
CurrentVersion: []byte{0, 0, 0, 0},
},
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
parentRoot, err := ssz.SigningRoot(state.LatestBlockHeader)
@@ -263,15 +263,15 @@ func TestProcessBlockHeader_OK(t *testing.T) {
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: 0,
LatestBlockHeader: &pb.BeaconBlockHeader{Slot: 9},
Fork: &pb.Fork{
PreviousVersion: []byte{0, 0, 0, 0},
CurrentVersion: []byte{0, 0, 0, 0},
},
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
validators[5593].Slashed = false
@@ -381,7 +381,7 @@ func TestProcessRandao_SignatureVerifiesAndUpdatesLatestStateMixes(t *testing.T)
t.Errorf("Unexpected error processing block randao: %v", err)
}
currentEpoch := helpers.CurrentEpoch(beaconState)
mix := newState.LatestRandaoMixes[currentEpoch%params.BeaconConfig().LatestRandaoMixesLength]
mix := newState.RandaoMixes[currentEpoch%params.BeaconConfig().RandaoMixesLength]
if bytes.Equal(mix, params.BeaconConfig().ZeroHash[:]) {
t.Errorf(
@@ -416,11 +416,11 @@ func TestProcessEth1Data_SetsCorrectly(t *testing.T) {
if len(newETH1DataVotes) <= 1 {
t.Error("Expected new ETH1 data votes to have length > 1")
}
if !proto.Equal(beaconState.LatestEth1Data, block.Body.Eth1Data) {
if !proto.Equal(beaconState.Eth1Data, block.Body.Eth1Data) {
t.Errorf(
"Expected latest eth1 data to have been set to %v, received %v",
block.Body.Eth1Data,
beaconState.LatestEth1Data,
beaconState.Eth1Data,
)
}
}
@@ -436,7 +436,7 @@ func TestProcessProposerSlashings_ThresholdReached(t *testing.T) {
params.BeaconConfig().MaxProposerSlashings,
)
beaconState := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
Slot: currentSlot,
}
block := &pb.BeaconBlock{
@@ -471,7 +471,7 @@ func TestProcessProposerSlashings_UnmatchedHeaderEpochs(t *testing.T) {
}
beaconState := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
Slot: currentSlot,
}
block := &pb.BeaconBlock{
@@ -505,7 +505,7 @@ func TestProcessProposerSlashings_SameHeaders(t *testing.T) {
}
beaconState := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
Slot: currentSlot,
}
block := &pb.BeaconBlock{
@@ -549,7 +549,7 @@ func TestProcessProposerSlashings_ValidatorNotSlashable(t *testing.T) {
}
beaconState := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
Slot: currentSlot,
}
block := &pb.BeaconBlock{
@@ -559,7 +559,7 @@ func TestProcessProposerSlashings_ValidatorNotSlashable(t *testing.T) {
}
want := fmt.Sprintf(
"validator with key %#x is not slashable",
beaconState.ValidatorRegistry[0].Pubkey,
beaconState.Validators[0].Pubkey,
)
if _, err := blocks.ProcessProposerSlashings(
@@ -605,12 +605,12 @@ func TestProcessProposerSlashings_AppliesCorrectStatus(t *testing.T) {
}
currentSlot := uint64(0)
beaconState := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: currentSlot,
Balances: validatorBalances,
LatestSlashedBalances: make([]uint64, params.BeaconConfig().LatestSlashedExitLength),
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
SlashedBalances: make([]uint64, params.BeaconConfig().SlashedExitLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
block := &pb.BeaconBlock{
Body: &pb.BeaconBlockBody{
@@ -627,7 +627,7 @@ func TestProcessProposerSlashings_AppliesCorrectStatus(t *testing.T) {
t.Fatalf("Unexpected error: %s", err)
}
newStateVals := newState.ValidatorRegistry
newStateVals := newState.Validators
if newStateVals[1].ExitEpoch != validators[1].ExitEpoch {
t.Errorf("Proposer with index 1 did not correctly exit,"+"wanted slot:%d, got:%d",
newStateVals[1].ExitEpoch, validators[1].ExitEpoch)
@@ -640,7 +640,7 @@ func TestProcessAttesterSlashings_ThresholdReached(t *testing.T) {
currentSlot := uint64(0)
beaconState := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
Slot: currentSlot,
}
block := &pb.BeaconBlock{
@@ -690,7 +690,7 @@ func TestProcessAttesterSlashings_DataNotSlashable(t *testing.T) {
currentSlot := uint64(0)
beaconState := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
Slot: currentSlot,
}
block := &pb.BeaconBlock{
@@ -740,7 +740,7 @@ func TestProcessAttesterSlashings_IndexedAttestationFailedToVerify(t *testing.T)
currentSlot := uint64(0)
beaconState := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
Slot: currentSlot,
}
block := &pb.BeaconBlock{
@@ -839,12 +839,12 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) {
currentSlot := 2 * params.BeaconConfig().SlotsPerEpoch
beaconState := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: currentSlot,
Balances: validatorBalances,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestSlashedBalances: make([]uint64, params.BeaconConfig().LatestSlashedExitLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
SlashedBalances: make([]uint64, params.BeaconConfig().SlashedExitLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
block := &pb.BeaconBlock{
Body: &pb.BeaconBlockBody{
@@ -859,7 +859,7 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) {
if err != nil {
t.Fatal(err)
}
newRegistry := newState.ValidatorRegistry
newRegistry := newState.Validators
// Given the intersection of slashable indices is [1], only validator
// at index 1 should be slashed and exited. We confirm this below.
@@ -1251,9 +1251,9 @@ func TestConvertToIndexed_OK(t *testing.T) {
state := &pb.BeaconState{
Slot: 5,
ValidatorRegistry: validators,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
tests := []struct {
aggregationBitfield []byte
@@ -1338,10 +1338,10 @@ func TestProcessValidatorDeposits_ThresholdReached(t *testing.T) {
},
}
beaconState := &pb.BeaconState{
LatestEth1Data: &pb.Eth1Data{
Eth1Data: &pb.Eth1Data{
DepositCount: params.BeaconConfig().MaxDeposits,
},
DepositIndex: 0,
Eth1DepositIndex: 0,
}
want := "exceeds allowed threshold"
if _, err := blocks.ProcessValidatorDeposits(
@@ -1382,7 +1382,7 @@ func TestProcessValidatorDeposits_MerkleBranchFailsVerification(t *testing.T) {
},
}
beaconState := &pb.BeaconState{
LatestEth1Data: &pb.Eth1Data{
Eth1Data: &pb.Eth1Data{
DepositRoot: []byte{0},
BlockHash: []byte{1},
},
@@ -1434,12 +1434,12 @@ func TestProcessValidatorDeposits_IncorrectMerkleIndex(t *testing.T) {
balances := []uint64{0}
depositRoot := depositTrie.Root()
beaconState := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
Balances: balances,
Slot: 0,
GenesisTime: uint64(0),
DepositIndex: 1,
LatestEth1Data: &pb.Eth1Data{
Eth1DepositIndex: 1,
Eth1Data: &pb.Eth1Data{
DepositRoot: depositRoot[:],
BlockHash: []byte{1},
},
@@ -1493,9 +1493,9 @@ func TestProcessValidatorDeposits_ProcessCorrectly(t *testing.T) {
balances := []uint64{0}
root := depositTrie.Root()
beaconState := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
Balances: balances,
LatestEth1Data: &pb.Eth1Data{
Eth1Data: &pb.Eth1Data{
DepositRoot: root[:],
BlockHash: root[:],
},
@@ -1530,7 +1530,7 @@ func TestProcessDeposit_RepeatedDeposit(t *testing.T) {
balances := []uint64{0, 50}
beaconState := &pb.BeaconState{
Balances: balances,
ValidatorRegistry: registry,
Validators: registry,
}
deposit := &pb.Deposit{
@@ -1571,7 +1571,7 @@ func TestProcessDeposit_PublicKeyDoesNotExist(t *testing.T) {
balances := []uint64{1000, 1000}
beaconState := &pb.BeaconState{
Balances: balances,
ValidatorRegistry: registry,
Validators: registry,
}
deposit := &pb.Deposit{
@@ -1616,7 +1616,7 @@ func TestProcessDeposit_PublicKeyDoesNotExistAndEmptyValidator(t *testing.T) {
beaconState := &pb.BeaconState{
Slot: params.BeaconConfig().SlotsPerEpoch,
Balances: balances,
ValidatorRegistry: registry,
Validators: registry,
}
deposit := &pb.Deposit{
@@ -1650,7 +1650,7 @@ func TestProcessValidatorExits_ThresholdReached(t *testing.T) {
exits := make([]*pb.VoluntaryExit, params.BeaconConfig().MaxVoluntaryExits+1)
registry := []*pb.Validator{}
state := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
}
block := &pb.BeaconBlock{
Body: &pb.BeaconBlockBody{
@@ -1686,7 +1686,7 @@ func TestProcessValidatorExits_ValidatorNotActive(t *testing.T) {
},
}
state := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
}
block := &pb.BeaconBlock{
Body: &pb.BeaconBlockBody{
@@ -1718,7 +1718,7 @@ func TestProcessValidatorExits_InvalidExitEpoch(t *testing.T) {
},
}
state := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
Slot: 0,
}
block := &pb.BeaconBlock{
@@ -1752,7 +1752,7 @@ func TestProcessValidatorExits_NotActiveLongEnoughToExit(t *testing.T) {
},
}
state := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
Slot: 10,
}
block := &pb.BeaconBlock{
@@ -1786,7 +1786,7 @@ func TestProcessValidatorExits_AppliesCorrectStatus(t *testing.T) {
},
}
state := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
Slot: params.BeaconConfig().SlotsPerEpoch * 5,
}
state.Slot = state.Slot + (params.BeaconConfig().PersistentCommitteePeriod * params.BeaconConfig().SlotsPerEpoch)
@@ -1799,7 +1799,7 @@ func TestProcessValidatorExits_AppliesCorrectStatus(t *testing.T) {
if err != nil {
t.Fatalf("Could not process exits: %v", err)
}
newRegistry := newState.ValidatorRegistry
newRegistry := newState.Validators
if newRegistry[0].ExitEpoch != helpers.DelayedActivationExitEpoch(state.Slot/params.BeaconConfig().SlotsPerEpoch) {
t.Errorf("Expected validator exit epoch to be %d, got %d",
helpers.DelayedActivationExitEpoch(state.Slot/params.BeaconConfig().SlotsPerEpoch), newRegistry[0].ExitEpoch)
@@ -1810,7 +1810,7 @@ func TestProcessBeaconTransfers_ThresholdReached(t *testing.T) {
transfers := make([]*pb.Transfer, params.BeaconConfig().MaxTransfers+1)
registry := []*pb.Validator{}
state := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
}
block := &pb.BeaconBlock{
Body: &pb.BeaconBlockBody{
@@ -1847,7 +1847,7 @@ func TestProcessBeaconTransfers_DuplicateTransfer(t *testing.T) {
}
registry := []*pb.Validator{}
state := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
}
block := &pb.BeaconBlock{
Body: &pb.BeaconBlockBody{
@@ -1880,7 +1880,7 @@ func TestProcessBeaconTransfers_FailsVerification(t *testing.T) {
balances := []uint64{params.BeaconConfig().MaxDepositAmount}
state := &pb.BeaconState{
Slot: 0,
ValidatorRegistry: registry,
Validators: registry,
Balances: balances,
}
transfers := []*pb.Transfer{
@@ -1925,8 +1925,8 @@ func TestProcessBeaconTransfers_FailsVerification(t *testing.T) {
t.Errorf("Expected %s, received %v", want, err)
}
state.ValidatorRegistry[0].WithdrawableEpoch = params.BeaconConfig().FarFutureEpoch
state.ValidatorRegistry[0].ActivationEligibilityEpoch = 0
state.Validators[0].WithdrawableEpoch = params.BeaconConfig().FarFutureEpoch
state.Validators[0].ActivationEligibilityEpoch = 0
block.Body.Transfers = []*pb.Transfer{
{
Fee: params.BeaconConfig().MinDepositAmount,
@@ -1943,13 +1943,13 @@ func TestProcessBeaconTransfers_FailsVerification(t *testing.T) {
t.Errorf("Expected %s, received %v", want, err)
}
state.ValidatorRegistry[0].WithdrawableEpoch = 0
state.ValidatorRegistry[0].ActivationEligibilityEpoch = params.BeaconConfig().FarFutureEpoch
state.Validators[0].WithdrawableEpoch = 0
state.Validators[0].ActivationEligibilityEpoch = params.BeaconConfig().FarFutureEpoch
buf := []byte{params.BeaconConfig().BLSWithdrawalPrefixByte}
pubKey := []byte("B")
hashed := hashutil.Hash(pubKey)
buf = append(buf, hashed[:]...)
state.ValidatorRegistry[0].WithdrawalCredentials = buf
state.Validators[0].WithdrawalCredentials = buf
block.Body.Transfers = []*pb.Transfer{
{
Fee: params.BeaconConfig().MinDepositAmount,
@@ -1988,12 +1988,12 @@ func TestProcessBeaconTransfers_OK(t *testing.T) {
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: 0,
Balances: validatorBalances,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestSlashedBalances: make([]uint64, params.BeaconConfig().LatestSlashedExitLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
SlashedBalances: make([]uint64, params.BeaconConfig().SlashedExitLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
transfers := []*pb.Transfer{
{
@@ -2014,8 +2014,8 @@ func TestProcessBeaconTransfers_OK(t *testing.T) {
pubKey := []byte("A")
hashed := hashutil.Hash(pubKey)
buf = append(buf, hashed[:]...)
state.ValidatorRegistry[0].WithdrawalCredentials = buf
state.ValidatorRegistry[0].ActivationEligibilityEpoch = params.BeaconConfig().FarFutureEpoch
state.Validators[0].WithdrawalCredentials = buf
state.Validators[0].ActivationEligibilityEpoch = params.BeaconConfig().FarFutureEpoch
newState, err := blocks.ProcessTransfers(
state,
block,

View File

@@ -32,7 +32,7 @@ func IsValidBlock(
return fmt.Errorf("unprocessed parent block as it is not saved in the db: %#x", parentRoot)
}
h := common.BytesToHash(state.LatestEth1Data.BlockHash)
h := common.BytesToHash(state.Eth1Data.BlockHash)
powBlock, err := GetPOWBlock(ctx, h)
if err != nil {
return fmt.Errorf("unable to retrieve POW chain reference block: %v", err)
@@ -42,7 +42,7 @@ func IsValidBlock(
// The block pointed to by the state in state.processed_pow_receipt_root has
// been processed in the ETH 1.0 chain.
if powBlock == nil {
return fmt.Errorf("proof-of-Work chain reference in state does not exist: %#x", state.LatestEth1Data.BlockHash)
return fmt.Errorf("proof-of-Work chain reference in state does not exist: %#x", state.Eth1Data.BlockHash)
}
// Pre-Processing Condition 4:

View File

@@ -77,7 +77,7 @@ func TestIsValidBlock_InvalidSlot(t *testing.T) {
block.Slot = 3
db.hasBlock = true
beaconState.LatestEth1Data = &pb.Eth1Data{
beaconState.Eth1Data = &pb.Eth1Data{
DepositRoot: []byte{2},
BlockHash: []byte{3},
}
@@ -106,7 +106,7 @@ func TestIsValidBlock_InvalidPoWReference(t *testing.T) {
db.hasBlock = true
block.Slot = 4
powClient.blockExists = false
beaconState.LatestEth1Data = &pb.Eth1Data{
beaconState.Eth1Data = &pb.Eth1Data{
DepositRoot: []byte{2},
BlockHash: []byte{3},
}
@@ -129,7 +129,7 @@ func TestIsValidBlock_InvalidGenesis(t *testing.T) {
powClient.blockExists = false
beaconState.Slot = 3
beaconState.LatestEth1Data = &pb.Eth1Data{
beaconState.Eth1Data = &pb.Eth1Data{
DepositRoot: []byte{2},
BlockHash: []byte{3},
}
@@ -159,7 +159,7 @@ func TestIsValidBlock_GoodBlock(t *testing.T) {
powClient.blockExists = true
beaconState.Slot = 3
beaconState.LatestEth1Data = &pb.Eth1Data{
beaconState.Eth1Data = &pb.Eth1Data{
DepositRoot: []byte{2},
BlockHash: []byte{3},
}

View File

@@ -322,7 +322,7 @@ func ProcessRewardsAndPenalties(state *pb.BeaconState) (*pb.BeaconState, error)
if err != nil {
return nil, fmt.Errorf("could not get crosslink delta: %v ", err)
}
for i := 0; i < len(state.ValidatorRegistry); i++ {
for i := 0; i < len(state.Validators); i++ {
state = helpers.IncreaseBalance(state, uint64(i), attsRewards[i]+clRewards[i])
state = helpers.DecreaseBalance(state, uint64(i), attsPenalties[i]+clPenalties[i])
}
@@ -358,7 +358,7 @@ func ProcessRewardsAndPenalties(state *pb.BeaconState) (*pb.BeaconState, error)
// validator.activation_epoch = get_delayed_activation_exit_epoch(get_current_epoch(state))
func ProcessRegistryUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
currentEpoch := helpers.CurrentEpoch(state)
for idx, validator := range state.ValidatorRegistry {
for idx, validator := range state.Validators {
// Process the validators for activation eligibility.
eligibleToActivate := validator.ActivationEligibilityEpoch == params.BeaconConfig().FarFutureEpoch
properBalance := validator.EffectiveBalance >= params.BeaconConfig().MaxEffectiveBalance
@@ -375,7 +375,7 @@ func ProcessRegistryUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
// Queue the validators whose eligible to activate and sort them by activation eligibility epoch number
var activationQ []uint64
for idx, validator := range state.ValidatorRegistry {
for idx, validator := range state.Validators {
eligibleActivated := validator.ActivationEligibilityEpoch != params.BeaconConfig().FarFutureEpoch
canBeActive := validator.ActivationEpoch >= helpers.DelayedActivationExitEpoch(state.FinalizedEpoch)
if eligibleActivated && canBeActive {
@@ -383,7 +383,7 @@ func ProcessRegistryUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
}
}
sort.Slice(activationQ, func(i, j int) bool {
return state.ValidatorRegistry[i].ActivationEligibilityEpoch < state.ValidatorRegistry[j].ActivationEligibilityEpoch
return state.Validators[i].ActivationEligibilityEpoch < state.Validators[j].ActivationEligibilityEpoch
})
// Only activate just enough validators according to the activation churn limit.
@@ -398,7 +398,7 @@ func ProcessRegistryUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
limit = int(churnLimit)
}
for _, index := range activationQ[:limit] {
validator := state.ValidatorRegistry[index]
validator := state.Validators[index]
if validator.ActivationEpoch == params.BeaconConfig().FarFutureEpoch {
validator.ActivationEpoch = helpers.DelayedActivationExitEpoch(currentEpoch)
}
@@ -432,13 +432,13 @@ func ProcessSlashings(state *pb.BeaconState) (*pb.BeaconState, error) {
}
// Compute slashed balances in the current epoch
exitLength := params.BeaconConfig().LatestSlashedExitLength
totalAtStart := state.LatestSlashedBalances[(currentEpoch+1)%exitLength]
totalAtEnd := state.LatestSlashedBalances[currentEpoch%exitLength]
exitLength := params.BeaconConfig().SlashedExitLength
totalAtStart := state.SlashedBalances[(currentEpoch+1)%exitLength]
totalAtEnd := state.SlashedBalances[currentEpoch%exitLength]
totalPenalties := totalAtEnd - totalAtStart
// Compute slashing for each validator.
for index, validator := range state.ValidatorRegistry {
for index, validator := range state.Validators {
correctEpoch := currentEpoch == validator.WithdrawableEpoch-exitLength/2
if validator.Slashed && correctEpoch {
minPenalties := totalPenalties * 3
@@ -504,7 +504,7 @@ func ProcessFinalUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
}
// Update effective balances with hysteresis.
for i, v := range state.ValidatorRegistry {
for i, v := range state.Validators {
balance := state.Balances[i]
halfInc := params.BeaconConfig().EffectiveBalanceIncrement / 2
if balance < v.EffectiveBalance || v.EffectiveBalance+3*halfInc < balance {
@@ -520,12 +520,12 @@ func ProcessFinalUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
if err != nil {
return nil, fmt.Errorf("could not get shard delta: %v", err)
}
state.LatestStartShard = (state.LatestStartShard + delta) %
state.StartShard = (state.StartShard + delta) %
params.BeaconConfig().ShardCount
// Set active index root.
activationDelay := params.BeaconConfig().ActivationExitDelay
idxRootPosition := (nextEpoch + activationDelay) % params.BeaconConfig().LatestActiveIndexRootsLength
idxRootPosition := (nextEpoch + activationDelay) % params.BeaconConfig().ActiveIndexRootsLength
activeIndices, err := helpers.ActiveValidatorIndices(state, nextEpoch+activationDelay)
if err != nil {
return nil, fmt.Errorf("could not get active indices: %v", err)
@@ -534,24 +534,24 @@ func ProcessFinalUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
if err != nil {
return nil, fmt.Errorf("could not tree hash active indices: %v", err)
}
state.LatestActiveIndexRoots[idxRootPosition] = idxRoot[:]
state.ActiveIndexRoots[idxRootPosition] = idxRoot[:]
// Set total slashed balances.
slashedExitLength := params.BeaconConfig().LatestSlashedExitLength
state.LatestSlashedBalances[nextEpoch%slashedExitLength] =
state.LatestSlashedBalances[currentEpoch%slashedExitLength]
slashedExitLength := params.BeaconConfig().SlashedExitLength
state.SlashedBalances[nextEpoch%slashedExitLength] =
state.SlashedBalances[currentEpoch%slashedExitLength]
// Set RANDAO mix.
randaoMixLength := params.BeaconConfig().LatestRandaoMixesLength
randaoMixLength := params.BeaconConfig().RandaoMixesLength
mix := helpers.RandaoMix(state, currentEpoch)
state.LatestRandaoMixes[nextEpoch%randaoMixLength] = mix
state.RandaoMixes[nextEpoch%randaoMixLength] = mix
// Set historical root accumulator.
epochsPerHistoricalRoot := params.BeaconConfig().SlotsPerHistoricalRoot / params.BeaconConfig().SlotsPerEpoch
if nextEpoch%epochsPerHistoricalRoot == 0 {
historicalBatch := &pb.HistoricalBatch{
BlockRoots: state.LatestBlockRoots,
StateRoots: state.LatestStateRoots,
BlockRoots: state.BlockRoots,
StateRoots: state.StateRoots,
}
batchRoot, err := hashutil.HashProto(historicalBatch)
if err != nil {
@@ -589,7 +589,7 @@ func unslashedAttestingIndices(state *pb.BeaconState, atts []*pb.PendingAttestat
sort.Slice(setIndices, func(i, j int) bool { return setIndices[i] < setIndices[j] })
// Remove the slashed validator indices.
for i := 0; i < len(setIndices); i++ {
if state.ValidatorRegistry[setIndices[i]].Slashed {
if state.Validators[setIndices[i]].Slashed {
setIndices = append(setIndices[:i], setIndices[i+1:]...)
}
}
@@ -693,7 +693,7 @@ func baseReward(state *pb.BeaconState, index uint64) (uint64, error) {
if err != nil {
return 0, fmt.Errorf("could not calculate active balance: %v", err)
}
effectiveBalance := state.ValidatorRegistry[index].EffectiveBalance
effectiveBalance := state.Validators[index].EffectiveBalance
baseReward := effectiveBalance * params.BeaconConfig().BaseRewardFactor /
mathutil.IntegerSquareRoot(totalBalance) / params.BeaconConfig().BaseRewardsPerEpoch
return baseReward, nil
@@ -756,13 +756,13 @@ func attestationDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
return nil, nil, fmt.Errorf("could not get total active balance: %v", err)
}
rewards := make([]uint64, len(state.ValidatorRegistry))
penalties := make([]uint64, len(state.ValidatorRegistry))
rewards := make([]uint64, len(state.Validators))
penalties := make([]uint64, len(state.Validators))
// Filter out the list of eligible validator indices. The eligible validator
// has to be active or slashed but before withdrawn.
var eligible []uint64
for i, v := range state.ValidatorRegistry {
for i, v := range state.Validators {
isActive := helpers.IsActiveValidator(v, prevEpoch)
isSlashed := v.Slashed && (prevEpoch+1 < v.WithdrawableEpoch)
if isActive || isSlashed {
@@ -864,7 +864,7 @@ func attestationDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
}
penalties[index] += params.BeaconConfig().BaseRewardsPerEpoch * base
if _, ok := attestedTarget[index]; !ok {
penalties[index] += state.ValidatorRegistry[index].EffectiveBalance * finalityDelay /
penalties[index] += state.Validators[index].EffectiveBalance * finalityDelay /
params.BeaconConfig().InactivityPenaltyQuotient
}
}
@@ -898,8 +898,8 @@ func attestationDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
// penalties[index] += base_reward
// return rewards, penalties
func crosslinkDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
rewards := make([]uint64, len(state.ValidatorRegistry))
penalties := make([]uint64, len(state.ValidatorRegistry))
rewards := make([]uint64, len(state.Validators))
penalties := make([]uint64, len(state.Validators))
epoch := helpers.PrevEpoch(state)
count, err := helpers.EpochCommitteeCount(state, epoch)
if err != nil {

View File

@@ -85,9 +85,9 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) {
}
state := &pb.BeaconState{
Slot: 0,
ValidatorRegistry: validators,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
indices, err := unslashedAttestingIndices(state, atts)
@@ -102,7 +102,7 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) {
// Verify the slashed validator is filtered.
slashedValidator := indices[0]
state.ValidatorRegistry[slashedValidator].Slashed = true
state.Validators[slashedValidator].Slashed = true
indices, err = unslashedAttestingIndices(state, atts)
if err != nil {
t.Fatal(err)
@@ -130,8 +130,8 @@ func TestUnslashedAttestingIndices_CantGetIndicesBitfieldError(t *testing.T) {
state := &pb.BeaconState{
Slot: 0,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
const wantedErr = "could not get attester indices: wanted participants bitfield length 2, got: 1"
if _, err := unslashedAttestingIndices(state, atts); !strings.Contains(err.Error(), wantedErr) {
@@ -168,9 +168,9 @@ func TestAttestingBalance_CorrectBalance(t *testing.T) {
}
state := &pb.BeaconState{
Slot: 0,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
ValidatorRegistry: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
Validators: validators,
Balances: balances,
}
@@ -202,8 +202,8 @@ func TestAttestingBalance_CantGetIndicesBitfieldError(t *testing.T) {
state := &pb.BeaconState{
Slot: 0,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
const wantedErr = "could not get attester indices: wanted participants bitfield length 0, got: 1"
if _, err := AttestingBalance(state, atts); !strings.Contains(err.Error(), wantedErr) {
@@ -244,9 +244,9 @@ func TestMatchAttestations_PrevEpoch(t *testing.T) {
Slot: s + e + 2,
CurrentEpochAttestations: currentAtts,
PreviousEpochAttestations: prevAtts,
LatestBlockRoots: blockRoots,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
BlockRoots: blockRoots,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
mAtts, err := MatchAttestations(state, 0)
@@ -319,7 +319,7 @@ func TestMatchAttestations_CurrentEpoch(t *testing.T) {
Slot: s + e + 2,
CurrentEpochAttestations: currentAtts,
PreviousEpochAttestations: prevAtts,
LatestBlockRoots: blockRoots,
BlockRoots: blockRoots,
}
mAtts, err := MatchAttestations(state, 1)
@@ -395,7 +395,7 @@ func TestWinningCrosslink_ReturnGensisCrosslink(t *testing.T) {
state := &pb.BeaconState{
Slot: gs + e + 2,
PreviousEpochAttestations: []*pb.PendingAttestation{},
LatestBlockRoots: make([][]byte, 128),
BlockRoots: make([][]byte, 128),
CurrentCrosslinks: []*pb.Crosslink{{StartEpoch: ge}},
}
@@ -466,10 +466,10 @@ func TestWinningCrosslink_CanGetWinningRoot(t *testing.T) {
state := &pb.BeaconState{
Slot: gs + e + 2,
PreviousEpochAttestations: atts,
LatestBlockRoots: blockRoots,
BlockRoots: blockRoots,
CurrentCrosslinks: crosslinks,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
winner, indices, err := winningCrosslink(state, 1, ge)
@@ -512,11 +512,11 @@ func TestProcessCrosslinks_NoUpdate(t *testing.T) {
}
state := &pb.BeaconState{
Slot: params.BeaconConfig().SlotsPerEpoch + 1,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
LatestBlockRoots: blockRoots,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
BlockRoots: blockRoots,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
CurrentCrosslinks: crosslinks,
}
newState, err := ProcessCrosslinks(state)
@@ -577,13 +577,13 @@ func TestProcessCrosslinks_SuccessfulUpdate(t *testing.T) {
}
state := &pb.BeaconState{
Slot: gs + e + 2,
ValidatorRegistry: validators,
Validators: validators,
PreviousEpochAttestations: atts,
Balances: balances,
LatestBlockRoots: blockRoots,
BlockRoots: blockRoots,
CurrentCrosslinks: crosslinks,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
newState, err := ProcessCrosslinks(state)
if err != nil {
@@ -611,7 +611,7 @@ func TestBaseReward_AccurateRewards(t *testing.T) {
for _, tt := range tests {
helpers.ClearAllCaches()
state := &pb.BeaconState{
ValidatorRegistry: []*pb.Validator{
Validators: []*pb.Validator{
{ExitEpoch: params.BeaconConfig().FarFutureEpoch, EffectiveBalance: tt.b}},
Balances: []uint64{tt.a},
}
@@ -648,7 +648,7 @@ func TestProcessJustificationFinalization_CantJustifyFinalize(t *testing.T) {
PreviousJustifiedRoot: params.BeaconConfig().ZeroHash[:],
CurrentJustifiedEpoch: 0,
CurrentJustifiedRoot: params.BeaconConfig().ZeroHash[:],
ValidatorRegistry: []*pb.Validator{{ExitEpoch: e, EffectiveBalance: a}, {ExitEpoch: e, EffectiveBalance: a},
Validators: []*pb.Validator{{ExitEpoch: e, EffectiveBalance: a}, {ExitEpoch: e, EffectiveBalance: a},
{ExitEpoch: e, EffectiveBalance: a}, {ExitEpoch: e, EffectiveBalance: a}},
}
// Since Attested balances are less than total balances, nothing happened.
@@ -675,9 +675,9 @@ func TestProcessJustificationFinalization_NoBlockRootCurrentEpoch(t *testing.T)
CurrentJustifiedEpoch: 0,
CurrentJustifiedRoot: params.BeaconConfig().ZeroHash[:],
JustificationBitfield: 3,
ValidatorRegistry: []*pb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}},
Validators: []*pb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}},
Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000
LatestBlockRoots: blockRoots,
BlockRoots: blockRoots,
}
attestedBalance := 4 * e * 3 / 2
_, err := ProcessJustificationAndFinalization(state, 0, attestedBalance)
@@ -701,9 +701,9 @@ func TestProcessJustificationFinalization_JustifyCurrentEpoch(t *testing.T) {
CurrentJustifiedEpoch: 0,
CurrentJustifiedRoot: params.BeaconConfig().ZeroHash[:],
JustificationBitfield: 3,
ValidatorRegistry: []*pb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}},
Validators: []*pb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}},
Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000
LatestBlockRoots: blockRoots,
BlockRoots: blockRoots,
}
attestedBalance := 4 * e * 3 / 2
newState, err := ProcessJustificationAndFinalization(state, 0, attestedBalance)
@@ -742,9 +742,9 @@ func TestProcessJustificationFinalization_JustifyPrevEpoch(t *testing.T) {
CurrentJustifiedEpoch: 0,
CurrentJustifiedRoot: params.BeaconConfig().ZeroHash[:],
JustificationBitfield: 3,
ValidatorRegistry: []*pb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}},
Validators: []*pb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}},
Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000
LatestBlockRoots: blockRoots,
BlockRoots: blockRoots,
}
attestedBalance := 4 * e * 3 / 2
newState, err := ProcessJustificationAndFinalization(state, attestedBalance, 0)
@@ -771,9 +771,9 @@ func TestProcessJustificationFinalization_JustifyPrevEpoch(t *testing.T) {
func TestProcessSlashings_NotSlashed(t *testing.T) {
s := &pb.BeaconState{
Slot: 0,
ValidatorRegistry: []*pb.Validator{{Slashed: true}},
Validators: []*pb.Validator{{Slashed: true}},
Balances: []uint64{params.BeaconConfig().MaxDepositAmount},
LatestSlashedBalances: []uint64{0, 1e9},
SlashedBalances: []uint64{0, 1e9},
}
newState, err := ProcessSlashings(s)
if err != nil {
@@ -789,13 +789,13 @@ func TestProcessSlashings_SlashedLess(t *testing.T) {
helpers.ClearAllCaches()
s := &pb.BeaconState{
Slot: 0,
ValidatorRegistry: []*pb.Validator{
Validators: []*pb.Validator{
{Slashed: true,
WithdrawableEpoch: params.BeaconConfig().LatestSlashedExitLength / 2,
WithdrawableEpoch: params.BeaconConfig().SlashedExitLength / 2,
EffectiveBalance: params.BeaconConfig().MaxDepositAmount},
{ExitEpoch: params.BeaconConfig().FarFutureEpoch, EffectiveBalance: params.BeaconConfig().MaxDepositAmount}},
Balances: []uint64{params.BeaconConfig().MaxDepositAmount, params.BeaconConfig().MaxDepositAmount},
LatestSlashedBalances: []uint64{0, 1e9},
SlashedBalances: []uint64{0, 1e9},
}
newState, err := ProcessSlashings(s)
if err != nil {
@@ -813,38 +813,38 @@ func TestProcessFinalUpdates_CanProcess(t *testing.T) {
ne := ce + 1
s.Eth1DataVotes = []*pb.Eth1Data{}
s.Balances[0] = 29 * 1e9
s.LatestSlashedBalances[ce] = 100
s.LatestRandaoMixes[ce] = []byte{'A'}
s.SlashedBalances[ce] = 100
s.RandaoMixes[ce] = []byte{'A'}
newS, err := ProcessFinalUpdates(s)
if err != nil {
t.Fatal(err)
}
// Verify effective balance is correctly updated.
if newS.ValidatorRegistry[0].EffectiveBalance != 29*1e9 {
t.Errorf("effective balance incorrectly updated, got %d", s.ValidatorRegistry[0].EffectiveBalance)
if newS.Validators[0].EffectiveBalance != 29*1e9 {
t.Errorf("effective balance incorrectly updated, got %d", s.Validators[0].EffectiveBalance)
}
// Verify start shard is correctly updated.
if newS.LatestStartShard != 64 {
if newS.StartShard != 64 {
t.Errorf("start shard incorrectly updated, got %d", 64)
}
// Verify latest active index root is correctly updated in the right position.
pos := (ne + params.BeaconConfig().ActivationExitDelay) % params.BeaconConfig().LatestActiveIndexRootsLength
if bytes.Equal(newS.LatestActiveIndexRoots[pos], params.BeaconConfig().ZeroHash[:]) {
pos := (ne + params.BeaconConfig().ActivationExitDelay) % params.BeaconConfig().ActiveIndexRootsLength
if bytes.Equal(newS.ActiveIndexRoots[pos], params.BeaconConfig().ZeroHash[:]) {
t.Error("latest active index roots still zero hashes")
}
// Verify slashed balances correctly updated.
if newS.LatestSlashedBalances[ce] != newS.LatestSlashedBalances[ne] {
if newS.SlashedBalances[ce] != newS.SlashedBalances[ne] {
t.Errorf("wanted slashed balance %d, got %d",
newS.LatestSlashedBalances[ce],
newS.LatestSlashedBalances[ne])
newS.SlashedBalances[ce],
newS.SlashedBalances[ne])
}
// Verify randao is correctly updated in the right position.
if bytes.Equal(newS.LatestRandaoMixes[ne], params.BeaconConfig().ZeroHash[:]) {
if bytes.Equal(newS.RandaoMixes[ne], params.BeaconConfig().ZeroHash[:]) {
t.Error("latest RANDAO still zero hashes")
}
@@ -884,7 +884,7 @@ func TestCrosslinkDelta_NoOneAttested(t *testing.T) {
func TestProcessRegistryUpdates_NoRotation(t *testing.T) {
state := &pb.BeaconState{
Slot: 5 * params.BeaconConfig().SlotsPerEpoch,
ValidatorRegistry: []*pb.Validator{
Validators: []*pb.Validator{
{ExitEpoch: params.BeaconConfig().ActivationExitDelay},
{ExitEpoch: params.BeaconConfig().ActivationExitDelay},
},
@@ -897,7 +897,7 @@ func TestProcessRegistryUpdates_NoRotation(t *testing.T) {
if err != nil {
t.Fatal(err)
}
for i, validator := range newState.ValidatorRegistry {
for i, validator := range newState.Validators {
if validator.ExitEpoch != params.BeaconConfig().ActivationExitDelay {
t.Errorf("could not update registry %d, wanted exit slot %d got %d",
i, params.BeaconConfig().ActivationExitDelay, validator.ExitEpoch)
@@ -1112,7 +1112,7 @@ func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) {
}
limit, _ := helpers.ChurnLimit(state)
for i := 0; i < int(limit)+10; i++ {
state.ValidatorRegistry = append(state.ValidatorRegistry, &pb.Validator{
state.Validators = append(state.Validators, &pb.Validator{
ActivationEligibilityEpoch: params.BeaconConfig().FarFutureEpoch,
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
@@ -1120,7 +1120,7 @@ func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) {
}
currentEpoch := helpers.CurrentEpoch(state)
newState, _ := ProcessRegistryUpdates(state)
for i, validator := range newState.ValidatorRegistry {
for i, validator := range newState.Validators {
if validator.ActivationEligibilityEpoch != currentEpoch {
t.Errorf("could not update registry %d, wanted activation eligibility epoch %d got %d",
i, currentEpoch, validator.ActivationEligibilityEpoch)
@@ -1139,7 +1139,7 @@ func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) {
func TestProcessRegistryUpdates_ActivationCompletes(t *testing.T) {
state := &pb.BeaconState{
Slot: 5 * params.BeaconConfig().SlotsPerEpoch,
ValidatorRegistry: []*pb.Validator{
Validators: []*pb.Validator{
{ExitEpoch: params.BeaconConfig().ActivationExitDelay,
ActivationEpoch: 5 + params.BeaconConfig().ActivationExitDelay + 1},
{ExitEpoch: params.BeaconConfig().ActivationExitDelay,
@@ -1151,7 +1151,7 @@ func TestProcessRegistryUpdates_ActivationCompletes(t *testing.T) {
},
}
newState, _ := ProcessRegistryUpdates(state)
for i, validator := range newState.ValidatorRegistry {
for i, validator := range newState.Validators {
if validator.ExitEpoch != params.BeaconConfig().ActivationExitDelay {
t.Errorf("could not update registry %d, wanted exit slot %d got %d",
i, params.BeaconConfig().ActivationExitDelay, validator.ExitEpoch)
@@ -1165,7 +1165,7 @@ func TestProcessRegistryUpdates_CanExits(t *testing.T) {
minWithdrawalDelay := params.BeaconConfig().MinValidatorWithdrawalDelay
state := &pb.BeaconState{
Slot: epoch * params.BeaconConfig().SlotsPerEpoch,
ValidatorRegistry: []*pb.Validator{
Validators: []*pb.Validator{
{
ExitEpoch: exitEpoch,
WithdrawableEpoch: exitEpoch + minWithdrawalDelay},
@@ -1182,7 +1182,7 @@ func TestProcessRegistryUpdates_CanExits(t *testing.T) {
if err != nil {
t.Fatal(err)
}
for i, validator := range newState.ValidatorRegistry {
for i, validator := range newState.Validators {
if validator.ExitEpoch != exitEpoch {
t.Errorf("could not update registry %d, wanted exit slot %d got %d",
i,
@@ -1194,7 +1194,7 @@ func TestProcessRegistryUpdates_CanExits(t *testing.T) {
}
func TestProcessRewardsAndPenalties_GenesisEpoch(t *testing.T) {
state := &pb.BeaconState{Slot: params.BeaconConfig().SlotsPerEpoch - 1, LatestStartShard: 999}
state := &pb.BeaconState{Slot: params.BeaconConfig().SlotsPerEpoch - 1, StartShard: 999}
newState, err := ProcessRewardsAndPenalties(state)
if err != nil {
t.Fatal(err)
@@ -1264,14 +1264,14 @@ func buildState(slot uint64, validatorCount uint64) *pb.BeaconState {
}
latestActiveIndexRoots := make(
[][]byte,
params.BeaconConfig().LatestActiveIndexRootsLength,
params.BeaconConfig().ActiveIndexRootsLength,
)
for i := 0; i < len(latestActiveIndexRoots); i++ {
latestActiveIndexRoots[i] = params.BeaconConfig().ZeroHash[:]
}
latestRandaoMixes := make(
[][]byte,
params.BeaconConfig().LatestRandaoMixesLength,
params.BeaconConfig().RandaoMixesLength,
)
for i := 0; i < len(latestRandaoMixes); i++ {
latestRandaoMixes[i] = params.BeaconConfig().ZeroHash[:]
@@ -1279,11 +1279,11 @@ func buildState(slot uint64, validatorCount uint64) *pb.BeaconState {
return &pb.BeaconState{
Slot: slot,
Balances: validatorBalances,
ValidatorRegistry: validators,
Validators: validators,
CurrentCrosslinks: make([]*pb.Crosslink, params.BeaconConfig().ShardCount),
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
LatestSlashedBalances: make([]uint64, params.BeaconConfig().LatestSlashedExitLength),
LatestBlockRoots: make([][]byte, params.BeaconConfig().SlotsPerEpoch*10),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
SlashedBalances: make([]uint64, params.BeaconConfig().SlashedExitLength),
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerEpoch*10),
}
}

View File

@@ -30,7 +30,7 @@ func BlockRootAtSlot(state *pb.BeaconState, slot uint64) ([]byte, error) {
state.Slot,
)
}
return state.LatestBlockRoots[slot%params.BeaconConfig().SlotsPerHistoricalRoot], nil
return state.BlockRoots[slot%params.BeaconConfig().SlotsPerHistoricalRoot], nil
}
// BlockRoot returns the block root stored in the BeaconState for epoch start slot.

View File

@@ -16,7 +16,7 @@ func TestBlockRootAtSlot_CorrectBlockRoot(t *testing.T) {
blockRoots = append(blockRoots, []byte{byte(i)})
}
s := &pb.BeaconState{
LatestBlockRoots: blockRoots,
BlockRoots: blockRoots,
}
tests := []struct {
@@ -73,7 +73,7 @@ func TestBlockRootAtSlot_OutOfBounds(t *testing.T) {
blockRoots = append(blockRoots, []byte{byte(i)})
}
state := &pb.BeaconState{
LatestBlockRoots: blockRoots,
BlockRoots: blockRoots,
}
tests := []struct {

View File

@@ -330,7 +330,7 @@ func EpochStartShard(state *pb.BeaconState, epoch uint64) (uint64, error) {
return 0, fmt.Errorf("could not get shard delta: %v", err)
}
startShard = (state.LatestStartShard + delta) % params.BeaconConfig().ShardCount
startShard = (state.StartShard + delta) % params.BeaconConfig().ShardCount
for checkEpoch > epoch {
checkEpoch--
delta, err = ShardDelta(state, checkEpoch)

View File

@@ -35,7 +35,7 @@ func TestEpochCommitteeCount_OK(t *testing.T) {
}
}
s := &pb.BeaconState{
ValidatorRegistry: vals,
Validators: vals,
}
count, err := EpochCommitteeCount(s, 1)
if err != nil {
@@ -64,7 +64,7 @@ func TestEpochCommitteeCount_LessShardsThanEpoch(t *testing.T) {
}
}
s := &pb.BeaconState{
ValidatorRegistry: vals,
Validators: vals,
}
count, err := EpochCommitteeCount(s, 1)
if err != nil {
@@ -98,7 +98,7 @@ func TestShardDelta_OK(t *testing.T) {
}
}
s := &pb.BeaconState{
ValidatorRegistry: vals,
Validators: vals,
}
delta, err := ShardDelta(s, 1)
if err != nil {
@@ -124,10 +124,10 @@ func TestComputeCommittee_WithoutCache(t *testing.T) {
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: 200,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
epoch := CurrentEpoch(state)
@@ -183,10 +183,10 @@ func TestComputeCommittee_WithCache(t *testing.T) {
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: 200,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
epoch := CurrentEpoch(state)
@@ -229,9 +229,9 @@ func TestAttestationParticipants_NoCommitteeCache(t *testing.T) {
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
attestationData := &pb.AttestationData{}
@@ -298,9 +298,9 @@ func TestAttestationParticipants_IncorrectBitfield(t *testing.T) {
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
attestationData := &pb.AttestationData{Crosslink: &pb.Crosslink{}}
@@ -355,10 +355,10 @@ func TestCommitteeAssignment_CanRetrieve(t *testing.T) {
}
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: params.BeaconConfig().SlotsPerEpoch,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
tests := []struct {
@@ -426,8 +426,8 @@ func TestCommitteeAssignment_CanRetrieve(t *testing.T) {
func TestCommitteeAssignment_CantFindValidator(t *testing.T) {
state := &pb.BeaconState{
Slot: params.BeaconConfig().SlotsPerEpoch,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
index := uint64(10000)
_, _, _, _, err := CommitteeAssignment(state, 1, index)
@@ -462,7 +462,7 @@ func TestShardDelta_Ok(t *testing.T) {
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
}
}
state := &pb.BeaconState{ValidatorRegistry: validators}
state := &pb.BeaconState{Validators: validators}
delta, err := ShardDelta(state, 0)
if err != nil {
t.Fatal(err)
@@ -504,7 +504,7 @@ func TestEpochStartShard_AccurateShard(t *testing.T) {
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
}
}
state := &pb.BeaconState{ValidatorRegistry: validators, LatestStartShard: 100, Slot: 500}
state := &pb.BeaconState{Validators: validators, StartShard: 100, Slot: 500}
startShard, err := EpochStartShard(state, 0)
if err != nil {
t.Fatal(err)
@@ -521,7 +521,7 @@ func TestVerifyAttestationBitfield_OK(t *testing.T) {
}
validators := make([]*pb.Validator, 2*params.BeaconConfig().SlotsPerEpoch)
activeRoots := make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength)
activeRoots := make([][]byte, params.BeaconConfig().ActiveIndexRootsLength)
for i := 0; i < len(validators); i++ {
validators[i] = &pb.Validator{
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
@@ -530,9 +530,9 @@ func TestVerifyAttestationBitfield_OK(t *testing.T) {
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
LatestActiveIndexRoots: activeRoots,
LatestRandaoMixes: activeRoots,
Validators: validators,
ActiveIndexRoots: activeRoots,
RandaoMixes: activeRoots,
}
tests := []struct {
@@ -636,9 +636,9 @@ func BenchmarkComputeCommittee300000_WithPreCache(b *testing.B) {
}
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
epoch := CurrentEpoch(state)
@@ -675,9 +675,9 @@ func BenchmarkComputeCommittee3000000_WithPreCache(b *testing.B) {
}
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
epoch := CurrentEpoch(state)
@@ -714,9 +714,9 @@ func BenchmarkComputeCommittee128000_WithOutPreCache(b *testing.B) {
}
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
epoch := CurrentEpoch(state)
@@ -754,9 +754,9 @@ func BenchmarkComputeCommittee1000000_WithOutCache(b *testing.B) {
}
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
epoch := CurrentEpoch(state)
@@ -794,9 +794,9 @@ func BenchmarkComputeCommittee4000000_WithOutCache(b *testing.B) {
}
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
epoch := CurrentEpoch(state)

View File

@@ -36,7 +36,7 @@ func GenerateSeed(state *pb.BeaconState, epoch uint64) ([32]byte, error) {
return bytesutil.ToBytes32(seed), nil
}
lookAheadEpoch := epoch + params.BeaconConfig().LatestRandaoMixesLength -
lookAheadEpoch := epoch + params.BeaconConfig().RandaoMixesLength -
params.BeaconConfig().MinSeedLookahead
randaoMix := RandaoMix(state, lookAheadEpoch)
@@ -70,7 +70,7 @@ func GenerateSeed(state *pb.BeaconState, epoch uint64) ([32]byte, error) {
// """
// return state.latest_active_index_roots[epoch % LATEST_ACTIVE_INDEX_ROOTS_LENGTH]
func ActiveIndexRoot(state *pb.BeaconState, epoch uint64) []byte {
return state.LatestActiveIndexRoots[epoch%params.BeaconConfig().LatestActiveIndexRootsLength]
return state.ActiveIndexRoots[epoch%params.BeaconConfig().ActiveIndexRootsLength]
}
// RandaoMix returns the randao mix (xor'ed seed)
@@ -85,7 +85,7 @@ func ActiveIndexRoot(state *pb.BeaconState, epoch uint64) []byte {
// """
// return state.latest_randao_mixes[epoch % LATEST_RANDAO_MIXES_LENGTH]
func RandaoMix(state *pb.BeaconState, epoch uint64) []byte {
return state.LatestRandaoMixes[epoch%params.BeaconConfig().LatestRandaoMixesLength]
return state.RandaoMixes[epoch%params.BeaconConfig().RandaoMixesLength]
}
// CreateRandaoReveal generates a epoch signature using the beacon proposer priv key.

View File

@@ -10,13 +10,13 @@ import (
)
func TestRandaoMix_OK(t *testing.T) {
randaoMixes := make([][]byte, params.BeaconConfig().LatestRandaoMixesLength)
randaoMixes := make([][]byte, params.BeaconConfig().RandaoMixesLength)
for i := 0; i < len(randaoMixes); i++ {
intInBytes := make([]byte, 32)
binary.LittleEndian.PutUint64(intInBytes, uint64(i))
randaoMixes[i] = intInBytes
}
state := &pb.BeaconState{LatestRandaoMixes: randaoMixes}
state := &pb.BeaconState{RandaoMixes: randaoMixes}
tests := []struct {
epoch uint64
randaoMix []byte
@@ -31,7 +31,7 @@ func TestRandaoMix_OK(t *testing.T) {
},
{
epoch: 99999,
randaoMix: randaoMixes[99999%params.BeaconConfig().LatestRandaoMixesLength],
randaoMix: randaoMixes[99999%params.BeaconConfig().RandaoMixesLength],
},
}
for _, test := range tests {
@@ -45,13 +45,13 @@ func TestRandaoMix_OK(t *testing.T) {
}
func TestActiveIndexRoot_OK(t *testing.T) {
activeIndexRoots := make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength)
activeIndexRoots := make([][]byte, params.BeaconConfig().ActiveIndexRootsLength)
for i := 0; i < len(activeIndexRoots); i++ {
intInBytes := make([]byte, 32)
binary.LittleEndian.PutUint64(intInBytes, uint64(i))
activeIndexRoots[i] = intInBytes
}
state := &pb.BeaconState{LatestActiveIndexRoots: activeIndexRoots}
state := &pb.BeaconState{ActiveIndexRoots: activeIndexRoots}
tests := []struct {
epoch uint64
}{
@@ -70,9 +70,9 @@ func TestActiveIndexRoot_OK(t *testing.T) {
for i := 0; i <= int(params.BeaconConfig().ActivationExitDelay); i++ {
indexRoot := ActiveIndexRoot(state, test.epoch+uint64(i))
if !bytes.Equal(activeIndexRoots[(test.epoch+uint64(i))%params.BeaconConfig().LatestActiveIndexRootsLength], indexRoot) {
if !bytes.Equal(activeIndexRoots[(test.epoch+uint64(i))%params.BeaconConfig().ActiveIndexRootsLength], indexRoot) {
t.Errorf("Incorrect index root. Wanted: %#x, got: %#x",
activeIndexRoots[(test.epoch+uint64(i))%params.BeaconConfig().LatestActiveIndexRootsLength], indexRoot)
activeIndexRoots[(test.epoch+uint64(i))%params.BeaconConfig().ActiveIndexRootsLength], indexRoot)
}
}
@@ -82,13 +82,13 @@ func TestActiveIndexRoot_OK(t *testing.T) {
func TestGenerateSeed_OK(t *testing.T) {
ClearAllCaches()
activeIndexRoots := make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength)
activeIndexRoots := make([][]byte, params.BeaconConfig().ActiveIndexRootsLength)
for i := 0; i < len(activeIndexRoots); i++ {
intInBytes := make([]byte, 32)
binary.LittleEndian.PutUint64(intInBytes, uint64(i))
activeIndexRoots[i] = intInBytes
}
randaoMixes := make([][]byte, params.BeaconConfig().LatestRandaoMixesLength)
randaoMixes := make([][]byte, params.BeaconConfig().RandaoMixesLength)
for i := 0; i < len(randaoMixes); i++ {
intInBytes := make([]byte, 32)
binary.LittleEndian.PutUint64(intInBytes, uint64(i))
@@ -96,8 +96,8 @@ func TestGenerateSeed_OK(t *testing.T) {
}
slot := 10 * params.BeaconConfig().MinSeedLookahead * params.BeaconConfig().SlotsPerEpoch
state := &pb.BeaconState{
LatestActiveIndexRoots: activeIndexRoots,
LatestRandaoMixes: randaoMixes,
ActiveIndexRoots: activeIndexRoots,
RandaoMixes: randaoMixes,
Slot: slot}
got, err := GenerateSeed(state, 10)

View File

@@ -32,7 +32,7 @@ func TotalBalance(state *pb.BeaconState, indices []uint64) (uint64, error) {
total = 0
for _, idx := range indices {
total += state.ValidatorRegistry[idx].EffectiveBalance
total += state.Validators[idx].EffectiveBalance
}
if err := totalBalanceCache.AddTotalBalance(&cache.TotalBalanceByEpoch{
@@ -62,9 +62,9 @@ func TotalActiveBalance(state *pb.BeaconState) (uint64, error) {
}
total = 0
for i, v := range state.ValidatorRegistry {
for i, v := range state.Validators {
if IsActiveValidator(v, epoch) {
total += state.ValidatorRegistry[i].EffectiveBalance
total += state.Validators[i].EffectiveBalance
}
}

View File

@@ -7,7 +7,7 @@ import (
)
func TestTotalBalance_OK(t *testing.T) {
state := &pb.BeaconState{ValidatorRegistry: []*pb.Validator{
state := &pb.BeaconState{Validators: []*pb.Validator{
{EffectiveBalance: 27 * 1e9}, {EffectiveBalance: 28 * 1e9},
{EffectiveBalance: 32 * 1e9}, {EffectiveBalance: 40 * 1e9},
}}
@@ -53,7 +53,7 @@ func TestIncreseBalance_OK(t *testing.T) {
}
for _, test := range tests {
state := &pb.BeaconState{
ValidatorRegistry: []*pb.Validator{
Validators: []*pb.Validator{
{EffectiveBalance: 4}, {EffectiveBalance: 4}, {EffectiveBalance: 4}},
Balances: test.b,
}
@@ -76,7 +76,7 @@ func TestDecreseBalance_OK(t *testing.T) {
}
for _, test := range tests {
state := &pb.BeaconState{
ValidatorRegistry: []*pb.Validator{
Validators: []*pb.Validator{
{EffectiveBalance: 4}, {EffectiveBalance: 4}, {EffectiveBalance: 4}},
Balances: test.b,
}

View File

@@ -67,7 +67,7 @@ func ActiveValidatorIndices(state *pb.BeaconState, epoch uint64) ([]uint64, erro
return indices, nil
}
for i, v := range state.ValidatorRegistry {
for i, v := range state.Validators {
if IsActiveValidator(v, epoch) {
indices = append(indices, uint64(i))
}
@@ -95,7 +95,7 @@ func ActiveValidatorCount(state *pb.BeaconState, epoch uint64) (uint64, error) {
}
count = 0
for _, v := range state.ValidatorRegistry {
for _, v := range state.Validators {
if IsActiveValidator(v, epoch) {
count++
}
@@ -207,7 +207,7 @@ func BeaconProposerIndex(state *pb.BeaconState) (uint64, error) {
candidateIndex := firstCommittee[(e+i)%uint64(len(firstCommittee))]
b := append(seed[:], bytesutil.Bytes8(i)...)
randomByte := hashutil.Hash(b)[i%32]
effectiveBal := state.ValidatorRegistry[candidateIndex].EffectiveBalance
effectiveBal := state.Validators[candidateIndex].EffectiveBalance
if effectiveBal*maxRandomByte >= params.BeaconConfig().MaxEffectiveBalance*uint64(randomByte) {
return candidateIndex, nil
}

View File

@@ -43,10 +43,10 @@ func TestBeaconProposerIndex_OK(t *testing.T) {
}
state := &pb.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: 0,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
tests := []struct {
@@ -96,8 +96,8 @@ func TestBeaconProposerIndex_EmptyCommittee(t *testing.T) {
ClearAllCaches()
beaconState := &pb.BeaconState{
Slot: 0,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
_, err := BeaconProposerIndex(beaconState)
expected := fmt.Sprintf("empty first committee at slot %d", 0)
@@ -136,9 +136,9 @@ func TestChurnLimit_OK(t *testing.T) {
beaconState := &pb.BeaconState{
Slot: 1,
ValidatorRegistry: validators,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
resultChurn, err := ChurnLimit(beaconState)
if err != nil {

View File

@@ -44,14 +44,14 @@ import (
//
// return state
func GenesisBeaconState(deposits []*pb.Deposit, genesisTime uint64, eth1Data *pb.Eth1Data) (*pb.BeaconState, error) {
latestRandaoMixes := make([][]byte, params.BeaconConfig().LatestRandaoMixesLength)
latestRandaoMixes := make([][]byte, params.BeaconConfig().RandaoMixesLength)
for i := 0; i < len(latestRandaoMixes); i++ {
latestRandaoMixes[i] = make([]byte, 32)
}
zeroHash := params.BeaconConfig().ZeroHash[:]
latestActiveIndexRoots := make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength)
latestActiveIndexRoots := make([][]byte, params.BeaconConfig().ActiveIndexRootsLength)
for i := 0; i < len(latestActiveIndexRoots); i++ {
latestActiveIndexRoots[i] = zeroHash
}
@@ -68,7 +68,7 @@ func GenesisBeaconState(deposits []*pb.Deposit, genesisTime uint64, eth1Data *pb
latestBlockRoots[i] = zeroHash
}
latestSlashedExitBalances := make([]uint64, params.BeaconConfig().LatestSlashedExitLength)
latestSlashedExitBalances := make([]uint64, params.BeaconConfig().SlashedExitLength)
if eth1Data == nil {
eth1Data = &pb.Eth1Data{}
@@ -86,11 +86,11 @@ func GenesisBeaconState(deposits []*pb.Deposit, genesisTime uint64, eth1Data *pb
},
// Validator registry fields.
ValidatorRegistry: []*pb.Validator{},
Validators: []*pb.Validator{},
Balances: []uint64{},
// Randomness and committees.
LatestRandaoMixes: latestRandaoMixes,
RandaoMixes: latestRandaoMixes,
// Finality.
PreviousJustifiedEpoch: 0,
@@ -104,16 +104,16 @@ func GenesisBeaconState(deposits []*pb.Deposit, genesisTime uint64, eth1Data *pb
// Recent state.
CurrentCrosslinks: crosslinks,
PreviousCrosslinks: crosslinks,
LatestActiveIndexRoots: latestActiveIndexRoots,
LatestBlockRoots: latestBlockRoots,
LatestSlashedBalances: latestSlashedExitBalances,
ActiveIndexRoots: latestActiveIndexRoots,
BlockRoots: latestBlockRoots,
SlashedBalances: latestSlashedExitBalances,
CurrentEpochAttestations: []*pb.PendingAttestation{},
PreviousEpochAttestations: []*pb.PendingAttestation{},
// Eth1 data.
LatestEth1Data: eth1Data,
Eth1Data: eth1Data,
Eth1DataVotes: []*pb.Eth1Data{},
DepositIndex: 0,
Eth1DepositIndex: 0,
}
// Process initial deposits.
@@ -132,8 +132,8 @@ func GenesisBeaconState(deposits []*pb.Deposit, genesisTime uint64, eth1Data *pb
return nil, fmt.Errorf("could not process validator deposit: %v", err)
}
}
for i := 0; i < len(state.ValidatorRegistry); i++ {
if state.ValidatorRegistry[i].EffectiveBalance >=
for i := 0; i < len(state.Validators); i++ {
if state.Validators[i].EffectiveBalance >=
params.BeaconConfig().MaxDepositAmount {
state, err = v.ActivateValidator(state, uint64(i), true)
if err != nil {
@@ -153,8 +153,8 @@ func GenesisBeaconState(deposits []*pb.Deposit, genesisTime uint64, eth1Data *pb
indicesBytes = append(indicesBytes, buf...)
}
genesisActiveIndexRoot := hashutil.Hash(indicesBytes)
for i := uint64(0); i < params.BeaconConfig().LatestActiveIndexRootsLength; i++ {
state.LatestActiveIndexRoots[i] = genesisActiveIndexRoot[:]
for i := uint64(0); i < params.BeaconConfig().ActiveIndexRootsLength; i++ {
state.ActiveIndexRoots[i] = genesisActiveIndexRoot[:]
}
return state, nil
}

View File

@@ -38,10 +38,10 @@ func TestGenesisBeaconState_OK(t *testing.T) {
t.Error("ZeroHash should be all 0s for these tests to pass")
}
if params.BeaconConfig().LatestRandaoMixesLength != 8192 {
t.Error("LatestRandaoMixesLength should be 8192 for these tests to pass")
if params.BeaconConfig().RandaoMixesLength != 8192 {
t.Error("RandaoMixesLength should be 8192 for these tests to pass")
}
latestRandaoMixesLength := int(params.BeaconConfig().LatestRandaoMixesLength)
latestRandaoMixesLength := int(params.BeaconConfig().RandaoMixesLength)
if params.BeaconConfig().ShardCount != 1024 {
t.Error("ShardCount should be 1024 for these tests to pass")
@@ -57,8 +57,8 @@ func TestGenesisBeaconState_OK(t *testing.T) {
}
depositsForChainStart := int(params.BeaconConfig().DepositsForChainStart)
if params.BeaconConfig().LatestSlashedExitLength != 8192 {
t.Error("LatestSlashedExitLength should be 8192 for these tests to pass")
if params.BeaconConfig().SlashedExitLength != 8192 {
t.Error("slashed exit length should be 8192 for these tests to pass")
}
genesisTime := uint64(99999)
@@ -90,16 +90,16 @@ func TestGenesisBeaconState_OK(t *testing.T) {
}
// Validator registry fields checks.
if len(newState.ValidatorRegistry) != depositsForChainStart {
t.Error("ValidatorRegistry was not correctly initialized")
if len(newState.Validators) != depositsForChainStart {
t.Error("Validators was not correctly initialized")
}
if len(newState.Balances) != depositsForChainStart {
t.Error("Balances was not correctly initialized")
}
// Randomness and committees fields checks.
if len(newState.LatestRandaoMixes) != latestRandaoMixesLength {
t.Error("Length of LatestRandaoMixes was not correctly initialized")
if len(newState.RandaoMixes) != latestRandaoMixesLength {
t.Error("Length of RandaoMixes was not correctly initialized")
}
// Finality fields checks.
@@ -123,8 +123,8 @@ func TestGenesisBeaconState_OK(t *testing.T) {
if len(newState.PreviousCrosslinks) != shardCount {
t.Error("Length of PreviousCrosslinks was not correctly initialized")
}
if !reflect.DeepEqual(newState.LatestSlashedBalances, make([]uint64, params.BeaconConfig().LatestSlashedExitLength)) {
t.Error("LatestSlashedBalances was not correctly initialized")
if !reflect.DeepEqual(newState.SlashedBalances, make([]uint64, params.BeaconConfig().SlashedExitLength)) {
t.Error("SlashedBalances was not correctly initialized")
}
if !reflect.DeepEqual(newState.CurrentEpochAttestations, []*pb.PendingAttestation{}) {
t.Error("CurrentEpochAttestations was not correctly initialized")
@@ -141,21 +141,21 @@ func TestGenesisBeaconState_OK(t *testing.T) {
indicesBytes = append(indicesBytes, buf...)
}
genesisActiveIndexRoot := hashutil.Hash(indicesBytes)
if !bytes.Equal(newState.LatestActiveIndexRoots[0], genesisActiveIndexRoot[:]) {
if !bytes.Equal(newState.ActiveIndexRoots[0], genesisActiveIndexRoot[:]) {
t.Errorf(
"Expected index roots to be the tree hash root of active validator indices, received %#x",
newState.LatestActiveIndexRoots[0],
newState.ActiveIndexRoots[0],
)
}
if !bytes.Equal(newState.LatestActiveIndexRoots[0], genesisActiveIndexRoot[:]) {
if !bytes.Equal(newState.ActiveIndexRoots[0], genesisActiveIndexRoot[:]) {
t.Errorf(
"Expected index roots to be the tree hash root of active validator indices, received %#x",
newState.LatestActiveIndexRoots[0],
newState.ActiveIndexRoots[0],
)
}
// deposit root checks.
if !bytes.Equal(newState.LatestEth1Data.DepositRoot, eth1Data.DepositRoot) {
t.Error("LatestEth1Data DepositRoot was not correctly initialized")
if !bytes.Equal(newState.Eth1Data.DepositRoot, eth1Data.DepositRoot) {
t.Error("Eth1Data DepositRoot was not correctly initialized")
}
if !reflect.DeepEqual(newState.Eth1DataVotes, []*pb.Eth1Data{}) {
t.Error("Eth1DataVotes was not correctly initialized")
@@ -180,17 +180,17 @@ func TestGenesisState_HashEquality(t *testing.T) {
func TestGenesisState_InitializesLatestBlockHashes(t *testing.T) {
s, _ := state.GenesisBeaconState(nil, 0, nil)
want, got := len(s.LatestBlockRoots), int(params.BeaconConfig().SlotsPerHistoricalRoot)
want, got := len(s.BlockRoots), int(params.BeaconConfig().SlotsPerHistoricalRoot)
if want != got {
t.Errorf("Wrong number of recent block hashes. Got: %d Want: %d", got, want)
}
want = cap(s.LatestBlockRoots)
want = cap(s.BlockRoots)
if want != got {
t.Errorf("The slice underlying array capacity is wrong. Got: %d Want: %d", got, want)
}
for _, h := range s.LatestBlockRoots {
for _, h := range s.BlockRoots {
if !bytes.Equal(h, params.BeaconConfig().ZeroHash[:]) {
t.Errorf("Unexpected non-zero hash data: %v", h)
}

View File

@@ -9,7 +9,7 @@ import (
// a validator by their public key.
func ValidatorIndexMap(state *pb.BeaconState) map[[32]byte]int {
m := make(map[[32]byte]int)
for idx, record := range state.ValidatorRegistry {
for idx, record := range state.Validators {
key := bytesutil.ToBytes32(record.Pubkey)
m[key] = idx
}

View File

@@ -10,7 +10,7 @@ import (
func TestValidatorIndexMap_OK(t *testing.T) {
state := &pb.BeaconState{
ValidatorRegistry: []*pb.Validator{
Validators: []*pb.Validator{
{
Pubkey: []byte("zero"),
},

View File

@@ -85,7 +85,7 @@ func ProcessSlot(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState, e
if err != nil {
return nil, fmt.Errorf("could not tree hash prev state root: %v", err)
}
state.LatestStateRoots[state.Slot%params.BeaconConfig().SlotsPerHistoricalRoot] = prevStateRoot[:]
state.StateRoots[state.Slot%params.BeaconConfig().SlotsPerHistoricalRoot] = prevStateRoot[:]
zeroHash := params.BeaconConfig().ZeroHash
// Cache latest block header state root.
@@ -97,7 +97,7 @@ func ProcessSlot(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState, e
return nil, fmt.Errorf("could not determine prev block root: %v", err)
}
// Cache the block root.
state.LatestBlockRoots[state.Slot%params.BeaconConfig().SlotsPerHistoricalRoot] = prevBlockRoot[:]
state.BlockRoots[state.Slot%params.BeaconConfig().SlotsPerHistoricalRoot] = prevBlockRoot[:]
return state, nil
}

View File

@@ -157,7 +157,7 @@ func TestProcessBlock_IncorrectProcessBlockAttestations(t *testing.T) {
if err != nil {
t.Fatal(err)
}
beaconState.LatestSlashedBalances = make([]uint64, params.BeaconConfig().LatestSlashedExitLength)
beaconState.SlashedBalances = make([]uint64, params.BeaconConfig().SlashedExitLength)
proposerSlashings := []*pb.ProposerSlashing{
{
ProposerIndex: 3,
@@ -247,7 +247,7 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
if err != nil {
t.Fatal(err)
}
beaconState.LatestSlashedBalances = make([]uint64, params.BeaconConfig().LatestSlashedExitLength)
beaconState.SlashedBalances = make([]uint64, params.BeaconConfig().SlashedExitLength)
proposerSlashings := []*pb.ProposerSlashing{
{
ProposerIndex: 3,
@@ -287,7 +287,7 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
for i := uint64(0); i < params.BeaconConfig().SlotsPerHistoricalRoot; i++ {
blockRoots = append(blockRoots, []byte{byte(i)})
}
beaconState.LatestBlockRoots = blockRoots
beaconState.BlockRoots = blockRoots
beaconState.CurrentCrosslinks = []*pb.Crosslink{
{
DataRoot: []byte{1},
@@ -378,7 +378,7 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
ParentRoot: genesisBlock.ParentRoot,
BodyRoot: bodyRoot[:],
}
beaconState.LatestSlashedBalances = make([]uint64, params.BeaconConfig().LatestSlashedExitLength)
beaconState.SlashedBalances = make([]uint64, params.BeaconConfig().SlashedExitLength)
proposerSlashings := []*pb.ProposerSlashing{
{
ProposerIndex: 3,
@@ -420,7 +420,7 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
for i := uint64(0); i < params.BeaconConfig().SlotsPerHistoricalRoot; i++ {
blockRoots = append(blockRoots, []byte{byte(i)})
}
beaconState.LatestBlockRoots = blockRoots
beaconState.BlockRoots = blockRoots
beaconState.CurrentCrosslinks = []*pb.Crosslink{
{
DataRoot: []byte{1},
@@ -501,9 +501,9 @@ func TestProcessEpoch_CantGetTgtAttsCurrEpoch(t *testing.T) {
atts := []*pb.PendingAttestation{{Data: &pb.AttestationData{Crosslink: &pb.Crosslink{Shard: 100}}}}
_, err := state.ProcessEpoch(context.Background(), &pb.BeaconState{
Slot: epoch * params.BeaconConfig().SlotsPerEpoch,
LatestBlockRoots: make([][]byte, 128),
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
BlockRoots: make([][]byte, 128),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
CurrentEpochAttestations: atts})
if !strings.Contains(err.Error(), "could not get target atts current epoch") {
t.Fatal("Did not receive wanted error")
@@ -518,9 +518,9 @@ func TestProcessEpoch_CantGetAttsBalancePrevEpoch(t *testing.T) {
atts := []*pb.PendingAttestation{{Data: &pb.AttestationData{Crosslink: &pb.Crosslink{Shard: 961}}, AggregationBitfield: []byte{1}}}
_, err := state.ProcessEpoch(context.Background(), &pb.BeaconState{
Slot: epoch*params.BeaconConfig().SlotsPerEpoch + 1,
LatestBlockRoots: make([][]byte, 128),
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
BlockRoots: make([][]byte, 128),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
PreviousEpochAttestations: atts})
if !strings.Contains(err.Error(), "could not get attesting balance prev epoch") {
t.Fatal("Did not receive wanted error")
@@ -533,9 +533,9 @@ func TestProcessEpoch_CantGetAttsBalanceCurrentEpoch(t *testing.T) {
atts := []*pb.PendingAttestation{{Data: &pb.AttestationData{Crosslink: &pb.Crosslink{Shard: 961}}, AggregationBitfield: []byte{1}}}
_, err := state.ProcessEpoch(context.Background(), &pb.BeaconState{
Slot: epoch*params.BeaconConfig().SlotsPerEpoch + 1,
LatestBlockRoots: make([][]byte, 128),
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
BlockRoots: make([][]byte, 128),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
CurrentEpochAttestations: atts})
if !strings.Contains(err.Error(), "could not get attesting balance current epoch") {
t.Fatal("Did not receive wanted error")
@@ -555,10 +555,10 @@ func TestProcessEpoch_CanProcess(t *testing.T) {
}
newState, err := state.ProcessEpoch(context.Background(), &pb.BeaconState{
Slot: epoch*params.BeaconConfig().SlotsPerEpoch + 1,
LatestBlockRoots: make([][]byte, 128),
LatestSlashedBalances: []uint64{0, 1e9, 0},
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
BlockRoots: make([][]byte, 128),
SlashedBalances: []uint64{0, 1e9, 0},
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
CurrentCrosslinks: crosslinks,
CurrentEpochAttestations: atts})
if err != nil {
@@ -566,16 +566,16 @@ func TestProcessEpoch_CanProcess(t *testing.T) {
}
wanted := uint64(1e9)
if newState.LatestSlashedBalances[2] != wanted {
if newState.SlashedBalances[2] != wanted {
t.Errorf("Wanted slashed balance: %d, got: %d", wanted, newState.Balances[2])
}
}
func TestProcessEpoch_NotPanicOnEmptyActiveValidatorIndices(t *testing.T) {
newState := &pb.BeaconState{
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
LatestSlashedBalances: make([]uint64, params.BeaconConfig().LatestSlashedExitLength),
LatestRandaoMixes: make([][]byte, params.BeaconConfig().SlotsPerEpoch),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
SlashedBalances: make([]uint64, params.BeaconConfig().SlashedExitLength),
RandaoMixes: make([][]byte, params.BeaconConfig().SlotsPerEpoch),
}
config := state.DefaultConfig()
config.Logging = true
@@ -626,13 +626,13 @@ func BenchmarkProcessEpoch65536Validators(b *testing.B) {
s := &pb.BeaconState{
Slot: epoch*params.BeaconConfig().SlotsPerEpoch + 1,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
LatestStartShard: 512,
LatestBlockRoots: make([][]byte, 254),
LatestSlashedBalances: []uint64{0, 1e9, 0},
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
StartShard: 512,
BlockRoots: make([][]byte, 254),
SlashedBalances: []uint64{0, 1e9, 0},
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
CurrentCrosslinks: crosslinks,
PreviousEpochAttestations: atts,
}
@@ -675,7 +675,7 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
validatorBalances[i] = params.BeaconConfig().MaxDepositAmount
}
randaoMixes := make([][]byte, params.BeaconConfig().LatestRandaoMixesLength)
randaoMixes := make([][]byte, params.BeaconConfig().RandaoMixesLength)
for i := 0; i < len(randaoMixes); i++ {
randaoMixes[i] = params.BeaconConfig().ZeroHash[:]
}
@@ -690,12 +690,12 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
s := &pb.BeaconState{
Slot: 20,
LatestBlockRoots: make([][]byte, 254),
LatestRandaoMixes: randaoMixes,
ValidatorRegistry: validators,
BlockRoots: make([][]byte, 254),
RandaoMixes: randaoMixes,
Validators: validators,
Balances: validatorBalances,
LatestSlashedBalances: make([]uint64, params.BeaconConfig().LatestSlashedExitLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
SlashedBalances: make([]uint64, params.BeaconConfig().SlashedExitLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
CurrentJustifiedRoot: []byte("hello-world"),
Fork: &pb.Fork{
PreviousVersion: []byte{0, 0, 0, 0},
@@ -778,7 +778,7 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
if err != nil {
b.Fatal(err)
}
s.ValidatorRegistry[proposerIdx].Pubkey = priv.PublicKey().Marshal()
s.Validators[proposerIdx].Pubkey = priv.PublicKey().Marshal()
buf := make([]byte, 32)
binary.LittleEndian.PutUint64(buf, 0)
domain := helpers.DomainVersion(s, 0, params.BeaconConfig().DomainRandao)
@@ -799,7 +799,7 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
pubKey := []byte("A")
hashed := hashutil.Hash(pubKey)
buf = append(buf, hashed[:]...)
s.ValidatorRegistry[3].WithdrawalCredentials = buf
s.Validators[3].WithdrawalCredentials = buf
// Set up attestations obj for block.
encoded, err := ssz.HashTreeRoot(s.CurrentCrosslinks[0])
@@ -853,8 +853,8 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
b.Fatal(err)
}
// Reset state fields to process block again
s.ValidatorRegistry[1].Slashed = false
s.ValidatorRegistry[2].Slashed = false
s.Validators[1].Slashed = false
s.Validators[2].Slashed = false
s.Balances[3] += 2 * params.BeaconConfig().MinDepositAmount
}
}

View File

@@ -43,7 +43,7 @@ var VStore = validatorStore{
//
// validator.activation_epoch = GENESIS_EPOCH if is_genesis else get_entry_exit_effect_epoch(get_current_epoch(state))
func ActivateValidator(state *pb.BeaconState, idx uint64, genesis bool) (*pb.BeaconState, error) {
validator := state.ValidatorRegistry[idx]
validator := state.Validators[idx]
if genesis {
validator.ActivationEligibilityEpoch = 0
validator.ActivationEpoch = 0
@@ -51,7 +51,7 @@ func ActivateValidator(state *pb.BeaconState, idx uint64, genesis bool) (*pb.Bea
validator.ActivationEpoch = helpers.DelayedActivationExitEpoch(helpers.CurrentEpoch(state))
}
state.ValidatorRegistry[idx] = validator
state.Validators[idx] = validator
log.WithFields(logrus.Fields{
"index": idx,
@@ -85,12 +85,12 @@ func ActivateValidator(state *pb.BeaconState, idx uint64, genesis bool) (*pb.Bea
// validator.exit_epoch = exit_queue_epoch
// validator.withdrawable_epoch = validator.exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY
func InitiateValidatorExit(state *pb.BeaconState, idx uint64) (*pb.BeaconState, error) {
validator := state.ValidatorRegistry[idx]
validator := state.Validators[idx]
if validator.ExitEpoch != params.BeaconConfig().FarFutureEpoch {
return state, nil
}
exitEpochs := []uint64{}
for _, val := range state.ValidatorRegistry {
for _, val := range state.Validators {
if val.ExitEpoch != params.BeaconConfig().FarFutureEpoch {
exitEpochs = append(exitEpochs, val.ExitEpoch)
}
@@ -107,7 +107,7 @@ func InitiateValidatorExit(state *pb.BeaconState, idx uint64) (*pb.BeaconState,
// We use the exit queue churn to determine if we have passed a churn limit.
exitQueueChurn := 0
for _, val := range state.ValidatorRegistry {
for _, val := range state.Validators {
if val.ExitEpoch == exitQueueEpoch {
exitQueueChurn++
}
@@ -120,8 +120,8 @@ func InitiateValidatorExit(state *pb.BeaconState, idx uint64) (*pb.BeaconState,
if uint64(exitQueueChurn) >= churn {
exitQueueEpoch++
}
state.ValidatorRegistry[idx].ExitEpoch = exitQueueEpoch
state.ValidatorRegistry[idx].WithdrawableEpoch = exitQueueEpoch + params.BeaconConfig().MinValidatorWithdrawalDelay
state.Validators[idx].ExitEpoch = exitQueueEpoch
state.Validators[idx].WithdrawableEpoch = exitQueueEpoch + params.BeaconConfig().MinValidatorWithdrawalDelay
return state, nil
}
@@ -142,7 +142,7 @@ func InitiateValidatorExit(state *pb.BeaconState, idx uint64) (*pb.BeaconState,
//
// validator.exit_epoch = get_entry_exit_effect_epoch(get_current_epoch(state))
func ExitValidator(state *pb.BeaconState, idx uint64) *pb.BeaconState {
validator := state.ValidatorRegistry[idx]
validator := state.Validators[idx]
if validator.ExitEpoch != params.BeaconConfig().FarFutureEpoch {
return state
@@ -178,10 +178,10 @@ func ExitValidator(state *pb.BeaconState, idx uint64) *pb.BeaconState {
func SlashValidator(state *pb.BeaconState, slashedIdx uint64, whistleBlowerIdx uint64) (*pb.BeaconState, error) {
state = ExitValidator(state, slashedIdx)
currentEpoch := helpers.CurrentEpoch(state)
state.ValidatorRegistry[slashedIdx].Slashed = true
state.ValidatorRegistry[slashedIdx].WithdrawableEpoch = currentEpoch + params.BeaconConfig().LatestSlashedExitLength
slashedBalance := state.ValidatorRegistry[slashedIdx].EffectiveBalance
state.LatestSlashedBalances[currentEpoch%params.BeaconConfig().LatestSlashedExitLength] += slashedBalance
state.Validators[slashedIdx].Slashed = true
state.Validators[slashedIdx].WithdrawableEpoch = currentEpoch + params.BeaconConfig().SlashedExitLength
slashedBalance := state.Validators[slashedIdx].EffectiveBalance
state.SlashedBalances[currentEpoch%params.BeaconConfig().SlashedExitLength] += slashedBalance
proposerIdx, err := helpers.BeaconProposerIndex(state)
if err != nil {

View File

@@ -48,7 +48,7 @@ func TestHasVoted_OK(t *testing.T) {
func TestActivateValidatorGenesis_OK(t *testing.T) {
state := &pb.BeaconState{
ValidatorRegistry: []*pb.Validator{
Validators: []*pb.Validator{
{Pubkey: []byte{'A'}},
},
}
@@ -56,20 +56,20 @@ func TestActivateValidatorGenesis_OK(t *testing.T) {
if err != nil {
t.Fatalf("could not execute activateValidator:%v", err)
}
if newState.ValidatorRegistry[0].ActivationEpoch != 0 {
if newState.Validators[0].ActivationEpoch != 0 {
t.Errorf("Wanted activation epoch = genesis epoch, got %d",
newState.ValidatorRegistry[0].ActivationEpoch)
newState.Validators[0].ActivationEpoch)
}
if newState.ValidatorRegistry[0].ActivationEligibilityEpoch != 0 {
if newState.Validators[0].ActivationEligibilityEpoch != 0 {
t.Errorf("Wanted activation eligibility epoch = genesis epoch, got %d",
newState.ValidatorRegistry[0].ActivationEligibilityEpoch)
newState.Validators[0].ActivationEligibilityEpoch)
}
}
func TestActivateValidator_OK(t *testing.T) {
state := &pb.BeaconState{
Slot: 100, // epoch 2
ValidatorRegistry: []*pb.Validator{
Validators: []*pb.Validator{
{Pubkey: []byte{'A'}},
},
}
@@ -79,32 +79,32 @@ func TestActivateValidator_OK(t *testing.T) {
}
currentEpoch := helpers.CurrentEpoch(state)
wantedEpoch := helpers.DelayedActivationExitEpoch(currentEpoch)
if newState.ValidatorRegistry[0].ActivationEpoch != wantedEpoch {
if newState.Validators[0].ActivationEpoch != wantedEpoch {
t.Errorf("Wanted activation slot = %d, got %d",
wantedEpoch,
newState.ValidatorRegistry[0].ActivationEpoch)
newState.Validators[0].ActivationEpoch)
}
}
func TestInitiateValidatorExit_AlreadyExited(t *testing.T) {
exitEpoch := uint64(199)
state := &pb.BeaconState{ValidatorRegistry: []*pb.Validator{{
state := &pb.BeaconState{Validators: []*pb.Validator{{
ExitEpoch: exitEpoch},
}}
newState, err := InitiateValidatorExit(state, 0)
if err != nil {
t.Fatal(err)
}
if newState.ValidatorRegistry[0].ExitEpoch != exitEpoch {
if newState.Validators[0].ExitEpoch != exitEpoch {
t.Errorf("Already exited, wanted exit epoch %d, got %d",
exitEpoch, newState.ValidatorRegistry[0].ExitEpoch)
exitEpoch, newState.Validators[0].ExitEpoch)
}
}
func TestInitiateValidatorExit_ProperExit(t *testing.T) {
exitedEpoch := uint64(100)
idx := uint64(3)
state := &pb.BeaconState{ValidatorRegistry: []*pb.Validator{
state := &pb.BeaconState{Validators: []*pb.Validator{
{ExitEpoch: exitedEpoch},
{ExitEpoch: exitedEpoch + 1},
{ExitEpoch: exitedEpoch + 2},
@@ -114,16 +114,16 @@ func TestInitiateValidatorExit_ProperExit(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if newState.ValidatorRegistry[idx].ExitEpoch != exitedEpoch+2 {
if newState.Validators[idx].ExitEpoch != exitedEpoch+2 {
t.Errorf("Exit epoch was not the highest, wanted exit epoch %d, got %d",
exitedEpoch+2, newState.ValidatorRegistry[idx].ExitEpoch)
exitedEpoch+2, newState.Validators[idx].ExitEpoch)
}
}
func TestInitiateValidatorExit_ChurnOverflow(t *testing.T) {
exitedEpoch := uint64(100)
idx := uint64(4)
state := &pb.BeaconState{ValidatorRegistry: []*pb.Validator{
state := &pb.BeaconState{Validators: []*pb.Validator{
{ExitEpoch: exitedEpoch + 2},
{ExitEpoch: exitedEpoch + 2},
{ExitEpoch: exitedEpoch + 2},
@@ -137,19 +137,19 @@ func TestInitiateValidatorExit_ChurnOverflow(t *testing.T) {
// Because of exit queue overflow,
// validator who init exited has to wait one more epoch.
wantedEpoch := state.ValidatorRegistry[0].ExitEpoch + 1
wantedEpoch := state.Validators[0].ExitEpoch + 1
if newState.ValidatorRegistry[idx].ExitEpoch != wantedEpoch {
if newState.Validators[idx].ExitEpoch != wantedEpoch {
t.Errorf("Exit epoch did not cover overflow case, wanted exit epoch %d, got %d",
wantedEpoch, newState.ValidatorRegistry[idx].ExitEpoch)
wantedEpoch, newState.Validators[idx].ExitEpoch)
}
}
func TestExitValidator_OK(t *testing.T) {
state := &pb.BeaconState{
Slot: 100, // epoch 2
LatestSlashedBalances: []uint64{0},
ValidatorRegistry: []*pb.Validator{
SlashedBalances: []uint64{0},
Validators: []*pb.Validator{
{ExitEpoch: params.BeaconConfig().FarFutureEpoch, Pubkey: []byte{'B'}},
},
}
@@ -157,22 +157,22 @@ func TestExitValidator_OK(t *testing.T) {
currentEpoch := helpers.CurrentEpoch(state)
wantedEpoch := helpers.DelayedActivationExitEpoch(currentEpoch)
if newState.ValidatorRegistry[0].ExitEpoch != wantedEpoch {
if newState.Validators[0].ExitEpoch != wantedEpoch {
t.Errorf("Wanted exit slot %d, got %d",
wantedEpoch,
newState.ValidatorRegistry[0].ExitEpoch)
newState.Validators[0].ExitEpoch)
}
}
func TestExitValidator_AlreadyExited(t *testing.T) {
state := &pb.BeaconState{
Slot: 1000,
ValidatorRegistry: []*pb.Validator{
Validators: []*pb.Validator{
{ExitEpoch: params.BeaconConfig().ActivationExitDelay},
},
}
state = ExitValidator(state, 0)
if state.ValidatorRegistry[0].ExitEpoch != params.BeaconConfig().ActivationExitDelay {
if state.Validators[0].ExitEpoch != params.BeaconConfig().ActivationExitDelay {
t.Error("Expected exited validator to stay exited")
}
}
@@ -191,7 +191,7 @@ func TestInitializeValidatoreStore(t *testing.T) {
}
bState := &pb.BeaconState{
ValidatorRegistry: registry,
Validators: registry,
Slot: 0,
}

View File

@@ -78,7 +78,7 @@ func (db *BeaconDB) InitializeState(ctx context.Context, genesisTime uint64, dep
return err
}
for i, validator := range beaconState.ValidatorRegistry {
for i, validator := range beaconState.Validators {
h := hashutil.Hash(validator.Pubkey)
buf := make([]byte, binary.MaxVarintLen64)
n := binary.PutUvarint(buf, uint64(i))
@@ -168,10 +168,10 @@ func (db *BeaconDB) SaveState(ctx context.Context, beaconState *pb.BeaconState)
}
stateHash := hashutil.Hash(enc)
tempState := &pb.BeaconState{}
tempState.ValidatorRegistry = beaconState.ValidatorRegistry
tempState.Validators = beaconState.Validators
copy(db.validatorBalances, beaconState.Balances)
db.validatorRegistry = proto.Clone(tempState).(*pb.BeaconState).ValidatorRegistry
db.validatorRegistry = proto.Clone(tempState).(*pb.BeaconState).Validators
db.serializedState = enc
db.stateHash = stateHash
@@ -345,9 +345,9 @@ func (db *BeaconDB) HistoricalStateFromSlot(ctx context.Context, slot uint64, bl
return beaconState, err
}
// ValidatorRegistry fetches the current validator registry stored in state.
func (db *BeaconDB) ValidatorRegistry(ctx context.Context) ([]*pb.Validator, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.ValidatorRegistry")
// Validators fetches the current validator registry stored in state.
func (db *BeaconDB) Validators(ctx context.Context) ([]*pb.Validator, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.Validators")
defer span.End()
db.stateLock.RLock()
@@ -355,13 +355,13 @@ func (db *BeaconDB) ValidatorRegistry(ctx context.Context) ([]*pb.Validator, err
// Return in-memory cached state, if available.
if db.validatorRegistry != nil {
_, span := trace.StartSpan(ctx, "proto.Clone.ValidatorRegistry")
_, span := trace.StartSpan(ctx, "proto.Clone.Validators")
defer span.End()
tempState := &pb.BeaconState{
ValidatorRegistry: db.validatorRegistry,
Validators: db.validatorRegistry,
}
newState := proto.Clone(tempState).(*pb.BeaconState)
return newState.ValidatorRegistry, nil
return newState.Validators, nil
}
var beaconState *pb.BeaconState
@@ -380,7 +380,7 @@ func (db *BeaconDB) ValidatorRegistry(ctx context.Context) ([]*pb.Validator, err
return err
})
return beaconState.ValidatorRegistry, err
return beaconState.Validators, err
}
// ValidatorFromState fetches the validator with the desired index from the cached registry.
@@ -421,7 +421,7 @@ func (db *BeaconDB) ValidatorFromState(ctx context.Context, index uint64) (*pb.V
return nil, fmt.Errorf("invalid validator index %d", index)
}
return beaconState.ValidatorRegistry[index], err
return beaconState.Validators[index], err
}
// Balances fetches the current validator balances stored in state.

View File

@@ -62,12 +62,12 @@ func reportStateMetrics(state *pb.BeaconState) {
// Validator balances
for i, bal := range state.Balances {
validatorBalancesGauge.WithLabelValues(
"0x" + hex.EncodeToString(state.ValidatorRegistry[i].Pubkey), // Validator
"0x" + hex.EncodeToString(state.Validators[i].Pubkey), // Validator
).Set(float64(bal))
}
var active float64
for i, v := range state.ValidatorRegistry {
for i, v := range state.Validators {
// Track individual Validator's activation epochs
validatorActivatedGauge.WithLabelValues(
strconv.Itoa(i), //Validator index
@@ -80,7 +80,7 @@ func reportStateMetrics(state *pb.BeaconState) {
if v.Slashed {
validatorSlashedGauge.WithLabelValues(
strconv.Itoa(i), //Validator index
).Set(float64(v.WithdrawableEpoch - params.BeaconConfig().LatestSlashedExitLength))
).Set(float64(v.WithdrawableEpoch - params.BeaconConfig().SlashedExitLength))
} else {
validatorSlashedGauge.WithLabelValues(
strconv.Itoa(i), //Validator index

View File

@@ -47,8 +47,8 @@ func (db *BeaconDB) ValidatorIndex(pubKey []byte) (uint64, error) {
if err != nil {
return 0, err
}
for i := 0; i < len(state.ValidatorRegistry); i++ {
v := state.ValidatorRegistry[i]
for i := 0; i < len(state.Validators); i++ {
v := state.Validators[i]
if bytes.Equal(v.Pubkey, pubKey) {
if err := db.SaveValidatorIndex(pubKey, i); err != nil {
return 0, err
@@ -119,8 +119,8 @@ func (db *BeaconDB) HasAnyValidators(state *pb.BeaconState, pubKeys [][]byte) (b
if !exists {
for _, pubKey := range pubKeys {
for i := 0; i < len(state.ValidatorRegistry); i++ {
v := state.ValidatorRegistry[i]
for i := 0; i < len(state.Validators); i++ {
v := state.Validators[i]
if bytes.Equal(v.Pubkey, pubKey) {
if err := db.SaveValidatorIndex(pubKey, i); err != nil {
return false, err

View File

@@ -125,7 +125,7 @@ func TestHasAnyValidator(t *testing.T) {
}
beaconState := &pb.BeaconState{
ValidatorRegistry: []*pb.Validator{},
Validators: []*pb.Validator{},
}
has, err := db.HasAnyValidators(beaconState, append(knownPubKeys, unknownPubKeys...))

View File

@@ -221,8 +221,8 @@ func (w *Web3Service) processPastLogs() error {
if err != nil {
return fmt.Errorf("could not get head state: %v", err)
}
if currentState != nil && currentState.DepositIndex > 0 {
w.beaconDB.PrunePendingDeposits(w.ctx, currentState.DepositIndex)
if currentState != nil && currentState.Eth1DepositIndex > 0 {
w.beaconDB.PrunePendingDeposits(w.ctx, currentState.Eth1DepositIndex)
}
return nil

View File

@@ -53,9 +53,9 @@ func TestSubmitAttestation_OK(t *testing.T) {
state := &pbp2p.BeaconState{
Slot: params.BeaconConfig().SlotsPerEpoch + 1,
ValidatorRegistry: validators,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
if err := db.SaveState(context.Background(), state); err != nil {
@@ -106,7 +106,7 @@ func TestRequestAttestation_OK(t *testing.T) {
beaconState := &pbp2p.BeaconState{
Slot: 3*params.BeaconConfig().SlotsPerEpoch + 1,
CurrentJustifiedEpoch: 2 + 0,
LatestBlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot),
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot),
CurrentCrosslinks: []*pbp2p.Crosslink{
{
DataRoot: []byte("A"),
@@ -119,9 +119,9 @@ func TestRequestAttestation_OK(t *testing.T) {
},
CurrentJustifiedRoot: justifiedRoot[:],
}
beaconState.LatestBlockRoots[1] = blockRoot[:]
beaconState.LatestBlockRoots[1*params.BeaconConfig().SlotsPerEpoch] = targetRoot[:]
beaconState.LatestBlockRoots[2*params.BeaconConfig().SlotsPerEpoch] = justifiedRoot[:]
beaconState.BlockRoots[1] = blockRoot[:]
beaconState.BlockRoots[1*params.BeaconConfig().SlotsPerEpoch] = targetRoot[:]
beaconState.BlockRoots[2*params.BeaconConfig().SlotsPerEpoch] = justifiedRoot[:]
attesterServer := &AttesterServer{
beaconDB: db,
p2p: &mockBroadcaster{},
@@ -216,7 +216,7 @@ func TestAttestationDataAtSlot_handlesFarAwayJustifiedEpoch(t *testing.T) {
beaconState := &pbp2p.BeaconState{
Slot: 10000,
CurrentJustifiedEpoch: helpers.SlotToEpoch(1500),
LatestBlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot),
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot),
PreviousCrosslinks: []*pbp2p.Crosslink{
{
DataRoot: []byte("A"),
@@ -229,9 +229,9 @@ func TestAttestationDataAtSlot_handlesFarAwayJustifiedEpoch(t *testing.T) {
},
CurrentJustifiedRoot: justifiedBlockRoot[:],
}
beaconState.LatestBlockRoots[1] = blockRoot[:]
beaconState.LatestBlockRoots[1*params.BeaconConfig().SlotsPerEpoch] = epochBoundaryRoot[:]
beaconState.LatestBlockRoots[2*params.BeaconConfig().SlotsPerEpoch] = justifiedBlockRoot[:]
beaconState.BlockRoots[1] = blockRoot[:]
beaconState.BlockRoots[1*params.BeaconConfig().SlotsPerEpoch] = epochBoundaryRoot[:]
beaconState.BlockRoots[2*params.BeaconConfig().SlotsPerEpoch] = justifiedBlockRoot[:]
attesterServer := &AttesterServer{
beaconDB: db,
p2p: &mockBroadcaster{},

View File

@@ -236,7 +236,7 @@ func TestBlockTree_OK(t *testing.T) {
justifiedState := &pbp2p.BeaconState{
Slot: 0,
Balances: make([]uint64, 11),
ValidatorRegistry: validators,
Validators: validators,
}
for i := 0; i < len(justifiedState.Balances); i++ {
justifiedState.Balances[i] = params.BeaconConfig().MaxDepositAmount
@@ -261,7 +261,7 @@ func TestBlockTree_OK(t *testing.T) {
b1Root, _ := blockutil.BlockSigningRoot(b1)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b1Root); err != nil {
t.Fatal(err)
@@ -274,7 +274,7 @@ func TestBlockTree_OK(t *testing.T) {
b2Root, _ := blockutil.BlockSigningRoot(b2)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b2Root); err != nil {
t.Fatal(err)
@@ -287,7 +287,7 @@ func TestBlockTree_OK(t *testing.T) {
b3Root, _ := blockutil.BlockSigningRoot(b3)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b3Root); err != nil {
t.Fatal(err)
@@ -300,7 +300,7 @@ func TestBlockTree_OK(t *testing.T) {
b4Root, _ := blockutil.BlockSigningRoot(b4)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 4,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b4Root); err != nil {
t.Fatal(err)
@@ -313,7 +313,7 @@ func TestBlockTree_OK(t *testing.T) {
b5Root, _ := blockutil.BlockSigningRoot(b5)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 5,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b5Root); err != nil {
t.Fatal(err)
@@ -476,7 +476,7 @@ func TestBlockTreeBySlots_ArgsValildation(t *testing.T) {
b1Root, _ := blockutil.BlockSigningRoot(b1)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b1Root); err != nil {
t.Fatal(err)
@@ -488,7 +488,7 @@ func TestBlockTreeBySlots_ArgsValildation(t *testing.T) {
b2Root, _ := blockutil.BlockSigningRoot(b2)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b2Root); err != nil {
t.Fatal(err)
@@ -500,7 +500,7 @@ func TestBlockTreeBySlots_ArgsValildation(t *testing.T) {
b3Root, _ := blockutil.BlockSigningRoot(b3)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b3Root); err != nil {
t.Fatal(err)
@@ -512,7 +512,7 @@ func TestBlockTreeBySlots_ArgsValildation(t *testing.T) {
b4Root, _ := blockutil.BlockSigningRoot(b4)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 4,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b4Root); err != nil {
t.Fatal(err)
@@ -524,7 +524,7 @@ func TestBlockTreeBySlots_ArgsValildation(t *testing.T) {
b5Root, _ := blockutil.BlockSigningRoot(b5)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 5,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b5Root); err != nil {
t.Fatal(err)
@@ -670,7 +670,7 @@ func TestBlockTreeBySlots_OK(t *testing.T) {
for i := 0; i < 11; i++ {
validators = append(validators, &pbp2p.Validator{ExitEpoch: params.BeaconConfig().FarFutureEpoch, EffectiveBalance: params.BeaconConfig().MaxDepositAmount})
}
justifiedState.ValidatorRegistry = validators
justifiedState.Validators = validators
if err := db.SaveJustifiedState(justifiedState); err != nil {
t.Fatal(err)
}
@@ -689,7 +689,7 @@ func TestBlockTreeBySlots_OK(t *testing.T) {
b1Root, _ := blockutil.BlockSigningRoot(b1)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b1Root); err != nil {
t.Fatal(err)
@@ -701,7 +701,7 @@ func TestBlockTreeBySlots_OK(t *testing.T) {
b2Root, _ := blockutil.BlockSigningRoot(b2)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b2Root); err != nil {
t.Fatal(err)
@@ -713,7 +713,7 @@ func TestBlockTreeBySlots_OK(t *testing.T) {
b3Root, _ := blockutil.BlockSigningRoot(b3)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b3Root); err != nil {
t.Fatal(err)
@@ -725,7 +725,7 @@ func TestBlockTreeBySlots_OK(t *testing.T) {
b4Root, _ := blockutil.BlockSigningRoot(b4)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 4,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b4Root); err != nil {
t.Fatal(err)
@@ -737,7 +737,7 @@ func TestBlockTreeBySlots_OK(t *testing.T) {
b5Root, _ := blockutil.BlockSigningRoot(b5)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 5,
ValidatorRegistry: validators,
Validators: validators,
Balances: balances,
}, b5Root); err != nil {
t.Fatal(err)

View File

@@ -251,7 +251,7 @@ func (ps *ProposerServer) deposits(ctx context.Context) ([]*pbp2p.Deposit, error
if err != nil {
return nil, fmt.Errorf("could not fetch beacon state: %v", err)
}
h := bytesutil.ToBytes32(beaconState.LatestEth1Data.BlockHash)
h := bytesutil.ToBytes32(beaconState.Eth1Data.BlockHash)
_, latestEth1DataHeight, err := ps.powChainService.BlockExists(ctx, h)
if err != nil {
return nil, fmt.Errorf("could not fetch eth1data height: %v", err)
@@ -260,12 +260,12 @@ func (ps *ProposerServer) deposits(ctx context.Context) ([]*pbp2p.Deposit, error
// If this doesn't match the number of deposits stored in the cache, the generated trie will not be the same and
// root will fail to verify. This can happen in a scenario where we perhaps have a deposit from height 101,
// so we want to avoid any possible mismatches in these lengths.
upToLatestEth1DataDeposits := ps.beaconDB.AllDeposits(ctx, latestEth1DataHeight)
if len(upToLatestEth1DataDeposits) != len(allDeps) {
upToEth1DataDeposits := ps.beaconDB.AllDeposits(ctx, latestEth1DataHeight)
if len(upToEth1DataDeposits) != len(allDeps) {
return nil, nil
}
depositData := [][]byte{}
for _, dep := range upToLatestEth1DataDeposits {
for _, dep := range upToEth1DataDeposits {
depHash, err := hashutil.DepositHash(dep.Data)
if err != nil {
return nil, fmt.Errorf("coulf not hash deposit data %v", err)
@@ -284,7 +284,7 @@ func (ps *ProposerServer) deposits(ctx context.Context) ([]*pbp2p.Deposit, error
// deposits are sorted from lowest to highest.
var pendingDeps []*pbp2p.Deposit
for _, dep := range allPendingDeps {
if dep.Index >= beaconState.DepositIndex {
if dep.Index >= beaconState.Eth1DepositIndex {
pendingDeps = append(pendingDeps, dep)
}
}

View File

@@ -83,7 +83,7 @@ func TestComputeStateRoot_OK(t *testing.T) {
if err != nil {
t.Fatalf("Could not instantiate genesis state: %v", err)
}
beaconState.LatestStateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.StateRoots = make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
beaconState.LatestBlockHeader = &pbp2p.BeaconBlockHeader{
StateRoot: []byte{},
}
@@ -138,12 +138,12 @@ func TestPendingAttestations_FiltersWithinInclusionDelay(t *testing.T) {
stateSlot := uint64(100)
beaconState := &pbp2p.BeaconState{
Slot: stateSlot,
ValidatorRegistry: validators,
Validators: validators,
CurrentCrosslinks: crosslinks,
PreviousCrosslinks: crosslinks,
LatestStartShard: 100,
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
StartShard: 100,
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
encoded, err := ssz.HashTreeRoot(beaconState.PreviousCrosslinks[0])
@@ -278,7 +278,7 @@ func TestPendingAttestations_FiltersExpiredAttestations(t *testing.T) {
}
beaconState := &pbp2p.BeaconState{
ValidatorRegistry: validators,
Validators: validators,
Slot: currentSlot + params.BeaconConfig().MinAttestationInclusionDelay,
CurrentJustifiedEpoch: expectedEpoch,
PreviousJustifiedEpoch: expectedEpoch,
@@ -286,8 +286,8 @@ func TestPendingAttestations_FiltersExpiredAttestations(t *testing.T) {
StartEpoch: 9,
DataRoot: params.BeaconConfig().ZeroHash[:],
}},
LatestRandaoMixes: make([][]byte, params.BeaconConfig().LatestRandaoMixesLength),
LatestActiveIndexRoots: make([][]byte, params.BeaconConfig().LatestActiveIndexRootsLength),
RandaoMixes: make([][]byte, params.BeaconConfig().RandaoMixesLength),
ActiveIndexRoots: make([][]byte, params.BeaconConfig().ActiveIndexRootsLength),
}
if err := db.SaveState(ctx, beaconState); err != nil {
@@ -365,10 +365,10 @@ func TestPendingDeposits_OutsideEth1FollowWindow(t *testing.T) {
d := internal.SetupDB(t)
beaconState := &pbp2p.BeaconState{
LatestEth1Data: &pbp2p.Eth1Data{
Eth1Data: &pbp2p.Eth1Data{
BlockHash: []byte("0x0"),
},
DepositIndex: 2,
Eth1DepositIndex: 2,
}
if err := d.SaveState(ctx, beaconState); err != nil {
t.Fatal(err)
@@ -460,7 +460,7 @@ func Benchmark_Eth1Data(b *testing.B) {
beaconState := &pbp2p.BeaconState{
Eth1DataVotes: []*pbp2p.Eth1Data{},
LatestEth1Data: &pbp2p.Eth1Data{
Eth1Data: &pbp2p.Eth1Data{
BlockHash: []byte("stub"),
},
}
@@ -496,7 +496,7 @@ func Benchmark_Eth1Data(b *testing.B) {
}
}
func TestPendingDeposits_CantReturnBelowStateDepositIndex(t *testing.T) {
func TestPendingDeposits_CantReturnBelowStateEth1DepositIndex(t *testing.T) {
ctx := context.Background()
height := big.NewInt(int64(params.BeaconConfig().Eth1FollowDistance))
@@ -509,10 +509,10 @@ func TestPendingDeposits_CantReturnBelowStateDepositIndex(t *testing.T) {
d := internal.SetupDB(t)
beaconState := &pbp2p.BeaconState{
LatestEth1Data: &pbp2p.Eth1Data{
Eth1Data: &pbp2p.Eth1Data{
BlockHash: []byte("0x0"),
},
DepositIndex: 10,
Eth1DepositIndex: 10,
}
if err := d.SaveState(ctx, beaconState); err != nil {
t.Fatal(err)
@@ -580,11 +580,11 @@ func TestPendingDeposits_CantReturnBelowStateDepositIndex(t *testing.T) {
expectedDeposits,
)
}
if deposits[0].Index != beaconState.DepositIndex {
if deposits[0].Index != beaconState.Eth1DepositIndex {
t.Errorf(
"Received unexpected merkle index: %d, wanted: %d",
deposits[0].Index,
beaconState.DepositIndex,
beaconState.Eth1DepositIndex,
)
}
}
@@ -602,10 +602,10 @@ func TestPendingDeposits_CantReturnMoreThanMax(t *testing.T) {
d := internal.SetupDB(t)
beaconState := &pbp2p.BeaconState{
LatestEth1Data: &pbp2p.Eth1Data{
Eth1Data: &pbp2p.Eth1Data{
BlockHash: []byte("0x0"),
},
DepositIndex: 2,
Eth1DepositIndex: 2,
}
if err := d.SaveState(ctx, beaconState); err != nil {
t.Fatal(err)
@@ -685,7 +685,7 @@ func TestEth1Data_EmptyVotesFetchBlockHashFailure(t *testing.T) {
},
}
beaconState := &pbp2p.BeaconState{
LatestEth1Data: &pbp2p.Eth1Data{
Eth1Data: &pbp2p.Eth1Data{
BlockHash: []byte{'a'},
},
Eth1DataVotes: []*pbp2p.Eth1Data{},
@@ -730,7 +730,7 @@ func TestEth1Data_EmptyVotesOk(t *testing.T) {
}
depositRoot := depositTrie.Root()
beaconState := &pbp2p.BeaconState{
LatestEth1Data: &pbp2p.Eth1Data{
Eth1Data: &pbp2p.Eth1Data{
BlockHash: []byte("hash0"),
DepositRoot: depositRoot[:],
},
@@ -741,7 +741,7 @@ func TestEth1Data_EmptyVotesOk(t *testing.T) {
latestBlockNumber: height,
hashesByHeight: map[int][]byte{
0: []byte("hash0"),
1: beaconState.LatestEth1Data.BlockHash,
1: beaconState.Eth1Data.BlockHash,
},
}
proposerServer := &ProposerServer{
@@ -776,7 +776,7 @@ func TestEth1Data_NonEmptyVotesSelectsBestVote(t *testing.T) {
eth1DataVotes := []*pbp2p.Eth1Data{}
beaconState := &pbp2p.BeaconState{
Eth1DataVotes: eth1DataVotes,
LatestEth1Data: &pbp2p.Eth1Data{
Eth1Data: &pbp2p.Eth1Data{
BlockHash: []byte("stub"),
},
}
@@ -789,7 +789,7 @@ func TestEth1Data_NonEmptyVotesSelectsBestVote(t *testing.T) {
powChainService: &mockPOWChainService{
latestBlockNumber: big.NewInt(int64(currentHeight)),
hashesByHeight: map[int][]byte{
0: beaconState.LatestEth1Data.BlockHash,
0: beaconState.Eth1Data.BlockHash,
1: beaconState.Eth1DataVotes[0].BlockHash,
2: beaconState.Eth1DataVotes[1].BlockHash,
3: beaconState.Eth1DataVotes[3].BlockHash,

View File

@@ -95,7 +95,7 @@ func (vs *ValidatorServer) ValidatorPerformance(
if err != nil {
return nil, fmt.Errorf("could not get head: %v", err)
}
validatorRegistry, err := vs.beaconDB.ValidatorRegistry(ctx)
validatorRegistry, err := vs.beaconDB.Validators(ctx)
if err != nil {
return nil, fmt.Errorf("could not retrieve beacon state: %v", err)
}
@@ -151,7 +151,7 @@ func (vs *ValidatorServer) CommitteeAssignment(ctx context.Context, req *pb.Assi
Status: pb.ValidatorStatus_UNKNOWN_STATUS,
}
v := s.ValidatorRegistry[idx]
v := s.Validators[idx]
// Update validator assignment when it is active
if ok && helpers.IsActiveValidator(v, helpers.CurrentEpoch(s)) {
assignment, err = vs.assignment(pk, s, req.EpochStart)
@@ -358,7 +358,7 @@ func (vs *ValidatorServer) validatorStatus(
activationEpoch := params.BeaconConfig().FarFutureEpoch
var validatorInState *pbp2p.Validator
var validatorIndex uint64
for idx, val := range beaconState.ValidatorRegistry {
for idx, val := range beaconState.Validators {
if ctx.Err() != nil {
return nil
}
@@ -377,8 +377,8 @@ func (vs *ValidatorServer) validatorStatus(
// If the validator has deposited and has been added to the state:
if validatorInState != nil {
var lastActivatedValidatorIdx uint64
for j := len(beaconState.ValidatorRegistry) - 1; j >= 0; j-- {
if helpers.IsActiveValidator(beaconState.ValidatorRegistry[j], currEpoch) {
for j := len(beaconState.Validators) - 1; j >= 0; j-- {
if helpers.IsActiveValidator(beaconState.Validators[j], currEpoch) {
lastActivatedValidatorIdx = uint64(j)
break
}
@@ -399,7 +399,7 @@ func (vs *ValidatorServer) validatorStatus(
func (vs *ValidatorServer) lookupValidatorStatus(validatorIdx uint64, beaconState *pbp2p.BeaconState) pb.ValidatorStatus {
var status pb.ValidatorStatus
v := beaconState.ValidatorRegistry[validatorIdx]
v := beaconState.Validators[validatorIdx]
epoch := helpers.CurrentEpoch(beaconState)
farFutureEpoch := params.BeaconConfig().FarFutureEpoch

View File

@@ -55,7 +55,7 @@ func TestValidatorIndex_InStateNotInDB(t *testing.T) {
// Wanted validator with public key 'A' is in index '1'.
s := &pbp2p.BeaconState{
ValidatorRegistry: []*pbp2p.Validator{{Pubkey: []byte{0}}, {Pubkey: []byte{'A'}}, {Pubkey: []byte{'B'}}},
Validators: []*pbp2p.Validator{{Pubkey: []byte{0}}, {Pubkey: []byte{'A'}}, {Pubkey: []byte{'B'}}},
}
if err := db.SaveState(context.Background(), s); err != nil {
@@ -301,7 +301,7 @@ func TestValidatorStatus_PendingActive(t *testing.T) {
}
// Pending active because activation epoch is still defaulted at far future slot.
if err := db.SaveState(ctx, &pbp2p.BeaconState{ValidatorRegistry: []*pbp2p.Validator{
if err := db.SaveState(ctx, &pbp2p.BeaconState{Validators: []*pbp2p.Validator{
{ActivationEpoch: params.BeaconConfig().FarFutureEpoch, Pubkey: pubKey},
},
Slot: 5000,
@@ -366,7 +366,7 @@ func TestValidatorStatus_Active(t *testing.T) {
if err := db.SaveState(ctx, &pbp2p.BeaconState{
GenesisTime: uint64(time.Unix(0, 0).Unix()),
Slot: 10000,
ValidatorRegistry: []*pbp2p.Validator{{
Validators: []*pbp2p.Validator{{
ActivationEpoch: activeEpoch,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
Pubkey: pubKey},
@@ -418,7 +418,7 @@ func TestValidatorStatus_InitiatedExit(t *testing.T) {
withdrawableEpoch := exitEpoch + params.BeaconConfig().MinValidatorWithdrawalDelay
if err := db.SaveState(ctx, &pbp2p.BeaconState{
Slot: slot,
ValidatorRegistry: []*pbp2p.Validator{{
Validators: []*pbp2p.Validator{{
Pubkey: pubKey,
ActivationEpoch: 0,
ExitEpoch: exitEpoch,
@@ -472,7 +472,7 @@ func TestValidatorStatus_Withdrawable(t *testing.T) {
epoch := helpers.SlotToEpoch(slot)
if err := db.SaveState(ctx, &pbp2p.BeaconState{
Slot: 10000,
ValidatorRegistry: []*pbp2p.Validator{{
Validators: []*pbp2p.Validator{{
WithdrawableEpoch: epoch - 1,
ExitEpoch: epoch - 2,
Pubkey: pubKey},
@@ -525,7 +525,7 @@ func TestValidatorStatus_ExitedSlashed(t *testing.T) {
epoch := helpers.SlotToEpoch(slot)
if err := db.SaveState(ctx, &pbp2p.BeaconState{
Slot: slot,
ValidatorRegistry: []*pbp2p.Validator{{
Validators: []*pbp2p.Validator{{
Slashed: true,
Pubkey: pubKey,
WithdrawableEpoch: epoch + 1},
@@ -578,7 +578,7 @@ func TestValidatorStatus_Exited(t *testing.T) {
epoch := helpers.SlotToEpoch(slot)
if err := db.SaveState(ctx, &pbp2p.BeaconState{
Slot: slot,
ValidatorRegistry: []*pbp2p.Validator{{
Validators: []*pbp2p.Validator{{
Pubkey: pubKey,
WithdrawableEpoch: epoch + 1},
}}); err != nil {
@@ -627,7 +627,7 @@ func TestValidatorStatus_UnknownStatus(t *testing.T) {
if err := db.SaveState(ctx, &pbp2p.BeaconState{
Slot: 0,
ValidatorRegistry: []*pbp2p.Validator{{
Validators: []*pbp2p.Validator{{
ActivationEpoch: 0,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
Pubkey: pubKey},
@@ -672,7 +672,7 @@ func TestWaitForActivation_ContextClosed(t *testing.T) {
beaconState := &pbp2p.BeaconState{
Slot: 0,
ValidatorRegistry: []*pbp2p.Validator{},
Validators: []*pbp2p.Validator{},
}
if err := db.SaveState(ctx, beaconState); err != nil {
t.Fatalf("could not save state: %v", err)
@@ -723,7 +723,7 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
beaconState := &pbp2p.BeaconState{
Slot: 4000,
ValidatorRegistry: []*pbp2p.Validator{
Validators: []*pbp2p.Validator{
{
ActivationEpoch: 0,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
@@ -811,7 +811,7 @@ func TestMultipleValidatorStatus_OK(t *testing.T) {
beaconState := &pbp2p.BeaconState{
Slot: 4000,
ValidatorRegistry: []*pbp2p.Validator{{
Validators: []*pbp2p.Validator{{
ActivationEpoch: 0,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
Pubkey: pubKeys[0]},

View File

@@ -67,7 +67,7 @@ func (s *InitialSync) processState(msg p2p.Message, chainHead *pb.ChainHeadRespo
return nil
}
exists, _, err := s.powchain.BlockExists(ctx, bytesutil.ToBytes32(finalizedState.LatestEth1Data.BlockHash))
exists, _, err := s.powchain.BlockExists(ctx, bytesutil.ToBytes32(finalizedState.Eth1Data.BlockHash))
if err != nil {
log.Errorf("Unable to get powchain block %v", err)
}
@@ -77,7 +77,7 @@ func (s *InitialSync) processState(msg p2p.Message, chainHead *pb.ChainHeadRespo
return nil
}
s.db.PrunePendingDeposits(ctx, finalizedState.DepositIndex)
s.db.PrunePendingDeposits(ctx, finalizedState.Eth1DepositIndex)
if err := s.db.UpdateChainHead(ctx, blockWithNoBody, finalizedState); err != nil {
log.Errorf("Could not update chain head: %v", err)

View File

@@ -5,11 +5,10 @@ package ethereum_beacon_p2p_v1
import (
fmt "fmt"
io "io"
math "math"
proto "github.com/gogo/protobuf/proto"
types "github.com/gogo/protobuf/types"
io "io"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.

File diff suppressed because it is too large Load Diff

View File

@@ -11,13 +11,13 @@ message BeaconState {
uint64 slot = 1003;
// Validator registry [2001-3000]
repeated Validator validator_registry = 2001;
repeated Validator validators = 2001;
// Balances in Gwei
repeated uint64 balances = 2002;
// Randomness and committees [3001-4000]
repeated bytes latest_randao_mixes = 3001;
uint64 latest_start_shard = 3002;
repeated bytes randao_mixes = 3001;
uint64 start_shard = 3002;
// Finality [4001-5000]
repeated PendingAttestation previous_epoch_attestations = 4001;
@@ -33,17 +33,17 @@ message BeaconState {
// Recent state [5001-6000]
repeated Crosslink current_crosslinks = 5001;
repeated Crosslink previous_crosslinks = 5002;
repeated bytes latest_block_roots = 5003;
repeated bytes latest_state_roots = 5004;
repeated bytes latest_active_index_roots = 5005;
repeated uint64 latest_slashed_balances = 5006;
repeated bytes block_roots = 5003;
repeated bytes state_roots = 5004;
repeated bytes active_index_roots = 5005;
repeated uint64 slashed_balances = 5006;
BeaconBlockHeader latest_block_header = 5007;
repeated bytes historical_roots = 5008;
// Ethereum 1.0 chain data [6001-7000]
Eth1Data latest_eth1_data = 6001;
Eth1Data eth1_data = 6001;
repeated Eth1Data eth1_data_votes = 6002;
uint64 deposit_index = 6003;
uint64 eth1_deposit_index = 6003;
}
message Fork {
@@ -117,12 +117,6 @@ message Validator {
uint64 effective_balance = 8;
}
message ShardReassignmentRecord {
uint64 validator_index = 1;
uint64 shard = 2;
uint64 slot = 3;
}
message Crosslink {
uint64 shard = 1;
uint64 start_epoch = 2;
@@ -239,4 +233,3 @@ message HistoricalBatch {
repeated bytes block_roots = 1;
repeated bytes state_roots = 2;
}

View File

@@ -7,15 +7,14 @@ import (
context "context"
encoding_binary "encoding/binary"
fmt "fmt"
io "io"
math "math"
proto "github.com/gogo/protobuf/proto"
types "github.com/gogo/protobuf/types"
_ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options"
v1 "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
_ "google.golang.org/genproto/googleapis/api/annotations"
grpc "google.golang.org/grpc"
io "io"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.

View File

@@ -6,14 +6,13 @@ package ethereum_beacon_rpc_v1
import (
context "context"
fmt "fmt"
math "math"
proto "github.com/golang/protobuf/proto"
empty "github.com/golang/protobuf/ptypes/empty"
_ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options"
v1 "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
_ "google.golang.org/genproto/googleapis/api/annotations"
grpc "google.golang.org/grpc"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.

View File

@@ -5,10 +5,9 @@ package ethereum_sharding_p2p_v1
import (
fmt "fmt"
proto "github.com/gogo/protobuf/proto"
io "io"
math "math"
proto "github.com/gogo/protobuf/proto"
)
// Reference imports to suppress errors if they are not otherwise used.

View File

@@ -49,9 +49,9 @@ type BeaconChainConfig struct {
Eth1FollowDistance uint64 // Eth1FollowDistance is the number of eth1.0 blocks to wait before considering a new deposit for voting. This only applies after the chain as been started.
// State list lengths
LatestRandaoMixesLength uint64 `yaml:"LATEST_RANDAO_MIXES_LENGTH"` // LatestRandaoMixesLength is the number of randao mixes kept in the beacon state.
LatestActiveIndexRootsLength uint64 `yaml:"LATEST_ACTIVE_INDEX_ROOTS_LENGTH"` // LatestIndexRootsLength is the number of index roots kept in beacon state, used by light client.
LatestSlashedExitLength uint64 `yaml:"LATEST_SLASHED_EXIT_LENGTH"` // LatestSlashedExitLength is used to track penalized exit balances per time interval.
RandaoMixesLength uint64 `yaml:"LATEST_RANDAO_MIXES_LENGTH"` // RandaoMixesLength is the number of randao mixes kept in the beacon state.
ActiveIndexRootsLength uint64 `yaml:"LATEST_ACTIVE_INDEX_ROOTS_LENGTH"` // ActiveIndexRootsLength is the number of index roots kept in beacon state, used by light client.
SlashedExitLength uint64 `yaml:"LATEST_SLASHED_EXIT_LENGTH"` // SlashedExitLength is used to track penalized exit balances per time interval.
// Reward and penalty quotients constants.
BaseRewardFactor uint64 `yaml:"BASE_REWARD_FACTOR"` // BaseRewardFactor is used to calculate validator per-slot interest rate.
@@ -150,9 +150,9 @@ var defaultBeaconConfig = &BeaconChainConfig{
Eth1FollowDistance: 1024,
// State list length constants.
LatestRandaoMixesLength: 8192,
LatestActiveIndexRootsLength: 8192,
LatestSlashedExitLength: 8192,
RandaoMixesLength: 8192,
ActiveIndexRootsLength: 8192,
SlashedExitLength: 8192,
// Reward and penalty quotients constants.
BaseRewardFactor: 32,
@@ -238,9 +238,9 @@ func DemoBeaconConfig() *BeaconChainConfig {
demoConfig.SyncPollingInterval = 1 * 10 // Query nodes over the network every slot.
demoConfig.Eth1FollowDistance = 5
demoConfig.SlotsPerEth1VotingPeriod = 1
demoConfig.LatestRandaoMixesLength = 5 * demoConfig.SlotsPerEpoch
demoConfig.LatestActiveIndexRootsLength = 5 * demoConfig.SlotsPerEpoch
demoConfig.LatestSlashedExitLength = 5 * demoConfig.SlotsPerEpoch
demoConfig.RandaoMixesLength = 5 * demoConfig.SlotsPerEpoch
demoConfig.ActiveIndexRootsLength = 5 * demoConfig.SlotsPerEpoch
demoConfig.SlashedExitLength = 5 * demoConfig.SlotsPerEpoch
demoConfig.SlotsPerHistoricalRoot = 5 * demoConfig.SlotsPerEpoch
return &demoConfig
@@ -275,9 +275,9 @@ func MinimalSpecConfig() *BeaconChainConfig {
minimalConfig.PersistentCommitteePeriod = 2048
minimalConfig.MaxEpochsPerCrosslink = 64
minimalConfig.MinEpochsToInactivityPenalty = 4
minimalConfig.LatestRandaoMixesLength = 64
minimalConfig.LatestActiveIndexRootsLength = 64
minimalConfig.LatestSlashedExitLength = 64
minimalConfig.RandaoMixesLength = 64
minimalConfig.ActiveIndexRootsLength = 64
minimalConfig.SlashedExitLength = 64
minimalConfig.BaseRewardFactor = 32
minimalConfig.WhistleBlowingRewardQuotient = 512
minimalConfig.ProposerRewardQuotient = 8