Beacon State V2 Interface Definition With Semantic Version Paths (#9125)

* v2 state initialize and semantic paths

* ensure build

* gaz changes to ignored build files

* gaz
This commit is contained in:
Raul Jordan
2021-06-30 10:06:19 -05:00
committed by GitHub
parent 4fb3e05124
commit b23f63a064
155 changed files with 1029 additions and 450 deletions

View File

@@ -36,7 +36,7 @@ go_test(
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state/stateV0:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//proto/eth/v1alpha1:go_default_library",
"//shared/params:go_default_library",

View File

@@ -4,7 +4,7 @@ import (
"testing"
fuzz "github.com/google/gofuzz"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateV0"
"github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
ethereum_beacon_p2p_v1 "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
@@ -15,7 +15,7 @@ func TestFuzzFinalUpdates_10000(t *testing.T) {
for i := 0; i < 10000; i++ {
fuzzer.Fuzz(base)
s, err := stateV0.InitializeFromProtoUnsafe(base)
s, err := v1.InitializeFromProtoUnsafe(base)
require.NoError(t, err)
_, err = ProcessFinalUpdates(s)
_ = err

View File

@@ -9,7 +9,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateV0"
"github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -43,7 +43,7 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) {
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
}
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
indices, err := epoch.UnslashedAttestingIndices(beaconState, atts)
@@ -89,7 +89,7 @@ func TestUnslashedAttestingIndices_DuplicatedAttestations(t *testing.T) {
Validators: validators,
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
}
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
indices, err := epoch.UnslashedAttestingIndices(beaconState, atts)
@@ -135,7 +135,7 @@ func TestAttestingBalance_CorrectBalance(t *testing.T) {
Validators: validators,
Balances: balances,
}
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
balance, err := epoch.AttestingBalance(beaconState, atts)
@@ -161,7 +161,7 @@ func TestBaseReward_AccurateRewards(t *testing.T) {
{ExitEpoch: params.BeaconConfig().FarFutureEpoch, EffectiveBalance: tt.b}},
Balances: []uint64{tt.a},
}
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
c, err := epoch.BaseReward(beaconState, 0)
require.NoError(t, err)
@@ -176,7 +176,7 @@ func TestProcessSlashings_NotSlashed(t *testing.T) {
Balances: []uint64{params.BeaconConfig().MaxEffectiveBalance},
Slashings: []uint64{0, 1e9},
}
s, err := stateV0.InitializeFromProto(base)
s, err := v1.InitializeFromProto(base)
require.NoError(t, err)
newState, err := epoch.ProcessSlashings(s)
require.NoError(t, err)
@@ -254,7 +254,7 @@ func TestProcessSlashings_SlashedLess(t *testing.T) {
for i, tt := range tests {
t.Run(fmt.Sprint(i), func(t *testing.T) {
original := proto.Clone(tt.state)
s, err := stateV0.InitializeFromProto(tt.state)
s, err := v1.InitializeFromProto(tt.state)
require.NoError(t, err)
newState, err := epoch.ProcessSlashings(s)
require.NoError(t, err)
@@ -314,7 +314,7 @@ func TestProcessRegistryUpdates_NoRotation(t *testing.T) {
},
FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
}
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
newState, err := epoch.ProcessRegistryUpdates(beaconState)
require.NoError(t, err)
@@ -337,7 +337,7 @@ func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) {
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
})
}
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
currentEpoch := helpers.CurrentEpoch(beaconState)
newState, err := epoch.ProcessRegistryUpdates(beaconState)
@@ -366,7 +366,7 @@ func TestProcessRegistryUpdates_ActivationCompletes(t *testing.T) {
},
FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
}
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
newState, err := epoch.ProcessRegistryUpdates(beaconState)
require.NoError(t, err)
@@ -390,7 +390,7 @@ func TestProcessRegistryUpdates_ValidatorsEjected(t *testing.T) {
},
FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
}
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
newState, err := epoch.ProcessRegistryUpdates(beaconState)
require.NoError(t, err)
@@ -415,7 +415,7 @@ func TestProcessRegistryUpdates_CanExits(t *testing.T) {
},
FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
}
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
newState, err := epoch.ProcessRegistryUpdates(beaconState)
require.NoError(t, err)

View File

@@ -44,7 +44,7 @@ go_test(
deps = [
"//beacon-chain/core/epoch:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state/stateV0:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//proto/eth/v1alpha1:go_default_library",
"//shared/attestationutil:go_default_library",

View File

@@ -6,7 +6,7 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateV0"
"github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -37,7 +37,7 @@ func TestProcessJustificationAndFinalizationPreCompute_ConsecutiveEpochs(t *test
Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000
BlockRoots: blockRoots,
}
state, err := stateV0.InitializeFromProto(base)
state, err := v1.InitializeFromProto(base)
require.NoError(t, err)
attestedBalance := 4 * uint64(e) * 3 / 2
b := &precompute.Balance{PrevEpochTargetAttested: attestedBalance}
@@ -74,7 +74,7 @@ func TestProcessJustificationAndFinalizationPreCompute_JustifyCurrentEpoch(t *te
Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000
BlockRoots: blockRoots,
}
state, err := stateV0.InitializeFromProto(base)
state, err := v1.InitializeFromProto(base)
require.NoError(t, err)
attestedBalance := 4 * uint64(e) * 3 / 2
b := &precompute.Balance{PrevEpochTargetAttested: attestedBalance}
@@ -110,7 +110,7 @@ func TestProcessJustificationAndFinalizationPreCompute_JustifyPrevEpoch(t *testi
Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000
BlockRoots: blockRoots, FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
}
state, err := stateV0.InitializeFromProto(base)
state, err := v1.InitializeFromProto(base)
require.NoError(t, err)
attestedBalance := 4 * uint64(e) * 3 / 2
b := &precompute.Balance{PrevEpochTargetAttested: attestedBalance}

View File

@@ -5,7 +5,7 @@ import (
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateV0"
"github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -15,7 +15,7 @@ import (
func TestNew(t *testing.T) {
ffe := params.BeaconConfig().FarFutureEpoch
s, err := stateV0.InitializeFromProto(&pb.BeaconState{
s, err := v1.InitializeFromProto(&pb.BeaconState{
Slot: params.BeaconConfig().SlotsPerEpoch,
// Validator 0 is slashed
// Validator 1 is withdrawable

View File

@@ -8,7 +8,7 @@ import (
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateV0"
"github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/mathutil"
@@ -34,7 +34,7 @@ func TestProcessRewardsAndPenaltiesPrecompute(t *testing.T) {
}
base.PreviousEpochAttestations = atts
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
vp, bp, err := New(context.Background(), beaconState)
@@ -44,7 +44,7 @@ func TestProcessRewardsAndPenaltiesPrecompute(t *testing.T) {
processedState, err := ProcessRewardsAndPenaltiesPrecompute(beaconState, bp, vp, AttestationsDelta, ProposersDelta)
require.NoError(t, err)
beaconState, ok := processedState.(*stateV0.BeaconState)
beaconState, ok := processedState.(*v1.BeaconState)
require.Equal(t, true, ok)
// Indices that voted everything except for head, lost a bit money
@@ -78,7 +78,7 @@ func TestAttestationDeltaPrecompute(t *testing.T) {
}
}
base.PreviousEpochAttestations = atts
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
slashedAttestedIndices := []types.ValidatorIndex{1413}
for _, i := range slashedAttestedIndices {
@@ -162,7 +162,7 @@ func TestAttestationDeltas_ZeroEpoch(t *testing.T) {
}
}
base.PreviousEpochAttestations = atts
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
pVals, pBal, err := New(context.Background(), beaconState)
@@ -200,7 +200,7 @@ func TestAttestationDeltas_ZeroInclusionDelay(t *testing.T) {
}
}
base.PreviousEpochAttestations = atts
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
pVals, pBal, err := New(context.Background(), beaconState)
@@ -226,7 +226,7 @@ func TestProcessRewardsAndPenaltiesPrecompute_SlashedInactivePenalty(t *testing.
}
base.PreviousEpochAttestations = atts
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch*10))
@@ -300,7 +300,7 @@ func TestProposerDeltaPrecompute_HappyCase(t *testing.T) {
e := params.BeaconConfig().SlotsPerEpoch
validatorCount := uint64(10)
base := buildState(e, validatorCount)
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
proposerIndex := types.ValidatorIndex(1)
@@ -322,7 +322,7 @@ func TestProposerDeltaPrecompute_ValidatorIndexOutOfRange(t *testing.T) {
e := params.BeaconConfig().SlotsPerEpoch
validatorCount := uint64(10)
base := buildState(e, validatorCount)
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
proposerIndex := types.ValidatorIndex(validatorCount)
@@ -338,7 +338,7 @@ func TestProposerDeltaPrecompute_SlashedCase(t *testing.T) {
e := params.BeaconConfig().SlotsPerEpoch
validatorCount := uint64(10)
base := buildState(e, validatorCount)
beaconState, err := stateV0.InitializeFromProto(base)
beaconState, err := v1.InitializeFromProto(base)
require.NoError(t, err)
proposerIndex := types.ValidatorIndex(1)

View File

@@ -5,7 +5,7 @@ import (
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateV0"
"github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -15,7 +15,7 @@ import (
)
func TestProcessSlashingsPrecompute_NotSlashedWithSlashedTrue(t *testing.T) {
s, err := stateV0.InitializeFromProto(&pb.BeaconState{
s, err := v1.InitializeFromProto(&pb.BeaconState{
Slot: 0,
Validators: []*ethpb.Validator{{Slashed: true}},
Balances: []uint64{params.BeaconConfig().MaxEffectiveBalance},
@@ -30,7 +30,7 @@ func TestProcessSlashingsPrecompute_NotSlashedWithSlashedTrue(t *testing.T) {
}
func TestProcessSlashingsPrecompute_NotSlashedWithSlashedFalse(t *testing.T) {
s, err := stateV0.InitializeFromProto(&pb.BeaconState{
s, err := v1.InitializeFromProto(&pb.BeaconState{
Slot: 0,
Validators: []*ethpb.Validator{{}},
Balances: []uint64{params.BeaconConfig().MaxEffectiveBalance},
@@ -124,7 +124,7 @@ func TestProcessSlashingsPrecompute_SlashedLess(t *testing.T) {
pBal := &precompute.Balance{ActiveCurrentEpoch: ab}
original := proto.Clone(tt.state)
state, err := stateV0.InitializeFromProto(tt.state)
state, err := v1.InitializeFromProto(tt.state)
require.NoError(t, err)
require.NoError(t, precompute.ProcessSlashingsPrecompute(state, pBal))
assert.Equal(t, tt.want, state.Balances()[0], "ProcessSlashings({%v}) = newState; newState.Balances[0] = %d; wanted %d", original, state.Balances()[0])