mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Deprecate native state flag (#11268)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/altair"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func Test_BaseReward(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
genState := func(valCount uint64) state.ReadOnlyBeaconState {
|
||||
s, _ := util.DeterministicGenesisStateAltair(t, valCount)
|
||||
return s
|
||||
@@ -66,6 +68,7 @@ func Test_BaseReward(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_BaseRewardWithTotalBalance(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
s, _ := util.DeterministicGenesisStateAltair(t, 1)
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -137,6 +140,7 @@ func Test_BaseRewardWithTotalBalance(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_BaseRewardPerIncrement(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
tests := []struct {
|
||||
name string
|
||||
activeBalance uint64
|
||||
|
||||
@@ -132,7 +132,7 @@ func TestSlashValidator_OK(t *testing.T) {
|
||||
state, err := v1.InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
|
||||
slashedIdx := types.ValidatorIndex(2)
|
||||
slashedIdx := types.ValidatorIndex(3)
|
||||
|
||||
proposer, err := helpers.BeaconProposerIndex(context.Background(), state)
|
||||
require.NoError(t, err, "Could not get proposer")
|
||||
|
||||
@@ -233,13 +233,7 @@ func (s *Store) saveStatesEfficientInternal(ctx context.Context, tx *bolt.Tx, bl
|
||||
// look at issue https://github.com/prysmaticlabs/prysm/issues/9262.
|
||||
switch rawType := states[i].InnerStateUnsafe().(type) {
|
||||
case *ethpb.BeaconState:
|
||||
var pbState *ethpb.BeaconState
|
||||
var err error
|
||||
if features.Get().EnableNativeState {
|
||||
pbState, err = statenative.ProtobufBeaconStatePhase0(rawType)
|
||||
} else {
|
||||
pbState, err = v1.ProtobufBeaconState(rawType)
|
||||
}
|
||||
pbState, err := statenative.ProtobufBeaconStatePhase0(rawType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -260,13 +254,7 @@ func (s *Store) saveStatesEfficientInternal(ctx context.Context, tx *bolt.Tx, bl
|
||||
return err
|
||||
}
|
||||
case *ethpb.BeaconStateAltair:
|
||||
var pbState *ethpb.BeaconStateAltair
|
||||
var err error
|
||||
if features.Get().EnableNativeState {
|
||||
pbState, err = statenative.ProtobufBeaconStateAltair(rawType)
|
||||
} else {
|
||||
pbState, err = v2.ProtobufBeaconState(rawType)
|
||||
}
|
||||
pbState, err := statenative.ProtobufBeaconStateAltair(rawType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -288,13 +276,7 @@ func (s *Store) saveStatesEfficientInternal(ctx context.Context, tx *bolt.Tx, bl
|
||||
return err
|
||||
}
|
||||
case *ethpb.BeaconStateBellatrix:
|
||||
var pbState *ethpb.BeaconStateBellatrix
|
||||
var err error
|
||||
if features.Get().EnableNativeState {
|
||||
pbState, err = statenative.ProtobufBeaconStateBellatrix(rawType)
|
||||
} else {
|
||||
pbState, err = v3.ProtobufBeaconState(rawType)
|
||||
}
|
||||
pbState, err := statenative.ProtobufBeaconStateBellatrix(rawType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ go_library(
|
||||
"//beacon-chain/state/state-native:go_default_library",
|
||||
"//beacon-chain/state/stategen:go_default_library",
|
||||
"//beacon-chain/state/v1:go_default_library",
|
||||
"//config/features:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/blocks:go_default_library",
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
|
||||
coreState "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition"
|
||||
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
contracts "github.com/prysmaticlabs/prysm/v3/contracts/deposit"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/hash"
|
||||
@@ -552,13 +550,7 @@ func (s *Service) processChainStartIfReady(ctx context.Context, blockHash [32]by
|
||||
|
||||
// savePowchainData saves all powchain related metadata to disk.
|
||||
func (s *Service) savePowchainData(ctx context.Context) error {
|
||||
var pbState *ethpb.BeaconState
|
||||
var err error
|
||||
if features.Get().EnableNativeState {
|
||||
pbState, err = statenative.ProtobufBeaconStatePhase0(s.preGenesisState.InnerStateUnsafe())
|
||||
} else {
|
||||
pbState, err = v1.ProtobufBeaconState(s.preGenesisState.InnerStateUnsafe())
|
||||
}
|
||||
pbState, err := statenative.ProtobufBeaconStatePhase0(s.preGenesisState.InnerStateUnsafe())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import (
|
||||
native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
|
||||
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/trie"
|
||||
contracts "github.com/prysmaticlabs/prysm/v3/contracts/deposit"
|
||||
@@ -262,11 +261,7 @@ func (s *Service) Stop() error {
|
||||
// ClearPreGenesisData clears out the stored chainstart deposits and beacon state.
|
||||
func (s *Service) ClearPreGenesisData() {
|
||||
s.chainStartData.ChainstartDeposits = []*ethpb.Deposit{}
|
||||
if features.Get().EnableNativeState {
|
||||
s.preGenesisState = &native.BeaconState{}
|
||||
} else {
|
||||
s.preGenesisState = &v1.BeaconState{}
|
||||
}
|
||||
s.preGenesisState = &native.BeaconState{}
|
||||
}
|
||||
|
||||
// ChainStartEth1Data returns the eth1 data at chainstart.
|
||||
@@ -784,13 +779,7 @@ func (s *Service) ensureValidPowchainData(ctx context.Context) error {
|
||||
return errors.Wrap(err, "unable to retrieve eth1 data")
|
||||
}
|
||||
if eth1Data == nil || !eth1Data.ChainstartData.Chainstarted || !validateDepositContainers(eth1Data.DepositContainers) {
|
||||
var pbState *ethpb.BeaconState
|
||||
var err error
|
||||
if features.Get().EnableNativeState {
|
||||
pbState, err = native.ProtobufBeaconStatePhase0(s.preGenesisState.InnerStateUnsafe())
|
||||
} else {
|
||||
pbState, err = v1.ProtobufBeaconState(s.preGenesisState.InnerStateUnsafe())
|
||||
}
|
||||
pbState, err := native.ProtobufBeaconStatePhase0(s.preGenesisState.InnerStateUnsafe())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -85,7 +85,6 @@ go_test(
|
||||
"//beacon-chain/execution/testing:go_default_library",
|
||||
"//cmd:go_default_library",
|
||||
"//cmd/beacon-chain/flags:go_default_library",
|
||||
"//config/features:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
mockExecution "github.com/prysmaticlabs/prysm/v3/beacon-chain/execution/testing"
|
||||
"github.com/prysmaticlabs/prysm/v3/cmd"
|
||||
"github.com/prysmaticlabs/prysm/v3/cmd/beacon-chain/flags"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
@@ -34,7 +33,6 @@ var _ statefeed.Notifier = (*BeaconNode)(nil)
|
||||
// Test that beacon chain node can close.
|
||||
func TestNodeClose_OK(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())
|
||||
|
||||
app := cli.App{}
|
||||
@@ -54,7 +52,6 @@ func TestNodeClose_OK(t *testing.T) {
|
||||
node.Close()
|
||||
|
||||
require.LogsContain(t, hook, "Stopping beacon node")
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestNodeStart_Ok(t *testing.T) {
|
||||
@@ -63,7 +60,6 @@ func TestNodeStart_Ok(t *testing.T) {
|
||||
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String("datadir", tmp, "node data directory")
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
ctx := cli.NewContext(&app, set, nil)
|
||||
node, err := New(ctx, WithBlockchainFlagOptions([]blockchain.Option{}),
|
||||
WithBuilderFlagOptions([]builder.Option{}),
|
||||
@@ -80,7 +76,6 @@ func TestNodeStart_Ok(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNodeStart_Ok_registerDeterministicGenesisService(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
numValidators := uint64(1)
|
||||
hook := logTest.NewGlobal()
|
||||
app := cli.App{}
|
||||
@@ -124,7 +119,6 @@ func TestNodeStart_Ok_registerDeterministicGenesisService(t *testing.T) {
|
||||
node.Close()
|
||||
require.LogsContain(t, hook, "Starting beacon node")
|
||||
require.NoError(t, os.Remove("genesis_ssz.json"))
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
// TestClearDB tests clearing the database
|
||||
|
||||
@@ -35,6 +35,7 @@ go_library(
|
||||
"//beacon-chain/rpc/prysm/v1alpha1/validator:go_default_library",
|
||||
"//beacon-chain/rpc/statefetcher:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/state-native:go_default_library",
|
||||
"//beacon-chain/state/stategen:go_default_library",
|
||||
"//beacon-chain/state/v1:go_default_library",
|
||||
"//beacon-chain/sync:go_default_library",
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
corehelpers "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/rpc/eth/helpers"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
@@ -255,7 +256,7 @@ func valContainersByRequestIds(state state.BeaconState, validatorIds [][]byte) (
|
||||
valIndex = types.ValidatorIndex(index)
|
||||
}
|
||||
validator, err := state.ValidatorAtIndex(valIndex)
|
||||
if _, ok := err.(*v1.ValidatorIndexOutOfRangeError); ok {
|
||||
if _, ok := err.(*statenative.ValidatorIndexOutOfRangeError); ok {
|
||||
// Ignore well-formed yet unknown indexes.
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -81,7 +81,9 @@ go_test(
|
||||
"validators_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
eth_network = "minimal",
|
||||
shard_count = 4,
|
||||
tags = ["minimal"],
|
||||
deps = [
|
||||
"//beacon-chain/blockchain/testing:go_default_library",
|
||||
"//beacon-chain/core/altair:go_default_library",
|
||||
|
||||
@@ -497,7 +497,7 @@ func TestServer_mapAttestationToTargetRoot(t *testing.T) {
|
||||
|
||||
func TestServer_ListIndexedAttestations_GenesisEpoch(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
db := dbTest.SetupDB(t)
|
||||
helpers.ClearCache()
|
||||
ctx := context.Background()
|
||||
@@ -542,8 +542,8 @@ func TestServer_ListIndexedAttestations_GenesisEpoch(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
// We setup 128 validators.
|
||||
numValidators := uint64(128)
|
||||
// We setup 512 validators so that committee size matches the length of attestations' aggregation bits.
|
||||
numValidators := uint64(512)
|
||||
state, _ := util.DeterministicGenesisState(t, numValidators)
|
||||
|
||||
// Next up we convert the test attestations to indexed form:
|
||||
@@ -605,7 +605,7 @@ func TestServer_ListIndexedAttestations_GenesisEpoch(t *testing.T) {
|
||||
|
||||
func TestServer_ListIndexedAttestations_OldEpoch(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
db := dbTest.SetupDB(t)
|
||||
helpers.ClearCache()
|
||||
ctx := context.Background()
|
||||
@@ -852,7 +852,7 @@ func TestServer_StreamIndexedAttestations_ContextCanceled(t *testing.T) {
|
||||
|
||||
func TestServer_StreamIndexedAttestations_OK(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
db := dbTest.SetupDB(t)
|
||||
exitRoutine := make(chan bool)
|
||||
ctrl := gomock.NewController(t)
|
||||
|
||||
@@ -382,7 +382,7 @@ func TestServer_StreamBlocks_ContextCanceled(t *testing.T) {
|
||||
|
||||
func TestServer_StreamBlocks_OnHeadUpdated(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
|
||||
ctx := context.Background()
|
||||
beaconState, privs := util.DeterministicGenesisState(t, 32)
|
||||
@@ -421,7 +421,7 @@ func TestServer_StreamBlocks_OnHeadUpdated(t *testing.T) {
|
||||
|
||||
func TestServer_StreamBlocksVerified_OnHeadUpdated(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -82,7 +82,7 @@ func addDefaultReplayerBuilder(s *Server, h stategen.HistoryAccessor) {
|
||||
|
||||
func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
ctx := context.Background()
|
||||
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
@@ -51,7 +51,7 @@ func TestInfostream_EpochToTimestamp(t *testing.T) {
|
||||
|
||||
func TestInfostream_HandleSetValidatorKeys(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
tests := []struct {
|
||||
name string
|
||||
reqPubKeys [][]byte
|
||||
@@ -89,7 +89,7 @@ func TestInfostream_HandleSetValidatorKeys(t *testing.T) {
|
||||
|
||||
func TestInfostream_HandleAddValidatorKeys(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
tests := []struct {
|
||||
name string
|
||||
initialPubKeys [][]byte
|
||||
@@ -137,7 +137,7 @@ func TestInfostream_HandleAddValidatorKeys(t *testing.T) {
|
||||
|
||||
func TestInfostream_HandleRemoveValidatorKeys(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
tests := []struct {
|
||||
name string
|
||||
initialPubKeys [][]byte
|
||||
|
||||
@@ -1022,7 +1022,7 @@ func TestServer_ListValidators_DefaultPageSize(t *testing.T) {
|
||||
|
||||
func TestServer_ListValidators_FromOldEpoch(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
transition.SkipSlotCache.Disable()
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -1506,8 +1506,6 @@ func TestServer_GetValidatorParticipation_CannotRequestFutureEpoch(t *testing.T)
|
||||
|
||||
func TestServer_GetValidatorParticipation_CurrentAndPrevEpoch(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
beaconDB := dbTest.SetupDB(t)
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -1532,14 +1530,14 @@ func TestServer_GetValidatorParticipation_CurrentAndPrevEpoch(t *testing.T) {
|
||||
}}
|
||||
headState, err := util.NewBeaconState()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, headState.SetSlot(16))
|
||||
require.NoError(t, headState.SetSlot(8))
|
||||
require.NoError(t, headState.SetValidators(validators))
|
||||
require.NoError(t, headState.SetBalances(balances))
|
||||
require.NoError(t, headState.AppendCurrentEpochAttestations(atts[0]))
|
||||
require.NoError(t, headState.AppendPreviousEpochAttestations(atts[0]))
|
||||
|
||||
b := util.NewBeaconBlock()
|
||||
b.Block.Slot = 16
|
||||
b.Block.Slot = 8
|
||||
util.SaveBlock(t, ctx, beaconDB, b)
|
||||
bRoot, err := b.Block.HashTreeRoot()
|
||||
require.NoError(t, beaconDB.SaveStateSummary(ctx, ðpb.StateSummary{Root: bRoot[:]}))
|
||||
@@ -1589,7 +1587,7 @@ func TestServer_GetValidatorParticipation_CurrentAndPrevEpoch(t *testing.T) {
|
||||
func TestServer_GetValidatorParticipation_OrphanedUntilGenesis(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
|
||||
beaconDB := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
@@ -1610,7 +1608,7 @@ func TestServer_GetValidatorParticipation_OrphanedUntilGenesis(t *testing.T) {
|
||||
atts := []*ethpb.PendingAttestation{{
|
||||
Data: util.HydrateAttestationData(ðpb.AttestationData{}),
|
||||
InclusionDelay: 1,
|
||||
AggregationBits: bitfield.NewBitlist(validatorCount / uint64(params.BeaconConfig().SlotsPerEpoch)),
|
||||
AggregationBits: bitfield.NewBitlist((validatorCount / 3) / uint64(params.BeaconConfig().SlotsPerEpoch)),
|
||||
}}
|
||||
headState, err := util.NewBeaconState()
|
||||
require.NoError(t, err)
|
||||
@@ -1667,7 +1665,7 @@ func TestServer_GetValidatorParticipation_OrphanedUntilGenesis(t *testing.T) {
|
||||
|
||||
func TestServer_GetValidatorParticipation_CurrentAndPrevEpochWithBits(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
transition.SkipSlotCache.Disable()
|
||||
|
||||
t.Run("altair", func(t *testing.T) {
|
||||
@@ -2350,8 +2348,6 @@ func TestServer_GetIndividualVotes_Working(t *testing.T) {
|
||||
|
||||
func TestServer_GetIndividualVotes_WorkingAltair(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
beaconDB := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -2422,7 +2418,7 @@ func TestServer_GetIndividualVotes_WorkingAltair(t *testing.T) {
|
||||
func TestServer_GetIndividualVotes_AltairEndOfEpoch(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
beaconDB := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -2510,7 +2506,7 @@ func TestServer_GetIndividualVotes_AltairEndOfEpoch(t *testing.T) {
|
||||
func TestServer_GetIndividualVotes_BellatrixEndOfEpoch(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
beaconDB := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
@@ -94,7 +94,73 @@ go_library(
|
||||
],
|
||||
)
|
||||
|
||||
# gazelle:exclude proposer_utils_bench_test.go
|
||||
common_deps = [
|
||||
"//async/event:go_default_library",
|
||||
"//beacon-chain/blockchain/testing:go_default_library",
|
||||
"//beacon-chain/builder:go_default_library",
|
||||
"//beacon-chain/builder/testing:go_default_library",
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/cache/depositcache:go_default_library",
|
||||
"//beacon-chain/core/altair:go_default_library",
|
||||
"//beacon-chain/core/blocks:go_default_library",
|
||||
"//beacon-chain/core/execution:go_default_library",
|
||||
"//beacon-chain/core/feed:go_default_library",
|
||||
"//beacon-chain/core/feed/block:go_default_library",
|
||||
"//beacon-chain/core/feed/operation:go_default_library",
|
||||
"//beacon-chain/core/feed/state:go_default_library",
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/core/signing:go_default_library",
|
||||
"//beacon-chain/core/time:go_default_library",
|
||||
"//beacon-chain/core/transition:go_default_library",
|
||||
"//beacon-chain/db/testing:go_default_library",
|
||||
"//beacon-chain/execution/testing:go_default_library",
|
||||
"//beacon-chain/forkchoice/protoarray:go_default_library",
|
||||
"//beacon-chain/operations/attestations:go_default_library",
|
||||
"//beacon-chain/operations/slashings:go_default_library",
|
||||
"//beacon-chain/operations/synccommittee:go_default_library",
|
||||
"//beacon-chain/operations/voluntaryexits:go_default_library",
|
||||
"//beacon-chain/p2p/testing:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/stategen:go_default_library",
|
||||
"//beacon-chain/state/stategen/mock:go_default_library",
|
||||
"//beacon-chain/state/v1:go_default_library",
|
||||
"//beacon-chain/state/v3:go_default_library",
|
||||
"//beacon-chain/sync/initial-sync/testing:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/blocks:go_default_library",
|
||||
"//consensus-types/interfaces:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
"//container/trie:go_default_library",
|
||||
"//crypto/bls:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//encoding/ssz:go_default_library",
|
||||
"//proto/engine/v1:go_default_library",
|
||||
"//proto/eth/v1:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//proto/prysm/v1alpha1/attestation:go_default_library",
|
||||
"//proto/prysm/v1alpha1/attestation/aggregation/attestations:go_default_library",
|
||||
"//testing/assert:go_default_library",
|
||||
"//testing/mock:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
"//testing/util:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_d4l3k_messagediff//:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
|
||||
"@com_github_golang_mock//gomock:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
||||
"@org_golang_google_grpc//codes:go_default_library",
|
||||
"@org_golang_google_grpc//status:go_default_library",
|
||||
"@org_golang_google_protobuf//proto:go_default_library",
|
||||
"@org_golang_google_protobuf//types/known/emptypb:go_default_library",
|
||||
]
|
||||
|
||||
# gazelle:ignore
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
timeout = "moderate",
|
||||
@@ -116,69 +182,19 @@ go_test(
|
||||
"validator_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//async/event:go_default_library",
|
||||
"//beacon-chain/blockchain/testing:go_default_library",
|
||||
"//beacon-chain/builder:go_default_library",
|
||||
"//beacon-chain/builder/testing:go_default_library",
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/cache/depositcache:go_default_library",
|
||||
"//beacon-chain/core/altair:go_default_library",
|
||||
"//beacon-chain/core/blocks:go_default_library",
|
||||
"//beacon-chain/core/execution:go_default_library",
|
||||
"//beacon-chain/core/feed:go_default_library",
|
||||
"//beacon-chain/core/feed/block:go_default_library",
|
||||
"//beacon-chain/core/feed/operation:go_default_library",
|
||||
"//beacon-chain/core/feed/state:go_default_library",
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/core/signing:go_default_library",
|
||||
"//beacon-chain/core/time:go_default_library",
|
||||
"//beacon-chain/core/transition:go_default_library",
|
||||
"//beacon-chain/db/testing:go_default_library",
|
||||
"//beacon-chain/execution/testing:go_default_library",
|
||||
"//beacon-chain/forkchoice/protoarray:go_default_library",
|
||||
"//beacon-chain/operations/attestations:go_default_library",
|
||||
"//beacon-chain/operations/slashings:go_default_library",
|
||||
"//beacon-chain/operations/synccommittee:go_default_library",
|
||||
"//beacon-chain/operations/voluntaryexits:go_default_library",
|
||||
"//beacon-chain/p2p/testing:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/stategen:go_default_library",
|
||||
"//beacon-chain/state/stategen/mock:go_default_library",
|
||||
"//beacon-chain/state/v1:go_default_library",
|
||||
"//beacon-chain/state/v3:go_default_library",
|
||||
"//beacon-chain/sync/initial-sync/testing:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/blocks:go_default_library",
|
||||
"//consensus-types/interfaces:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
"//container/trie:go_default_library",
|
||||
"//crypto/bls:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//encoding/ssz:go_default_library",
|
||||
"//proto/engine/v1:go_default_library",
|
||||
"//proto/eth/v1:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//proto/prysm/v1alpha1/attestation:go_default_library",
|
||||
"//proto/prysm/v1alpha1/attestation/aggregation/attestations:go_default_library",
|
||||
"//testing/assert:go_default_library",
|
||||
"//testing/mock:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
"//testing/util:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_d4l3k_messagediff//:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
|
||||
"@com_github_golang_mock//gomock:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
||||
"@org_golang_google_grpc//codes:go_default_library",
|
||||
"@org_golang_google_grpc//status:go_default_library",
|
||||
"@org_golang_google_protobuf//proto:go_default_library",
|
||||
"@org_golang_google_protobuf//types/known/emptypb:go_default_library",
|
||||
],
|
||||
eth_network = "minimal",
|
||||
tags = ["minimal"],
|
||||
deps = common_deps,
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_mainnet_test",
|
||||
timeout = "moderate",
|
||||
srcs = [
|
||||
"attester_mainnet_test.go",
|
||||
"server_mainnet_test.go",
|
||||
"status_mainnet_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = common_deps,
|
||||
)
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestGetDuties_OK(t *testing.T) {
|
||||
|
||||
func TestGetAltairDuties_SyncCommitteeOK(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.AltairForkEpoch = types.Epoch(0)
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
@@ -113,13 +113,13 @@ func TestGetAltairDuties_SyncCommitteeOK(t *testing.T) {
|
||||
eth1Data, err := util.DeterministicEth1Data(len(deposits))
|
||||
require.NoError(t, err)
|
||||
bs, err := util.GenesisBeaconState(context.Background(), deposits, 0, eth1Data)
|
||||
require.NoError(t, err, "Could not setup genesis bs")
|
||||
h := ðpb.BeaconBlockHeader{
|
||||
StateRoot: bytesutil.PadTo([]byte{'a'}, fieldparams.RootLength),
|
||||
ParentRoot: bytesutil.PadTo([]byte{'b'}, fieldparams.RootLength),
|
||||
BodyRoot: bytesutil.PadTo([]byte{'c'}, fieldparams.RootLength),
|
||||
}
|
||||
require.NoError(t, bs.SetLatestBlockHeader(h))
|
||||
require.NoError(t, err, "Could not setup genesis bs")
|
||||
genesisRoot, err := genesis.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
|
||||
@@ -205,7 +205,7 @@ func TestGetAltairDuties_SyncCommitteeOK(t *testing.T) {
|
||||
|
||||
func TestGetBellatrixDuties_SyncCommitteeOK(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.AltairForkEpoch = types.Epoch(0)
|
||||
cfg.BellatrixForkEpoch = types.Epoch(1)
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
@@ -311,7 +311,7 @@ func TestGetBellatrixDuties_SyncCommitteeOK(t *testing.T) {
|
||||
|
||||
func TestGetAltairDuties_UnknownPubkey(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.AltairForkEpoch = types.Epoch(0)
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
@@ -353,14 +353,12 @@ func TestGetAltairDuties_UnknownPubkey(t *testing.T) {
|
||||
|
||||
unknownPubkey := bytesutil.PadTo([]byte{'u'}, 48)
|
||||
req := ðpb.DutiesRequest{
|
||||
PublicKeys: [][]byte{deposits[0].Data.PublicKey, unknownPubkey},
|
||||
PublicKeys: [][]byte{unknownPubkey},
|
||||
}
|
||||
res, err := vs.GetDuties(context.Background(), req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, true, res.CurrentEpochDuties[0].IsSyncCommittee)
|
||||
assert.Equal(t, true, res.NextEpochDuties[0].IsSyncCommittee)
|
||||
assert.Equal(t, false, res.CurrentEpochDuties[1].IsSyncCommittee)
|
||||
assert.Equal(t, false, res.NextEpochDuties[1].IsSyncCommittee)
|
||||
assert.Equal(t, false, res.CurrentEpochDuties[0].IsSyncCommittee)
|
||||
assert.Equal(t, false, res.NextEpochDuties[0].IsSyncCommittee)
|
||||
}
|
||||
|
||||
func TestGetDuties_SlotOutOfUpperBound(t *testing.T) {
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
mock "github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/cache"
|
||||
mockp2p "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing"
|
||||
mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
"github.com/prysmaticlabs/prysm/v3/time/slots"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func TestAttestationDataAtSlot_HandlesFarAwayJustifiedEpoch(t *testing.T) {
|
||||
// Scenario:
|
||||
//
|
||||
// State slot = 10000
|
||||
// Last justified slot = epoch start of 1500
|
||||
// HistoricalRootsLimit = 8192
|
||||
//
|
||||
// More background: https://github.com/prysmaticlabs/prysm/issues/2153
|
||||
// This test breaks if it doesn't use mainnet config
|
||||
|
||||
// Ensure HistoricalRootsLimit matches scenario
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg.HistoricalRootsLimit = 8192
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
block := util.NewBeaconBlock()
|
||||
block.Block.Slot = 10000
|
||||
epochBoundaryBlock := util.NewBeaconBlock()
|
||||
var err error
|
||||
epochBoundaryBlock.Block.Slot, err = slots.EpochStart(slots.ToEpoch(10000))
|
||||
require.NoError(t, err)
|
||||
justifiedBlock := util.NewBeaconBlock()
|
||||
justifiedBlock.Block.Slot, err = slots.EpochStart(slots.ToEpoch(1500))
|
||||
require.NoError(t, err)
|
||||
justifiedBlock.Block.Slot -= 2 // Imagine two skip block
|
||||
blockRoot, err := block.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not hash beacon block")
|
||||
justifiedBlockRoot, err := justifiedBlock.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not hash justified block")
|
||||
epochBoundaryRoot, err := epochBoundaryBlock.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not hash justified block")
|
||||
slot := types.Slot(10000)
|
||||
|
||||
beaconState, err := util.NewBeaconState()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, beaconState.SetSlot(slot))
|
||||
err = beaconState.SetCurrentJustifiedCheckpoint(ðpb.Checkpoint{
|
||||
Epoch: slots.ToEpoch(1500),
|
||||
Root: justifiedBlockRoot[:],
|
||||
})
|
||||
require.NoError(t, err)
|
||||
blockRoots := beaconState.BlockRoots()
|
||||
blockRoots[1] = blockRoot[:]
|
||||
blockRoots[1*params.BeaconConfig().SlotsPerEpoch] = epochBoundaryRoot[:]
|
||||
blockRoots[2*params.BeaconConfig().SlotsPerEpoch] = justifiedBlockRoot[:]
|
||||
require.NoError(t, beaconState.SetBlockRoots(blockRoots))
|
||||
chainService := &mock.ChainService{
|
||||
Genesis: time.Now(),
|
||||
}
|
||||
offset := int64(slot.Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
attesterServer := &Server{
|
||||
P2P: &mockp2p.MockBroadcaster{},
|
||||
AttestationCache: cache.NewAttestationCache(),
|
||||
HeadFetcher: &mock.ChainService{State: beaconState, Root: blockRoot[:]},
|
||||
FinalizationFetcher: &mock.ChainService{
|
||||
CurrentJustifiedCheckPoint: beaconState.CurrentJustifiedCheckpoint(),
|
||||
},
|
||||
SyncChecker: &mockSync.Sync{IsSyncing: false},
|
||||
TimeFetcher: &mock.ChainService{Genesis: time.Now().Add(time.Duration(-1*offset) * time.Second)},
|
||||
StateNotifier: chainService.StateNotifier(),
|
||||
}
|
||||
|
||||
req := ðpb.AttestationDataRequest{
|
||||
CommitteeIndex: 0,
|
||||
Slot: 10000,
|
||||
}
|
||||
res, err := attesterServer.GetAttestationData(context.Background(), req)
|
||||
require.NoError(t, err, "Could not get attestation info at slot")
|
||||
|
||||
expectedInfo := ðpb.AttestationData{
|
||||
Slot: req.Slot,
|
||||
BeaconBlockRoot: blockRoot[:],
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: slots.ToEpoch(1500),
|
||||
Root: justifiedBlockRoot[:],
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 312,
|
||||
Root: blockRoot[:],
|
||||
},
|
||||
}
|
||||
|
||||
if !proto.Equal(res, expectedInfo) {
|
||||
t.Errorf("Expected attestation info to match, received %v, wanted %v", res, expectedInfo)
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/v3/time"
|
||||
"github.com/prysmaticlabs/prysm/v3/time/slots"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/proto"
|
||||
@@ -201,94 +200,6 @@ func TestGetAttestationData_Optimistic(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestAttestationDataAtSlot_HandlesFarAwayJustifiedEpoch(t *testing.T) {
|
||||
// Scenario:
|
||||
//
|
||||
// State slot = 10000
|
||||
// Last justified slot = epoch start of 1500
|
||||
// HistoricalRootsLimit = 8192
|
||||
//
|
||||
// More background: https://github.com/prysmaticlabs/prysm/issues/2153
|
||||
// This test breaks if it doesn't use mainnet config
|
||||
|
||||
// Ensure HistoricalRootsLimit matches scenario
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg.HistoricalRootsLimit = 8192
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
block := util.NewBeaconBlock()
|
||||
block.Block.Slot = 10000
|
||||
epochBoundaryBlock := util.NewBeaconBlock()
|
||||
var err error
|
||||
epochBoundaryBlock.Block.Slot, err = slots.EpochStart(slots.ToEpoch(10000))
|
||||
require.NoError(t, err)
|
||||
justifiedBlock := util.NewBeaconBlock()
|
||||
justifiedBlock.Block.Slot, err = slots.EpochStart(slots.ToEpoch(1500))
|
||||
require.NoError(t, err)
|
||||
justifiedBlock.Block.Slot -= 2 // Imagine two skip block
|
||||
blockRoot, err := block.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not hash beacon block")
|
||||
justifiedBlockRoot, err := justifiedBlock.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not hash justified block")
|
||||
epochBoundaryRoot, err := epochBoundaryBlock.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not hash justified block")
|
||||
slot := types.Slot(10000)
|
||||
|
||||
beaconState, err := util.NewBeaconState()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, beaconState.SetSlot(slot))
|
||||
err = beaconState.SetCurrentJustifiedCheckpoint(ðpb.Checkpoint{
|
||||
Epoch: slots.ToEpoch(1500),
|
||||
Root: justifiedBlockRoot[:],
|
||||
})
|
||||
require.NoError(t, err)
|
||||
blockRoots := beaconState.BlockRoots()
|
||||
blockRoots[1] = blockRoot[:]
|
||||
blockRoots[1*params.BeaconConfig().SlotsPerEpoch] = epochBoundaryRoot[:]
|
||||
blockRoots[2*params.BeaconConfig().SlotsPerEpoch] = justifiedBlockRoot[:]
|
||||
require.NoError(t, beaconState.SetBlockRoots(blockRoots))
|
||||
chainService := &mock.ChainService{
|
||||
Genesis: time.Now(),
|
||||
}
|
||||
offset := int64(slot.Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
attesterServer := &Server{
|
||||
P2P: &mockp2p.MockBroadcaster{},
|
||||
AttestationCache: cache.NewAttestationCache(),
|
||||
HeadFetcher: &mock.ChainService{State: beaconState, Root: blockRoot[:]},
|
||||
FinalizationFetcher: &mock.ChainService{
|
||||
CurrentJustifiedCheckPoint: beaconState.CurrentJustifiedCheckpoint(),
|
||||
},
|
||||
SyncChecker: &mockSync.Sync{IsSyncing: false},
|
||||
TimeFetcher: &mock.ChainService{Genesis: time.Now().Add(time.Duration(-1*offset) * time.Second)},
|
||||
StateNotifier: chainService.StateNotifier(),
|
||||
}
|
||||
|
||||
req := ðpb.AttestationDataRequest{
|
||||
CommitteeIndex: 0,
|
||||
Slot: 10000,
|
||||
}
|
||||
res, err := attesterServer.GetAttestationData(context.Background(), req)
|
||||
require.NoError(t, err, "Could not get attestation info at slot")
|
||||
|
||||
expectedInfo := ðpb.AttestationData{
|
||||
Slot: req.Slot,
|
||||
BeaconBlockRoot: blockRoot[:],
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: slots.ToEpoch(1500),
|
||||
Root: justifiedBlockRoot[:],
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 312,
|
||||
Root: blockRoot[:],
|
||||
},
|
||||
}
|
||||
|
||||
if !proto.Equal(res, expectedInfo) {
|
||||
t.Errorf("Expected attestation info to match, received %v, wanted %v", res, expectedInfo)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttestationDataSlot_handlesInProgressRequest(t *testing.T) {
|
||||
s := ðpb.BeaconState{Slot: 100}
|
||||
state, err := v1.InitializeFromProto(s)
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestServer_StreamAltairBlocks_ContextCanceled(t *testing.T) {
|
||||
|
||||
func TestServer_StreamAltairBlocks_OnHeadUpdated(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
ctx := context.Background()
|
||||
beaconState, privs := util.DeterministicGenesisStateAltair(t, 64)
|
||||
c, err := altair.NextSyncCommittee(ctx, beaconState)
|
||||
@@ -113,8 +113,6 @@ func TestServer_StreamAltairBlocks_OnHeadUpdated(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_StreamAltairBlocksVerified_OnHeadUpdated(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
beaconState, privs := util.DeterministicGenesisStateAltair(t, 32)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
blockchainTest "github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain/testing"
|
||||
builderTest "github.com/prysmaticlabs/prysm/v3/beacon-chain/builder/testing"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/cache"
|
||||
@@ -48,8 +47,6 @@ func TestServer_buildHeaderBlock(t *testing.T) {
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
beaconState, keys := util.DeterministicGenesisStateAltair(t, 16384)
|
||||
sCom, err := altair.NextSyncCommittee(context.Background(), beaconState)
|
||||
require.NoError(t, err)
|
||||
@@ -455,8 +452,6 @@ func TestServer_getAndBuildHeaderBlock(t *testing.T) {
|
||||
require.Equal(t, false, ready)
|
||||
|
||||
// Block built and validated!
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
beaconState, keys := util.DeterministicGenesisStateAltair(t, 16384)
|
||||
sCom, err := altair.NextSyncCommittee(context.Background(), beaconState)
|
||||
require.NoError(t, err)
|
||||
@@ -540,7 +535,7 @@ func TestServer_GetBellatrixBeaconBlock_HappyCase(t *testing.T) {
|
||||
terminalBlockHash := bytesutil.PadTo([]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, 32)
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.BellatrixForkEpoch = 2
|
||||
cfg.AltairForkEpoch = 1
|
||||
cfg.TerminalBlockHash = common.BytesToHash(terminalBlockHash)
|
||||
@@ -574,6 +569,7 @@ func TestServer_GetBellatrixBeaconBlock_HappyCase(t *testing.T) {
|
||||
BaseFeePerGas: make([]byte, fieldparams.RootLength),
|
||||
BlockHash: make([]byte, fieldparams.RootLength),
|
||||
}
|
||||
var scBits [fieldparams.SyncAggregateSyncCommitteeBytesLength]byte
|
||||
blk := ðpb.SignedBeaconBlockBellatrix{
|
||||
Block: ðpb.BeaconBlockBellatrix{
|
||||
Slot: bellatrixSlot + 1,
|
||||
@@ -583,7 +579,7 @@ func TestServer_GetBellatrixBeaconBlock_HappyCase(t *testing.T) {
|
||||
RandaoReveal: genesis.Block.Body.RandaoReveal,
|
||||
Graffiti: genesis.Block.Body.Graffiti,
|
||||
Eth1Data: genesis.Block.Body.Eth1Data,
|
||||
SyncAggregate: ðpb.SyncAggregate{SyncCommitteeBits: bitfield.NewBitvector512(), SyncCommitteeSignature: make([]byte, 96)},
|
||||
SyncAggregate: ðpb.SyncAggregate{SyncCommitteeBits: scBits[:], SyncCommitteeSignature: make([]byte, 96)},
|
||||
ExecutionPayload: emptyPayload,
|
||||
},
|
||||
},
|
||||
@@ -591,7 +587,6 @@ func TestServer_GetBellatrixBeaconBlock_HappyCase(t *testing.T) {
|
||||
}
|
||||
|
||||
blkRoot, err := blk.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, blkRoot), "Could not save genesis state")
|
||||
require.NoError(t, db.SaveHeadBlockRoot(ctx, blkRoot), "Could not save genesis state")
|
||||
@@ -618,7 +613,7 @@ func TestServer_GetBellatrixBeaconBlock_HappyCase(t *testing.T) {
|
||||
ProposerSlotIndexCache: cache.NewProposerPayloadIDsCache(),
|
||||
BlockBuilder: &builderTest.MockBuilderService{},
|
||||
}
|
||||
proposerServer.ProposerSlotIndexCache.SetProposerAndPayloadIDs(65, 40, [8]byte{'a'}, parentRoot)
|
||||
proposerServer.ProposerSlotIndexCache.SetProposerAndPayloadIDs(17, 11, [8]byte{'a'}, parentRoot)
|
||||
|
||||
randaoReveal, err := util.RandaoReveal(beaconState, 0, privKeys)
|
||||
require.NoError(t, err)
|
||||
@@ -640,7 +635,7 @@ func TestServer_GetBellatrixBeaconBlock_BuilderCase(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.BellatrixForkEpoch = 2
|
||||
cfg.AltairForkEpoch = 1
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
@@ -672,6 +667,7 @@ func TestServer_GetBellatrixBeaconBlock_BuilderCase(t *testing.T) {
|
||||
BaseFeePerGas: make([]byte, fieldparams.RootLength),
|
||||
BlockHash: make([]byte, fieldparams.RootLength),
|
||||
}
|
||||
var scBits [fieldparams.SyncAggregateSyncCommitteeBytesLength]byte
|
||||
blk := ðpb.SignedBeaconBlockBellatrix{
|
||||
Block: ðpb.BeaconBlockBellatrix{
|
||||
Slot: bellatrixSlot + 1,
|
||||
@@ -681,7 +677,7 @@ func TestServer_GetBellatrixBeaconBlock_BuilderCase(t *testing.T) {
|
||||
RandaoReveal: genesis.Block.Body.RandaoReveal,
|
||||
Graffiti: genesis.Block.Body.Graffiti,
|
||||
Eth1Data: genesis.Block.Body.Eth1Data,
|
||||
SyncAggregate: ðpb.SyncAggregate{SyncCommitteeBits: bitfield.NewBitvector512(), SyncCommitteeSignature: make([]byte, 96)},
|
||||
SyncAggregate: ðpb.SyncAggregate{SyncCommitteeBits: scBits[:], SyncCommitteeSignature: make([]byte, 96)},
|
||||
ExecutionPayload: emptyPayload,
|
||||
},
|
||||
},
|
||||
@@ -768,7 +764,7 @@ func TestServer_GetBellatrixBeaconBlock_BuilderCase(t *testing.T) {
|
||||
randaoReveal, err := util.RandaoReveal(beaconState, 0, privKeys)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, proposerServer.BeaconDB.SaveRegistrationsByValidatorIDs(ctx, []types.ValidatorIndex{40},
|
||||
require.NoError(t, proposerServer.BeaconDB.SaveRegistrationsByValidatorIDs(ctx, []types.ValidatorIndex{11},
|
||||
[]*ethpb.ValidatorRegistrationV1{{FeeRecipient: bytesutil.PadTo([]byte{}, fieldparams.FeeRecipientLength), Pubkey: bytesutil.PadTo([]byte{}, fieldparams.BLSPubkeyLength)}}))
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
@@ -872,7 +868,9 @@ func TestServer_circuitBreakBuilder(t *testing.T) {
|
||||
require.Equal(t, false, b)
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.MaxBuilderEpochMissedSlots = 4
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
st, blkRoot, err = createState(params.BeaconConfig().SlotsPerEpoch, [32]byte{'b'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, s.ForkFetcher.ForkChoicer().InsertNode(ctx, st, blkRoot))
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
v2 "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
)
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
func TestProposerSyncContributions_FilterByBlockRoot(t *testing.T) {
|
||||
rootA := [32]byte{'a'}
|
||||
rootB := [32]byte{'b'}
|
||||
var aggBits [fieldparams.SyncCommitteeAggregationBytesLength]byte
|
||||
tests := []struct {
|
||||
name string
|
||||
cs proposerSyncContributions
|
||||
@@ -26,7 +27,7 @@ func TestProposerSyncContributions_FilterByBlockRoot(t *testing.T) {
|
||||
{
|
||||
name: "single item, not found",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.NewBitvector128()},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits[:]},
|
||||
},
|
||||
want: proposerSyncContributions{},
|
||||
},
|
||||
@@ -65,6 +66,7 @@ func TestProposerSyncContributions_FilterByBlockRoot(t *testing.T) {
|
||||
func TestProposerSyncContributions_FilterBySubcommitteeID(t *testing.T) {
|
||||
rootA := [32]byte{'a'}
|
||||
rootB := [32]byte{'b'}
|
||||
var aggBits [fieldparams.SyncCommitteeAggregationBytesLength]byte
|
||||
tests := []struct {
|
||||
name string
|
||||
cs proposerSyncContributions
|
||||
@@ -78,7 +80,7 @@ func TestProposerSyncContributions_FilterBySubcommitteeID(t *testing.T) {
|
||||
{
|
||||
name: "single item, not found",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.NewBitvector128(), SubcommitteeIndex: 1},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits[:], SubcommitteeIndex: 1},
|
||||
},
|
||||
want: proposerSyncContributions{},
|
||||
},
|
||||
@@ -115,6 +117,66 @@ func TestProposerSyncContributions_FilterBySubcommitteeID(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProposerSyncContributions_Dedup(t *testing.T) {
|
||||
// Prepare aggregation bits for all scenarios
|
||||
var aggBits1, aggBits2_1, aggBits2_2, aggBits3, aggBits4_1, aggBits4_2, aggBits4_3, aggBits4_4, aggBits4_5, aggBits5_1, aggBits5_2, aggBits5_3, aggBits5_4, aggBits5_5, aggBits6, aggBits7_1, aggBits7_2, aggBits7_3, aggBits7_4, aggBits7_5, aggBits8_1, aggBits8_2, aggBits8_3, aggBits8_4, aggBits8_5, aggBits8_6, aggBits9_1, aggBits9_2, aggBits9_3, aggBits9_4, aggBits10_1, aggBits10_2, aggBits10_3, aggBits10_4, aggBits10_5, aggBits11_1, aggBits11_2, aggBits11_3, aggBits11_4, aggBits12_1, aggBits12_2, aggBits12_3, aggBits12_4, aggBits12_5, aggBits13_1, aggBits13_2 [fieldparams.SyncCommitteeAggregationBytesLength]byte
|
||||
b2_1, b2_2 := []byte{0b10111110, 0x01}, []byte{0b01111111, 0x01}
|
||||
copy(aggBits2_1[:], b2_1)
|
||||
copy(aggBits2_2[:], b2_2)
|
||||
b3 := []byte{0xba, 0x01}
|
||||
copy(aggBits3[:], b3)
|
||||
b4_1, b4_2, b4_3, b4_4, b4_5 := []byte{0b11001111, 0b1}, []byte{0b01101101, 0b1}, []byte{0b00101011, 0b1}, []byte{0b10100000, 0b1}, []byte{0b00010000, 0b1}
|
||||
copy(aggBits4_1[:], b4_1)
|
||||
copy(aggBits4_2[:], b4_2)
|
||||
copy(aggBits4_3[:], b4_3)
|
||||
copy(aggBits4_4[:], b4_4)
|
||||
copy(aggBits4_5[:], b4_5)
|
||||
b5_1, b5_2, b5_3, b5_4, b5_5 := []byte{0b11001111, 0b1}, []byte{0b01101101, 0b1}, []byte{0b00001111, 0b1}, []byte{0b00000011, 0b1}, []byte{0b00000001, 0b1}
|
||||
copy(aggBits5_1[:], b5_1)
|
||||
copy(aggBits5_2[:], b5_2)
|
||||
copy(aggBits5_3[:], b5_3)
|
||||
copy(aggBits5_4[:], b5_4)
|
||||
copy(aggBits5_5[:], b5_5)
|
||||
b6 := []byte{0b00000011, 0b1}
|
||||
copy(aggBits6[:], b6)
|
||||
b7_1, b7_2, b7_3, b7_4, b7_5 := []byte{0b01101101, 0b1}, []byte{0b00100010, 0b1}, []byte{0b10100101, 0b1}, []byte{0b00010000, 0b1}, []byte{0b11001111, 0b1}
|
||||
copy(aggBits7_1[:], b7_1)
|
||||
copy(aggBits7_2[:], b7_2)
|
||||
copy(aggBits7_3[:], b7_3)
|
||||
copy(aggBits7_4[:], b7_4)
|
||||
copy(aggBits7_5[:], b7_5)
|
||||
b8_1, b8_2, b8_3, b8_4, b8_5, b8_6 := []byte{0b00001111, 0b1}, []byte{0b11001111, 0b1}, []byte{0b10100101, 0b1}, []byte{0b00000001, 0b1}, []byte{0b00000011, 0b1}, []byte{0b01101101, 0b1}
|
||||
copy(aggBits8_1[:], b8_1)
|
||||
copy(aggBits8_2[:], b8_2)
|
||||
copy(aggBits8_3[:], b8_3)
|
||||
copy(aggBits8_4[:], b8_4)
|
||||
copy(aggBits8_5[:], b8_5)
|
||||
copy(aggBits8_6[:], b8_6)
|
||||
b9_1, b9_2, b9_3, b9_4 := []byte{0b00000101, 0b1}, []byte{0b00000011, 0b1}, []byte{0b10000001, 0b1}, []byte{0b00011001, 0b1}
|
||||
copy(aggBits9_1[:], b9_1)
|
||||
copy(aggBits9_2[:], b9_2)
|
||||
copy(aggBits9_3[:], b9_3)
|
||||
copy(aggBits9_4[:], b9_4)
|
||||
b10_1, b10_2, b10_3, b10_4, b10_5 := []byte{0b00001111, 0b1}, []byte{0b11001111, 0b1}, []byte{0b00000001, 0b1}, []byte{0b00000011, 0b1}, []byte{0b01101101, 0b1}
|
||||
copy(aggBits10_1[:], b10_1)
|
||||
copy(aggBits10_2[:], b10_2)
|
||||
copy(aggBits10_3[:], b10_3)
|
||||
copy(aggBits10_4[:], b10_4)
|
||||
copy(aggBits10_5[:], b10_5)
|
||||
b11_1, b11_2, b11_3, b11_4 := []byte{0b00000101, 0b1}, []byte{0b00000011, 0b1}, []byte{0b10000001, 0b1}, []byte{0b00011001, 0b1}
|
||||
copy(aggBits11_1[:], b11_1)
|
||||
copy(aggBits11_2[:], b11_2)
|
||||
copy(aggBits11_3[:], b11_3)
|
||||
copy(aggBits11_4[:], b11_4)
|
||||
b12_1, b12_2, b12_3, b12_4, b12_5 := []byte{0b00001111, 0b1}, []byte{0b11001111, 0b1}, []byte{0b00000001, 0b1}, []byte{0b00000011, 0b1}, []byte{0b01101101, 0b1}
|
||||
copy(aggBits12_1[:], b12_1)
|
||||
copy(aggBits12_2[:], b12_2)
|
||||
copy(aggBits12_3[:], b12_3)
|
||||
copy(aggBits12_4[:], b12_4)
|
||||
copy(aggBits12_5[:], b12_5)
|
||||
b13_1, b13_2 := []byte{0b00001111, 0b1}, []byte{0b11001111, 0b1}
|
||||
copy(aggBits13_1[:], b13_1)
|
||||
copy(aggBits13_2[:], b13_2)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
cs proposerSyncContributions
|
||||
@@ -133,194 +195,194 @@ func TestProposerSyncContributions_Dedup(t *testing.T) {
|
||||
{
|
||||
name: "single item",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.NewBitvector128()},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits1[:]},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.NewBitvector128()},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits1[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "two items no duplicates",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10111110, 0x01}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01111111, 0x01}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits2_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits2_2[:]},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01111111, 0x01}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10111110, 0x01}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits2_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits2_1[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "two items with duplicates",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0xba, 0x01}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0xba, 0x01}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits3[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits3[:]},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0xba, 0x01}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits3[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sorted no duplicates",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00101011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100000, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00010000, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits4_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits4_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits4_3[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits4_4[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits4_5[:]},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00101011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100000, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00010000, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits4_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits4_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits4_3[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits4_4[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits4_5[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sorted with duplicates",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits5_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits5_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits5_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits5_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits5_3[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits5_4[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits5_4[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits5_5[:]},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits5_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits5_2[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "all equal",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits6[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits6[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits6[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits6[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits6[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits6[:]},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits6[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "unsorted no duplicates",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00100010, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00010000, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits7_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits7_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits7_3[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits7_4[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits7_5[:]},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00100010, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00010000, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits7_5[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits7_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits7_3[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits7_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits7_4[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "unsorted with duplicates",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits8_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits8_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits8_3[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits8_3[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits8_4[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits8_5[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits8_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits8_6[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits8_4[:]},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits8_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits8_6[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits8_3[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no proper subset (same root)",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00011001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits9_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits9_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits9_3[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits9_4[:]},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00011001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits9_4[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits9_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits9_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits9_3[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "proper subset (same root)",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits10_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits10_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits10_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits10_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits10_3[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits10_4[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits10_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits10_3[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits10_5[:]},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits10_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits10_5[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no proper subset (different index)",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b10000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00011001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits11_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits11_2[:]},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits11_3[:]},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits11_4[:]},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00011001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b10000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits11_4[:]},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits11_3[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits11_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits11_1[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "proper subset (different index 1)",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits12_1[:]},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits12_2[:]},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits12_1[:]},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits12_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits12_3[:]},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits12_4[:]},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits12_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits12_3[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits12_5[:]},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits12_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits12_5[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "proper subset (different index 2)",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits13_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits13_2[:]},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits13_1[:]},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits13_2[:]},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: aggBits13_2[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits13_2[:]},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -345,6 +407,20 @@ func TestProposerSyncContributions_Dedup(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProposerSyncContributions_MostProfitable(t *testing.T) {
|
||||
// Prepare aggregation bits for all scenarios.
|
||||
var aggBits1, aggBits2_1, aggBits2_2, aggBits3_1, aggBits3_2, aggBits4_1, aggBits4_2 [fieldparams.SyncCommitteeAggregationBytesLength]byte
|
||||
b1 := []byte{0b01}
|
||||
copy(aggBits1[:], b1)
|
||||
b2_1, b2_2 := []byte{0b01}, []byte{0b10}
|
||||
copy(aggBits2_1[:], b2_1)
|
||||
copy(aggBits2_2[:], b2_2)
|
||||
b3_1, b3_2 := []byte{0b0101}, []byte{0b0100}
|
||||
copy(aggBits3_1[:], b3_1)
|
||||
copy(aggBits3_2[:], b3_2)
|
||||
b4_1, b4_2 := []byte{0b0101}, []byte{0b0111}
|
||||
copy(aggBits4_1[:], b4_1)
|
||||
copy(aggBits4_2[:], b4_2)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
cs proposerSyncContributions
|
||||
@@ -353,34 +429,34 @@ func TestProposerSyncContributions_MostProfitable(t *testing.T) {
|
||||
{
|
||||
name: "Same item",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits1[:]},
|
||||
},
|
||||
want: &v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01}},
|
||||
want: &v2.SyncCommitteeContribution{AggregationBits: aggBits1[:]},
|
||||
},
|
||||
{
|
||||
name: "Same item again",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits2_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits2_2[:]},
|
||||
},
|
||||
want: &v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01}},
|
||||
want: &v2.SyncCommitteeContribution{AggregationBits: aggBits2_1[:]},
|
||||
},
|
||||
{
|
||||
name: "most profitable at the start",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b0101}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b0100}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits3_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits3_2[:]},
|
||||
},
|
||||
want: &v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b0101}},
|
||||
want: &v2.SyncCommitteeContribution{AggregationBits: aggBits3_1[:]},
|
||||
},
|
||||
{
|
||||
name: "most profitable at the end",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b0101}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b0111}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits4_1[:]},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: aggBits4_2[:]},
|
||||
},
|
||||
want: &v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b0111}},
|
||||
want: &v2.SyncCommitteeContribution{AggregationBits: aggBits4_2[:]},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -90,8 +90,6 @@ func TestProposer_ProposeBlock_OK(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
|
||||
genesis := util.NewBeaconBlock()
|
||||
util.SaveBlock(t, ctx, db, genesis)
|
||||
@@ -128,9 +126,6 @@ func TestProposer_ComputeStateRoot_OK(t *testing.T) {
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
|
||||
beaconState, parentRoot, privKeys := util.DeterministicGenesisStateWithGenesisBlock(t, ctx, db, 100)
|
||||
|
||||
proposerServer := &Server{
|
||||
@@ -140,7 +135,7 @@ func TestProposer_ComputeStateRoot_OK(t *testing.T) {
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
req := util.NewBeaconBlock()
|
||||
req.Block.ProposerIndex = 21
|
||||
req.Block.ProposerIndex = 84
|
||||
req.Block.ParentRoot = parentRoot[:]
|
||||
req.Block.Slot = 1
|
||||
require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1))
|
||||
@@ -1654,8 +1649,6 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProposer_FilterAttestation(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
genesis := util.NewBeaconBlock()
|
||||
|
||||
numValidators := uint64(64)
|
||||
@@ -1708,7 +1701,7 @@ func TestProposer_FilterAttestation(t *testing.T) {
|
||||
CommitteeIndex: types.CommitteeIndex(i),
|
||||
Source: ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b00000110},
|
||||
AggregationBits: bitfield.Bitlist{0b00010010},
|
||||
})
|
||||
committee, err := helpers.BeaconCommitteeFromState(context.Background(), st, atts[i].Data.Slot, atts[i].Data.CommitteeIndex)
|
||||
assert.NoError(t, err)
|
||||
@@ -1732,7 +1725,7 @@ func TestProposer_FilterAttestation(t *testing.T) {
|
||||
return atts
|
||||
},
|
||||
expectedAtts: func(inputAtts []*ethpb.Attestation) []*ethpb.Attestation {
|
||||
return []*ethpb.Attestation{inputAtts[0]}
|
||||
return []*ethpb.Attestation{inputAtts[0], inputAtts[1]}
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1885,8 +1878,6 @@ func TestProposer_GetBeaconBlock_PreForkEpoch(t *testing.T) {
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
beaconState, privKeys := util.DeterministicGenesisState(t, 64)
|
||||
stateRoot, err := beaconState.HashTreeRoot(ctx)
|
||||
require.NoError(t, err, "Could not hash genesis state")
|
||||
@@ -1987,7 +1978,7 @@ func TestProposer_GetBeaconBlock_PostForkEpoch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.AltairForkEpoch = 1
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
beaconState, privKeys := util.DeterministicGenesisState(t, 64)
|
||||
@@ -2006,6 +1997,7 @@ func TestProposer_GetBeaconBlock_PostForkEpoch(t *testing.T) {
|
||||
altairSlot, err := slots.EpochStart(params.BeaconConfig().AltairForkEpoch)
|
||||
require.NoError(t, err)
|
||||
|
||||
var scBits [fieldparams.SyncAggregateSyncCommitteeBytesLength]byte
|
||||
genAltair := ðpb.SignedBeaconBlockAltair{
|
||||
Block: ðpb.BeaconBlockAltair{
|
||||
Slot: altairSlot + 1,
|
||||
@@ -2015,7 +2007,7 @@ func TestProposer_GetBeaconBlock_PostForkEpoch(t *testing.T) {
|
||||
RandaoReveal: genesis.Block.Body.RandaoReveal,
|
||||
Graffiti: genesis.Block.Body.Graffiti,
|
||||
Eth1Data: genesis.Block.Body.Eth1Data,
|
||||
SyncAggregate: ðpb.SyncAggregate{SyncCommitteeBits: bitfield.NewBitvector512(), SyncCommitteeSignature: make([]byte, 96)},
|
||||
SyncAggregate: ðpb.SyncAggregate{SyncCommitteeBits: scBits[:], SyncCommitteeSignature: make([]byte, 96)},
|
||||
},
|
||||
},
|
||||
Signature: genesis.Signature,
|
||||
@@ -2102,7 +2094,7 @@ func TestProposer_GetBeaconBlock_BellatrixEpoch(t *testing.T) {
|
||||
terminalBlockHash := bytesutil.PadTo([]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, 32)
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.BellatrixForkEpoch = 2
|
||||
cfg.AltairForkEpoch = 1
|
||||
cfg.TerminalBlockHash = common.BytesToHash(terminalBlockHash)
|
||||
@@ -2124,6 +2116,7 @@ func TestProposer_GetBeaconBlock_BellatrixEpoch(t *testing.T) {
|
||||
bellatrixSlot, err := slots.EpochStart(params.BeaconConfig().BellatrixForkEpoch)
|
||||
require.NoError(t, err)
|
||||
|
||||
var scBits [fieldparams.SyncAggregateSyncCommitteeBytesLength]byte
|
||||
blk := ðpb.SignedBeaconBlockBellatrix{
|
||||
Block: ðpb.BeaconBlockBellatrix{
|
||||
Slot: bellatrixSlot + 1,
|
||||
@@ -2133,7 +2126,7 @@ func TestProposer_GetBeaconBlock_BellatrixEpoch(t *testing.T) {
|
||||
RandaoReveal: genesis.Block.Body.RandaoReveal,
|
||||
Graffiti: genesis.Block.Body.Graffiti,
|
||||
Eth1Data: genesis.Block.Body.Eth1Data,
|
||||
SyncAggregate: ðpb.SyncAggregate{SyncCommitteeBits: bitfield.NewBitvector512(), SyncCommitteeSignature: make([]byte, 96)},
|
||||
SyncAggregate: ðpb.SyncAggregate{SyncCommitteeBits: scBits[:], SyncCommitteeSignature: make([]byte, 96)},
|
||||
ExecutionPayload: &enginev1.ExecutionPayload{
|
||||
ParentHash: make([]byte, fieldparams.RootLength),
|
||||
FeeRecipient: make([]byte, fieldparams.FeeRecipientLength),
|
||||
@@ -2228,7 +2221,7 @@ func TestProposer_GetBeaconBlock_BellatrixEpoch(t *testing.T) {
|
||||
// Operator sets default fee recipient to not be burned through beacon node cli.
|
||||
newHook := logTest.NewGlobal()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg = params.MainnetConfig().Copy()
|
||||
cfg = params.MinimalSpecConfig().Copy()
|
||||
cfg.DefaultFeeRecipient = common.Address{'b'}
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
_, err = proposerServer.GetBeaconBlock(ctx, req)
|
||||
@@ -2238,7 +2231,7 @@ func TestProposer_GetBeaconBlock_BellatrixEpoch(t *testing.T) {
|
||||
|
||||
func TestProposer_GetBeaconBlock_Optimistic(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.BellatrixForkEpoch = 2
|
||||
cfg.AltairForkEpoch = 1
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
@@ -2289,15 +2282,15 @@ func TestProposer_GetSyncAggregate_OK(t *testing.T) {
|
||||
|
||||
aggregate, err := proposerServer.getSyncAggregate(context.Background(), 1, bytesutil.ToBytes32(conts[0].BlockRoot))
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, bitfield.Bitvector512{0xf, 0xf, 0xf, 0xf}, aggregate.SyncCommitteeBits)
|
||||
require.DeepEqual(t, bitfield.Bitvector32{0xf, 0xf, 0xf, 0xf}, aggregate.SyncCommitteeBits)
|
||||
|
||||
aggregate, err = proposerServer.getSyncAggregate(context.Background(), 2, bytesutil.ToBytes32(conts[0].BlockRoot))
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, bitfield.Bitvector512{0xaa, 0xaa, 0xaa, 0xaa}, aggregate.SyncCommitteeBits)
|
||||
require.DeepEqual(t, bitfield.Bitvector32{0xaa, 0xaa, 0xaa, 0xaa}, aggregate.SyncCommitteeBits)
|
||||
|
||||
aggregate, err = proposerServer.getSyncAggregate(context.Background(), 3, bytesutil.ToBytes32(conts[0].BlockRoot))
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, bitfield.NewBitvector512(), aggregate.SyncCommitteeBits)
|
||||
require.DeepEqual(t, bitfield.NewBitvector32(), aggregate.SyncCommitteeBits)
|
||||
}
|
||||
|
||||
func TestProposer_PrepareBeaconProposer(t *testing.T) {
|
||||
|
||||
114
beacon-chain/rpc/prysm/v1alpha1/validator/server_mainnet_test.go
Normal file
114
beacon-chain/rpc/prysm/v1alpha1/validator/server_mainnet_test.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
mockChain "github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/cache/depositcache"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing"
|
||||
mockExecution "github.com/prysmaticlabs/prysm/v3/beacon-chain/execution/testing"
|
||||
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/trie"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/mock"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
)
|
||||
|
||||
func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
|
||||
// This test breaks if it doesn't use mainnet config
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig().Copy())
|
||||
ctx := context.Background()
|
||||
|
||||
priv1, err := bls.RandKey()
|
||||
require.NoError(t, err)
|
||||
priv2, err := bls.RandKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
pubKey1 := priv1.PublicKey().Marshal()
|
||||
pubKey2 := priv2.PublicKey().Marshal()
|
||||
|
||||
beaconState := ðpb.BeaconState{
|
||||
Slot: 4000,
|
||||
Validators: []*ethpb.Validator{
|
||||
{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: pubKey1,
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
},
|
||||
},
|
||||
}
|
||||
block := util.NewBeaconBlock()
|
||||
genesisRoot, err := block.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey1,
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
domain, err := signing.ComputeDomain(params.BeaconConfig().DomainDeposit, nil, nil)
|
||||
require.NoError(t, err)
|
||||
signingRoot, err := signing.ComputeSigningRoot(depData, domain)
|
||||
require.NoError(t, err)
|
||||
depData.Signature = priv1.Sign(signingRoot[:]).Marshal()
|
||||
|
||||
deposit := ðpb.Deposit{
|
||||
Data: depData,
|
||||
}
|
||||
depositTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
require.NoError(t, err, "Could not setup deposit trie")
|
||||
depositCache, err := depositcache.New()
|
||||
require.NoError(t, err)
|
||||
|
||||
root, err := depositTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, depositCache.InsertDeposit(ctx, deposit, 10 /*blockNum*/, 0, root))
|
||||
s, err := v1.InitializeFromProtoUnsafe(beaconState)
|
||||
require.NoError(t, err)
|
||||
vs := &Server{
|
||||
Ctx: context.Background(),
|
||||
ChainStartFetcher: &mockExecution.Chain{},
|
||||
BlockFetcher: &mockExecution.Chain{},
|
||||
Eth1InfoFetcher: &mockExecution.Chain{},
|
||||
DepositFetcher: depositCache,
|
||||
HeadFetcher: &mockChain.ChainService{State: s, Root: genesisRoot[:]},
|
||||
}
|
||||
req := ðpb.ValidatorActivationRequest{
|
||||
PublicKeys: [][]byte{pubKey1, pubKey2},
|
||||
}
|
||||
ctrl := gomock.NewController(t)
|
||||
|
||||
defer ctrl.Finish()
|
||||
mockChainStream := mock.NewMockBeaconNodeValidator_WaitForActivationServer(ctrl)
|
||||
mockChainStream.EXPECT().Context().Return(context.Background())
|
||||
mockChainStream.EXPECT().Send(
|
||||
ðpb.ValidatorActivationResponse{
|
||||
Statuses: []*ethpb.ValidatorActivationResponse_Status{
|
||||
{
|
||||
PublicKey: pubKey1,
|
||||
Status: ðpb.ValidatorStatusResponse{
|
||||
Status: ethpb.ValidatorStatus_ACTIVE,
|
||||
},
|
||||
Index: 0,
|
||||
},
|
||||
{
|
||||
PublicKey: pubKey2,
|
||||
Status: ðpb.ValidatorStatusResponse{
|
||||
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
Index: nonExistentIndex,
|
||||
},
|
||||
},
|
||||
},
|
||||
).Return(nil)
|
||||
|
||||
require.NoError(t, vs.WaitForActivation(req, mockChainStream), "Could not setup wait for activation stream")
|
||||
}
|
||||
@@ -12,11 +12,9 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/cache/depositcache"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/feed"
|
||||
statefeed "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/feed/state"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing"
|
||||
mockExecution "github.com/prysmaticlabs/prysm/v3/beacon-chain/execution/testing"
|
||||
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/trie"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
@@ -102,98 +100,6 @@ func TestWaitForActivation_ContextClosed(t *testing.T) {
|
||||
exitRoutine <- true
|
||||
}
|
||||
|
||||
func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
|
||||
// This test breaks if it doesn't use mainnet config
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig().Copy())
|
||||
ctx := context.Background()
|
||||
|
||||
priv1, err := bls.RandKey()
|
||||
require.NoError(t, err)
|
||||
priv2, err := bls.RandKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
pubKey1 := priv1.PublicKey().Marshal()
|
||||
pubKey2 := priv2.PublicKey().Marshal()
|
||||
|
||||
beaconState := ðpb.BeaconState{
|
||||
Slot: 4000,
|
||||
Validators: []*ethpb.Validator{
|
||||
{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: pubKey1,
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
},
|
||||
},
|
||||
}
|
||||
block := util.NewBeaconBlock()
|
||||
genesisRoot, err := block.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey1,
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
domain, err := signing.ComputeDomain(params.BeaconConfig().DomainDeposit, nil, nil)
|
||||
require.NoError(t, err)
|
||||
signingRoot, err := signing.ComputeSigningRoot(depData, domain)
|
||||
require.NoError(t, err)
|
||||
depData.Signature = priv1.Sign(signingRoot[:]).Marshal()
|
||||
|
||||
deposit := ðpb.Deposit{
|
||||
Data: depData,
|
||||
}
|
||||
depositTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
require.NoError(t, err, "Could not setup deposit trie")
|
||||
depositCache, err := depositcache.New()
|
||||
require.NoError(t, err)
|
||||
|
||||
root, err := depositTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, depositCache.InsertDeposit(ctx, deposit, 10 /*blockNum*/, 0, root))
|
||||
s, err := v1.InitializeFromProtoUnsafe(beaconState)
|
||||
require.NoError(t, err)
|
||||
vs := &Server{
|
||||
Ctx: context.Background(),
|
||||
ChainStartFetcher: &mockExecution.Chain{},
|
||||
BlockFetcher: &mockExecution.Chain{},
|
||||
Eth1InfoFetcher: &mockExecution.Chain{},
|
||||
DepositFetcher: depositCache,
|
||||
HeadFetcher: &mockChain.ChainService{State: s, Root: genesisRoot[:]},
|
||||
}
|
||||
req := ðpb.ValidatorActivationRequest{
|
||||
PublicKeys: [][]byte{pubKey1, pubKey2},
|
||||
}
|
||||
ctrl := gomock.NewController(t)
|
||||
|
||||
defer ctrl.Finish()
|
||||
mockChainStream := mock.NewMockBeaconNodeValidator_WaitForActivationServer(ctrl)
|
||||
mockChainStream.EXPECT().Context().Return(context.Background())
|
||||
mockChainStream.EXPECT().Send(
|
||||
ðpb.ValidatorActivationResponse{
|
||||
Statuses: []*ethpb.ValidatorActivationResponse_Status{
|
||||
{
|
||||
PublicKey: pubKey1,
|
||||
Status: ðpb.ValidatorStatusResponse{
|
||||
Status: ethpb.ValidatorStatus_ACTIVE,
|
||||
},
|
||||
Index: 0,
|
||||
},
|
||||
{
|
||||
PublicKey: pubKey2,
|
||||
Status: ðpb.ValidatorStatusResponse{
|
||||
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
Index: nonExistentIndex,
|
||||
},
|
||||
},
|
||||
},
|
||||
).Return(nil)
|
||||
|
||||
require.NoError(t, vs.WaitForActivation(req, mockChainStream), "Could not setup wait for activation stream")
|
||||
}
|
||||
|
||||
func TestWaitForActivation_MultipleStatuses(t *testing.T) {
|
||||
priv1, err := bls.RandKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
102
beacon-chain/rpc/prysm/v1alpha1/validator/status_mainnet_test.go
Normal file
102
beacon-chain/rpc/prysm/v1alpha1/validator/status_mainnet_test.go
Normal file
@@ -0,0 +1,102 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
mockChain "github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/cache/depositcache"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
|
||||
mockExecution "github.com/prysmaticlabs/prysm/v3/beacon-chain/execution/testing"
|
||||
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/trie"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func TestValidatorStatus_Active(t *testing.T) {
|
||||
// This test breaks if it doesn't use mainnet config
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig().Copy())
|
||||
ctx := context.Background()
|
||||
|
||||
pubkey := generatePubkey(1)
|
||||
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubkey,
|
||||
Signature: bytesutil.PadTo([]byte("hi"), 96),
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
}
|
||||
|
||||
deposit := ðpb.Deposit{
|
||||
Data: depData,
|
||||
}
|
||||
depositTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
require.NoError(t, err, "Could not setup deposit trie")
|
||||
depositCache, err := depositcache.New()
|
||||
require.NoError(t, err)
|
||||
|
||||
root, err := depositTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, depositCache.InsertDeposit(ctx, deposit, 0 /*blockNum*/, 0, root))
|
||||
|
||||
// Active because activation epoch <= current epoch < exit epoch.
|
||||
activeEpoch := helpers.ActivationExitEpoch(0)
|
||||
|
||||
block := util.NewBeaconBlock()
|
||||
genesisRoot, err := block.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
|
||||
st := ðpb.BeaconState{
|
||||
GenesisTime: uint64(time.Unix(0, 0).Unix()),
|
||||
Slot: 10000,
|
||||
Validators: []*ethpb.Validator{{
|
||||
ActivationEpoch: activeEpoch,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: pubkey},
|
||||
}}
|
||||
stateObj, err := v1.InitializeFromProtoUnsafe(st)
|
||||
require.NoError(t, err)
|
||||
|
||||
timestamp := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix()
|
||||
p := &mockExecution.Chain{
|
||||
TimesByHeight: map[int]uint64{
|
||||
int(params.BeaconConfig().Eth1FollowDistance): uint64(timestamp),
|
||||
},
|
||||
}
|
||||
vs := &Server{
|
||||
ChainStartFetcher: p,
|
||||
BlockFetcher: p,
|
||||
Eth1InfoFetcher: p,
|
||||
DepositFetcher: depositCache,
|
||||
HeadFetcher: &mockChain.ChainService{State: stateObj, Root: genesisRoot[:]},
|
||||
}
|
||||
req := ðpb.ValidatorStatusRequest{
|
||||
PublicKey: pubkey,
|
||||
}
|
||||
resp, err := vs.ValidatorStatus(context.Background(), req)
|
||||
require.NoError(t, err, "Could not get validator status")
|
||||
|
||||
expected := ðpb.ValidatorStatusResponse{
|
||||
Status: ethpb.ValidatorStatus_ACTIVE,
|
||||
ActivationEpoch: 5,
|
||||
}
|
||||
if !proto.Equal(resp, expected) {
|
||||
t.Errorf("Wanted %v, got %v", expected, resp)
|
||||
}
|
||||
}
|
||||
|
||||
// pubKey is a helper to generate a well-formed public key.
|
||||
func generatePubkey(i uint64) []byte {
|
||||
pubKey := make([]byte, params.BeaconConfig().BLSPubkeyLength)
|
||||
binary.LittleEndian.PutUint64(pubKey, i)
|
||||
return pubKey
|
||||
}
|
||||
@@ -233,79 +233,6 @@ func TestValidatorStatus_Pending(t *testing.T) {
|
||||
assert.Equal(t, ethpb.ValidatorStatus_PENDING, resp.Status)
|
||||
}
|
||||
|
||||
func TestValidatorStatus_Active(t *testing.T) {
|
||||
// This test breaks if it doesn't use mainnet config
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig().Copy())
|
||||
ctx := context.Background()
|
||||
|
||||
pubKey := pubKey(1)
|
||||
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey,
|
||||
Signature: bytesutil.PadTo([]byte("hi"), 96),
|
||||
WithdrawalCredentials: bytesutil.PadTo([]byte("hey"), 32),
|
||||
}
|
||||
|
||||
deposit := ðpb.Deposit{
|
||||
Data: depData,
|
||||
}
|
||||
depositTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
require.NoError(t, err, "Could not setup deposit trie")
|
||||
depositCache, err := depositcache.New()
|
||||
require.NoError(t, err)
|
||||
|
||||
root, err := depositTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, depositCache.InsertDeposit(ctx, deposit, 0 /*blockNum*/, 0, root))
|
||||
|
||||
// Active because activation epoch <= current epoch < exit epoch.
|
||||
activeEpoch := helpers.ActivationExitEpoch(0)
|
||||
|
||||
block := util.NewBeaconBlock()
|
||||
genesisRoot, err := block.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
|
||||
st := ðpb.BeaconState{
|
||||
GenesisTime: uint64(time.Unix(0, 0).Unix()),
|
||||
Slot: 10000,
|
||||
Validators: []*ethpb.Validator{{
|
||||
ActivationEpoch: activeEpoch,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: pubKey},
|
||||
}}
|
||||
stateObj, err := v1.InitializeFromProtoUnsafe(st)
|
||||
require.NoError(t, err)
|
||||
|
||||
timestamp := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix()
|
||||
p := &mockExecution.Chain{
|
||||
TimesByHeight: map[int]uint64{
|
||||
int(params.BeaconConfig().Eth1FollowDistance): uint64(timestamp),
|
||||
},
|
||||
}
|
||||
vs := &Server{
|
||||
ChainStartFetcher: p,
|
||||
BlockFetcher: p,
|
||||
Eth1InfoFetcher: p,
|
||||
DepositFetcher: depositCache,
|
||||
HeadFetcher: &mockChain.ChainService{State: stateObj, Root: genesisRoot[:]},
|
||||
}
|
||||
req := ðpb.ValidatorStatusRequest{
|
||||
PublicKey: pubKey,
|
||||
}
|
||||
resp, err := vs.ValidatorStatus(context.Background(), req)
|
||||
require.NoError(t, err, "Could not get validator status")
|
||||
|
||||
expected := ðpb.ValidatorStatusResponse{
|
||||
Status: ethpb.ValidatorStatus_ACTIVE,
|
||||
ActivationEpoch: 5,
|
||||
}
|
||||
if !proto.Equal(resp, expected) {
|
||||
t.Errorf("Wanted %v, got %v", expected, resp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatorStatus_Exiting(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -438,8 +365,6 @@ func TestValidatorStatus_Exited(t *testing.T) {
|
||||
block := util.NewBeaconBlock()
|
||||
genesisRoot, err := block.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig().Copy())
|
||||
st, err := util.NewBeaconState()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, st.SetSlot(slot))
|
||||
|
||||
@@ -82,8 +82,6 @@ func TestSubmitSyncMessage_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetSyncSubcommitteeIndex_Ok(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
transition.SkipSlotCache.Disable()
|
||||
defer transition.SkipSlotCache.Enable()
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ go_test(
|
||||
"//beacon-chain/state/state-native/types:go_default_library",
|
||||
"//beacon-chain/state/stateutil:go_default_library",
|
||||
"//beacon-chain/state/types:go_default_library",
|
||||
"//config/features:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/fieldtrie"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||
stateTypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
@@ -16,7 +15,6 @@ import (
|
||||
)
|
||||
|
||||
func TestFieldTrie_NewTrie(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
newState, _ := util.DeterministicGenesisState(t, 40)
|
||||
|
||||
// 5 represents the enum value of state roots
|
||||
@@ -27,7 +25,6 @@ func TestFieldTrie_NewTrie(t *testing.T) {
|
||||
newRoot, err := trie.TrieRoot()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, root, newRoot)
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestFieldTrie_NewTrie_NilElements(t *testing.T) {
|
||||
@@ -38,7 +35,6 @@ func TestFieldTrie_NewTrie_NilElements(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFieldTrie_RecomputeTrie(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
newState, _ := util.DeterministicGenesisState(t, 32)
|
||||
// 10 represents the enum value of validators
|
||||
trie, err := fieldtrie.NewFieldTrie(stateTypes.FieldIndex(11), stateTypes.CompositeArray, newState.Validators(), params.BeaconConfig().ValidatorRegistryLimit)
|
||||
@@ -68,11 +64,9 @@ func TestFieldTrie_RecomputeTrie(t *testing.T) {
|
||||
root, err := trie.RecomputeTrie(changedIdx, newState.Validators())
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedRoot, root)
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestFieldTrie_RecomputeTrie_CompressedArray(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
newState, _ := util.DeterministicGenesisState(t, 32)
|
||||
trie, err := fieldtrie.NewFieldTrie(stateTypes.FieldIndex(12), stateTypes.CompressedArray, newState.Balances(), stateutil.ValidatorLimitForBalancesChunks())
|
||||
require.NoError(t, err)
|
||||
@@ -87,19 +81,15 @@ func TestFieldTrie_RecomputeTrie_CompressedArray(t *testing.T) {
|
||||
|
||||
// not equal for some reason :(
|
||||
assert.Equal(t, expectedRoot, root)
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestNewFieldTrie_UnknownType(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
newState, _ := util.DeterministicGenesisState(t, 32)
|
||||
_, err := fieldtrie.NewFieldTrie(stateTypes.FieldIndex(12), 4, newState.Balances(), 32)
|
||||
require.ErrorContains(t, "unrecognized data type", err)
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestFieldTrie_CopyTrieImmutable(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
newState, _ := util.DeterministicGenesisState(t, 32)
|
||||
// 12 represents the enum value of randao mixes.
|
||||
trie, err := fieldtrie.NewFieldTrie(stateTypes.FieldIndex(13), stateTypes.BasicArray, newState.RandaoMixes(), uint64(params.BeaconConfig().EpochsPerHistoricalVector))
|
||||
@@ -120,7 +110,6 @@ func TestFieldTrie_CopyTrieImmutable(t *testing.T) {
|
||||
if root == newRoot {
|
||||
t.Errorf("Wanted roots to be different, but they are the same: %#x", root)
|
||||
}
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestFieldTrie_CopyAndTransferEmpty(t *testing.T) {
|
||||
@@ -132,7 +121,6 @@ func TestFieldTrie_CopyAndTransferEmpty(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFieldTrie_TransferTrie(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
newState, _ := util.DeterministicGenesisState(t, 32)
|
||||
maxLength := (params.BeaconConfig().ValidatorRegistryLimit*8 + 31) / 32
|
||||
trie, err := fieldtrie.NewFieldTrie(stateTypes.FieldIndex(12), stateTypes.CompressedArray, newState.Balances(), maxLength)
|
||||
@@ -148,11 +136,9 @@ func TestFieldTrie_TransferTrie(t *testing.T) {
|
||||
newRoot, err := newTrie.TrieRoot()
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, oldRoot, newRoot)
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func FuzzFieldTrie(f *testing.F) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
newState, _ := util.DeterministicGenesisState(f, 40)
|
||||
var data []byte
|
||||
for _, root := range newState.StateRoots() {
|
||||
@@ -174,5 +160,4 @@ func FuzzFieldTrie(f *testing.F) {
|
||||
return
|
||||
}
|
||||
})
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
nativeStateTypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native/types"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||
stateTypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
@@ -93,7 +92,6 @@ func TestValidateIndices_CompressedField(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFieldTrie_NativeState_fieldConvertersNative(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
type args struct {
|
||||
field stateTypes.BeaconStateField
|
||||
indices []uint64
|
||||
@@ -370,5 +368,4 @@ func TestFieldTrie_NativeState_fieldConvertersNative(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
@@ -108,7 +108,6 @@ go_test(
|
||||
"//beacon-chain/state/state-native/types:go_default_library",
|
||||
"//beacon-chain/state/stateutil:go_default_library",
|
||||
"//beacon-chain/state/testing:go_default_library",
|
||||
"//config/features:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/blocks:go_default_library",
|
||||
|
||||
@@ -3,7 +3,6 @@ package state_native
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
@@ -28,7 +27,6 @@ func TestState_UnrealizedCheckpointBalances(t *testing.T) {
|
||||
PreviousEpochParticipation: make([]byte, params.BeaconConfig().MinGenesisActiveValidatorCount),
|
||||
Balances: balances,
|
||||
}
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
state, err := InitializeFromProtoAltair(base)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -7,51 +7,41 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
)
|
||||
|
||||
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Phase0(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
||||
return statenative.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{
|
||||
Validators: nil,
|
||||
})
|
||||
})
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Altair(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
||||
return statenative.InitializeFromProtoUnsafeAltair(ðpb.BeaconStateAltair{
|
||||
Validators: nil,
|
||||
})
|
||||
})
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Bellatrix(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
||||
return statenative.InitializeFromProtoUnsafeBellatrix(ðpb.BeaconStateBellatrix{
|
||||
Validators: nil,
|
||||
})
|
||||
})
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestValidatorIndexOutOfRangeError(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
err := statenative.NewValidatorIndexOutOfRangeError(1)
|
||||
require.Equal(t, err.Error(), "index 1 out of range")
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestValidatorIndexes(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
dState, _ := util.DeterministicGenesisState(t, 10)
|
||||
byteValue := dState.PubkeyAtIndex(1)
|
||||
t.Run("ValidatorIndexByPubkey", func(t *testing.T) {
|
||||
@@ -64,5 +54,4 @@ func TestValidatorIndexes(t *testing.T) {
|
||||
require.NotEmpty(t, readOnlyBytes)
|
||||
require.Equal(t, hexutil.Encode(readOnlyBytes[:]), hexutil.Encode(byteValue[:]))
|
||||
})
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
@@ -18,7 +17,6 @@ import (
|
||||
)
|
||||
|
||||
func TestComputeFieldRootsWithHasher_Phase0(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
beaconState, err := util.NewBeaconState(util.FillRootsNaturalOpt)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, beaconState.SetGenesisTime(123))
|
||||
@@ -80,11 +78,9 @@ func TestComputeFieldRootsWithHasher_Phase0(t *testing.T) {
|
||||
{0xa9, 0xbb, 0x6a, 0x1f, 0x5d, 0x86, 0x7d, 0xa7, 0x5a, 0x7d, 0x9d, 0x8d, 0xc0, 0x15, 0xb7, 0x0, 0xee, 0xa9, 0x68, 0x51, 0x88, 0x57, 0x5a, 0xd9, 0x4e, 0x1d, 0x8e, 0x44, 0xbf, 0xdc, 0x73, 0xff},
|
||||
}
|
||||
assert.DeepEqual(t, expected, root)
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestComputeFieldRootsWithHasher_Altair(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
beaconState, err := util.NewBeaconStateAltair(util.FillRootsNaturalOptAltair)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, beaconState.SetGenesisTime(123))
|
||||
@@ -152,11 +148,9 @@ func TestComputeFieldRootsWithHasher_Altair(t *testing.T) {
|
||||
{0xd6, 0x4c, 0xb1, 0xac, 0x61, 0x7, 0x26, 0xbb, 0xd3, 0x27, 0x2a, 0xcd, 0xdd, 0x55, 0xf, 0x2b, 0x6a, 0xe8, 0x1, 0x31, 0x48, 0x66, 0x2f, 0x98, 0x7b, 0x6d, 0x27, 0x69, 0xd9, 0x40, 0xcc, 0x37},
|
||||
}
|
||||
assert.DeepEqual(t, expected, root)
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestComputeFieldRootsWithHasher_Bellatrix(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
beaconState, err := util.NewBeaconStateBellatrix(util.FillRootsNaturalOptBellatrix)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, beaconState.SetGenesisTime(123))
|
||||
@@ -228,7 +222,6 @@ func TestComputeFieldRootsWithHasher_Bellatrix(t *testing.T) {
|
||||
{0xbc, 0xbb, 0x39, 0x57, 0x61, 0x1d, 0x54, 0xd6, 0x1b, 0xfe, 0x7a, 0xbd, 0x29, 0x52, 0x57, 0xdd, 0x19, 0x1, 0x89, 0x22, 0x7d, 0xdf, 0x7b, 0x53, 0x9f, 0xb, 0x46, 0x5, 0x9f, 0x80, 0xcc, 0x8e},
|
||||
}
|
||||
assert.DeepEqual(t, expected, root)
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func genesisValidatorsRoot() []byte {
|
||||
|
||||
@@ -6,14 +6,12 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/trie"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
)
|
||||
|
||||
func TestBeaconStateMerkleProofs_phase0_notsupported(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
ctx := context.Background()
|
||||
st, _ := util.DeterministicGenesisState(t, 256)
|
||||
t.Run("current sync committee", func(t *testing.T) {
|
||||
@@ -28,10 +26,8 @@ func TestBeaconStateMerkleProofs_phase0_notsupported(t *testing.T) {
|
||||
_, err := st.FinalizedRootProof(ctx)
|
||||
require.ErrorContains(t, "not supported", err)
|
||||
})
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
func TestBeaconStateMerkleProofs_altair(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
ctx := context.Background()
|
||||
altair, err := util.NewBeaconStateAltair()
|
||||
require.NoError(t, err)
|
||||
@@ -98,11 +94,9 @@ func TestBeaconStateMerkleProofs_altair(t *testing.T) {
|
||||
valid = trie.VerifyMerkleProof(newRoot[:], finalizedRoot, gIndex, proof)
|
||||
require.Equal(t, true, valid)
|
||||
})
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestBeaconStateMerkleProofs_bellatrix(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
ctx := context.Background()
|
||||
bellatrix, err := util.NewBeaconStateBellatrix()
|
||||
require.NoError(t, err)
|
||||
@@ -169,5 +163,4 @@ func TestBeaconStateMerkleProofs_bellatrix(t *testing.T) {
|
||||
valid = trie.VerifyMerkleProof(newRoot[:], finalizedRoot, gIndex, proof)
|
||||
require.Equal(t, true, valid)
|
||||
})
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
@@ -3,14 +3,12 @@ package state_native
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_RotateAttestations(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
st, err := InitializeFromProtoPhase0(ðpb.BeaconState{
|
||||
Slot: 1,
|
||||
CurrentEpochAttestations: []*ethpb.PendingAttestation{{Data: ðpb.AttestationData{Slot: 456}}},
|
||||
@@ -23,5 +21,4 @@ func TestBeaconState_RotateAttestations(t *testing.T) {
|
||||
require.Equal(t, true, ok)
|
||||
require.Equal(t, 0, len(s.currentEpochAttestationsVal()))
|
||||
require.Equal(t, types.Slot(456), s.previousEpochAttestationsVal()[0].Data.Slot)
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
nativetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native/types"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
@@ -66,7 +65,6 @@ func TestBeaconState_NoDeadlock_Phase0(t *testing.T) {
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
}
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
newState, err := InitializeFromProtoUnsafePhase0(ðpb.BeaconState{
|
||||
Validators: vals,
|
||||
})
|
||||
@@ -123,7 +121,6 @@ func TestBeaconState_NoDeadlock_Altair(t *testing.T) {
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
}
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
st, err := InitializeFromProtoUnsafeAltair(ðpb.BeaconStateAltair{
|
||||
Validators: vals,
|
||||
})
|
||||
@@ -180,7 +177,6 @@ func TestBeaconState_NoDeadlock_Bellatrix(t *testing.T) {
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
}
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
st, err := InitializeFromProtoUnsafeBellatrix(ðpb.BeaconStateBellatrix{
|
||||
Validators: vals,
|
||||
})
|
||||
@@ -253,7 +249,6 @@ func TestBeaconState_AppendBalanceWithTrie(t *testing.T) {
|
||||
for i := 0; i < len(mockrandaoMixes); i++ {
|
||||
mockrandaoMixes[i] = zeroHash[:]
|
||||
}
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
newState, err := InitializeFromProtoPhase0(ðpb.BeaconState{
|
||||
Slot: 1,
|
||||
GenesisValidatorsRoot: make([]byte, 32),
|
||||
@@ -305,7 +300,6 @@ func TestBeaconState_AppendBalanceWithTrie(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBeaconState_ModifyPreviousParticipationBits(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
st, err := InitializeFromProtoUnsafePhase0(ðpb.BeaconState{})
|
||||
assert.NoError(t, err)
|
||||
assert.ErrorContains(t, "ModifyPreviousParticipationBits is not supported", st.ModifyPreviousParticipationBits(func(val []byte) ([]byte, error) {
|
||||
@@ -314,7 +308,6 @@ func TestBeaconState_ModifyPreviousParticipationBits(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBeaconState_ModifyCurrentParticipationBits(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
st, err := InitializeFromProtoUnsafePhase0(ðpb.BeaconState{})
|
||||
assert.NoError(t, err)
|
||||
assert.ErrorContains(t, "ModifyCurrentParticipationBits is not supported", st.ModifyCurrentParticipationBits(func(val []byte) ([]byte, error) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
@@ -17,7 +16,6 @@ import (
|
||||
)
|
||||
|
||||
func TestInitializeFromProto_Phase0(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
testState, _ := util.DeterministicGenesisState(t, 64)
|
||||
pbState, err := statenative.ProtobufBeaconStatePhase0(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
@@ -87,14 +85,12 @@ func TestInitializeFromProto_Altair(t *testing.T) {
|
||||
}
|
||||
for _, tt := range initTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
_, err := statenative.InitializeFromProtoAltair(tt.state)
|
||||
if tt.error != "" {
|
||||
require.ErrorContains(t, tt.error, err)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -125,14 +121,12 @@ func TestInitializeFromProto_Bellatrix(t *testing.T) {
|
||||
}
|
||||
for _, tt := range initTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
_, err := statenative.InitializeFromProtoBellatrix(tt.state)
|
||||
if tt.error != "" {
|
||||
require.ErrorContains(t, tt.error, err)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -165,14 +159,12 @@ func TestInitializeFromProtoUnsafe_Phase0(t *testing.T) {
|
||||
}
|
||||
for _, tt := range initTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
_, err := statenative.InitializeFromProtoUnsafePhase0(tt.state)
|
||||
if tt.error != "" {
|
||||
assert.ErrorContains(t, tt.error, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -276,7 +268,6 @@ func TestBeaconState_HashTreeRoot(t *testing.T) {
|
||||
if err == nil && tt.error != "" {
|
||||
t.Errorf("Expected error, expected %v, recevied %v", tt.error, err)
|
||||
}
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
pbState, err := statenative.ProtobufBeaconStatePhase0(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
genericHTR, err := pbState.HashTreeRoot()
|
||||
@@ -289,13 +280,11 @@ func TestBeaconState_HashTreeRoot(t *testing.T) {
|
||||
t.Errorf("Expected HTR to change, received %#x == old %#x", root, oldHTR)
|
||||
}
|
||||
oldHTR = root[:]
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBeaconState(b *testing.B) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
testState, _ := util.DeterministicGenesisState(b, 16000)
|
||||
pbState, err := statenative.ProtobufBeaconStatePhase0(testState.InnerStateUnsafe())
|
||||
require.NoError(b, err)
|
||||
@@ -311,7 +300,6 @@ func BenchmarkBeaconState(b *testing.B) {
|
||||
_, err := pbState.HashTreeRoot()
|
||||
require.NoError(b, err)
|
||||
})
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestBeaconState_HashTreeRoot_FieldTrie(t *testing.T) {
|
||||
@@ -367,7 +355,6 @@ func TestBeaconState_HashTreeRoot_FieldTrie(t *testing.T) {
|
||||
if err == nil && tt.error != "" {
|
||||
t.Errorf("Expected error, expected %v, recevied %v", tt.error, err)
|
||||
}
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
pbState, err := statenative.ProtobufBeaconStatePhase0(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
genericHTR, err := pbState.HashTreeRoot()
|
||||
@@ -380,7 +367,6 @@ func TestBeaconState_HashTreeRoot_FieldTrie(t *testing.T) {
|
||||
t.Errorf("Expected HTR to change, received %#x == old %#x", root, oldHTR)
|
||||
}
|
||||
oldHTR = root[:]
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -429,7 +415,6 @@ func TestBeaconState_ValidatorMutation_Phase0(t *testing.T) {
|
||||
|
||||
rt, err := testState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
pbState, err = statenative.ProtobufBeaconStatePhase0(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -467,7 +452,6 @@ func TestBeaconState_ValidatorMutation_Phase0(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBeaconState_ValidatorMutation_Altair(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
testState, _ := util.DeterministicGenesisStateAltair(t, 400)
|
||||
pbState, err := statenative.ProtobufBeaconStateAltair(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
@@ -532,11 +516,9 @@ func TestBeaconState_ValidatorMutation_Altair(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, rt, rt2)
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
func TestBeaconState_ValidatorMutation_Bellatrix(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
testState, _ := util.DeterministicGenesisStateBellatrix(t, 400)
|
||||
pbState, err := statenative.ProtobufBeaconStateBellatrix(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
@@ -601,5 +583,4 @@ func TestBeaconState_ValidatorMutation_Bellatrix(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, rt, rt2)
|
||||
features.Init(&features.Flags{EnableNativeState: false})
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
|
||||
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
@@ -20,7 +19,6 @@ import (
|
||||
)
|
||||
|
||||
func TestBeaconState_ProtoBeaconStateCompatibility(t *testing.T) {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
params.SetupTestConfigCleanup(t)
|
||||
ctx := context.Background()
|
||||
genesis := setupGenesisState(t, 64)
|
||||
@@ -54,7 +52,6 @@ func TestBeaconState_ProtoBeaconStateCompatibility(t *testing.T) {
|
||||
}
|
||||
|
||||
func setupGenesisState(tb testing.TB, count uint64) *ethpb.BeaconState {
|
||||
features.Init(&features.Flags{EnableNativeState: true})
|
||||
genesisState, _, err := interop.GenerateGenesisState(context.Background(), 0, count)
|
||||
require.NoError(tb, err, "Could not generate genesis beacon state")
|
||||
for i := uint64(1); i < count; i++ {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
@@ -37,7 +37,6 @@ go_library(
|
||||
"//beacon-chain/state/state-native:go_default_library",
|
||||
"//beacon-chain/state/stateutil:go_default_library",
|
||||
"//beacon-chain/state/types:go_default_library",
|
||||
"//config/features:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/interfaces:go_default_library",
|
||||
@@ -55,46 +54,3 @@ go_library(
|
||||
"@org_golang_google_protobuf//proto:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
# gazelle:exclude types_bench_test.go
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"getters_attestation_test.go",
|
||||
"getters_block_test.go",
|
||||
"getters_checkpoint_test.go",
|
||||
"getters_test.go",
|
||||
"getters_validator_test.go",
|
||||
"proofs_test.go",
|
||||
"readonly_validator_test.go",
|
||||
"references_test.go",
|
||||
"setters_attestation_test.go",
|
||||
"state_fuzz_test.go",
|
||||
"state_test.go",
|
||||
"state_trie_test.go",
|
||||
"types_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//beacon-chain/core/transition:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/state-native:go_default_library",
|
||||
"//beacon-chain/state/stateutil:go_default_library",
|
||||
"//beacon-chain/state/testing:go_default_library",
|
||||
"//beacon-chain/state/types:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
"//container/trie:go_default_library",
|
||||
"//crypto/rand:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//runtime/interop:go_default_library",
|
||||
"//testing/assert:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
"//testing/util:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@org_golang_google_protobuf//proto:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_PreviousEpochAttestations(t *testing.T) {
|
||||
s, err := InitializeFromProto(ðpb.BeaconState{})
|
||||
require.NoError(t, err)
|
||||
atts, err := s.PreviousEpochAttestations()
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, []*ethpb.PendingAttestation(nil), atts)
|
||||
|
||||
want := []*ethpb.PendingAttestation{{ProposerIndex: 100}}
|
||||
s, err = InitializeFromProto(ðpb.BeaconState{PreviousEpochAttestations: want})
|
||||
require.NoError(t, err)
|
||||
got, err := s.PreviousEpochAttestations()
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, want, got)
|
||||
|
||||
// Test copy does not mutate.
|
||||
got[0].ProposerIndex = 101
|
||||
require.DeepNotEqual(t, want, got)
|
||||
}
|
||||
|
||||
func TestBeaconState_CurrentEpochAttestations(t *testing.T) {
|
||||
s, err := InitializeFromProto(ðpb.BeaconState{})
|
||||
require.NoError(t, err)
|
||||
atts, err := s.CurrentEpochAttestations()
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, []*ethpb.PendingAttestation(nil), atts)
|
||||
|
||||
want := []*ethpb.PendingAttestation{{ProposerIndex: 101}}
|
||||
s, err = InitializeFromProto(ðpb.BeaconState{CurrentEpochAttestations: want})
|
||||
require.NoError(t, err)
|
||||
got, err := s.CurrentEpochAttestations()
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, want, got)
|
||||
|
||||
// Test copy does not mutate.
|
||||
got[0].ProposerIndex = 102
|
||||
require.DeepNotEqual(t, want, got)
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
func TestBeaconState_LatestBlockHeader(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateLatestBlockHeader(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconState{})
|
||||
},
|
||||
func(BH *ethpb.BeaconBlockHeader) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconState{LatestBlockHeader: BH})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_BlockRoots(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateBlockRoots(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconState{})
|
||||
},
|
||||
func(BR [][]byte) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconState{BlockRoots: BR})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_BlockRootAtIndex(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateBlockRootAtIndex(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconState{})
|
||||
},
|
||||
func(BR [][]byte) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconState{BlockRoots: BR})
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
func TestBeaconState_JustificationBitsNil(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateJustificationBitsNil(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconState{})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_JustificationBits(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateJustificationBits(
|
||||
t,
|
||||
func(bits bitfield.Bitvector4) (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconState{JustificationBits: bits})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_PreviousJustifiedCheckpointNil(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStatePreviousJustifiedCheckpointNil(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconState{})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_PreviousJustifiedCheckpoint(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStatePreviousJustifiedCheckpoint(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconState{PreviousJustifiedCheckpoint: cp})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_CurrentJustifiedCheckpointNil(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateCurrentJustifiedCheckpointNil(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconState{})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_CurrentJustifiedCheckpoint(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateCurrentJustifiedCheckpoint(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconState{CurrentJustifiedCheckpoint: cp})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_FinalizedCheckpointNil(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateFinalizedCheckpointNil(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconState{})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_FinalizedCheckpoint(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateFinalizedCheckpoint(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconState{FinalizedCheckpoint: cp})
|
||||
})
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"runtime/debug"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_SlotDataRace(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateSlotDataRace(t, func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconState{Slot: 1})
|
||||
})
|
||||
}
|
||||
|
||||
func TestNilState_NoPanic(t *testing.T) {
|
||||
var st *BeaconState
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Errorf("Method panicked when it was not supposed to: %v\n%v\n", r, string(debug.Stack()))
|
||||
}
|
||||
}()
|
||||
// retrieve elements from nil state
|
||||
_ = st.GenesisTime()
|
||||
_ = st.GenesisValidatorsRoot()
|
||||
_ = st.GenesisValidatorsRoot()
|
||||
_ = st.Slot()
|
||||
_ = st.Fork()
|
||||
_ = st.LatestBlockHeader()
|
||||
_ = st.BlockRoots()
|
||||
_, err := st.BlockRootAtIndex(0)
|
||||
_ = err
|
||||
_ = st.StateRoots()
|
||||
_ = st.HistoricalRoots()
|
||||
_ = st.Eth1Data()
|
||||
_ = st.Eth1DataVotes()
|
||||
_ = st.Eth1DepositIndex()
|
||||
_, err = st.ValidatorAtIndex(0)
|
||||
_ = err
|
||||
_, err = st.ValidatorAtIndexReadOnly(0)
|
||||
_ = err
|
||||
_, _ = st.ValidatorIndexByPubkey([fieldparams.BLSPubkeyLength]byte{})
|
||||
_ = st.PubkeyAtIndex(0)
|
||||
_ = st.NumValidators()
|
||||
_ = st.Balances()
|
||||
_, err = st.BalanceAtIndex(0)
|
||||
_ = err
|
||||
_ = st.BalancesLength()
|
||||
_ = st.RandaoMixes()
|
||||
_, err = st.RandaoMixAtIndex(0)
|
||||
_ = err
|
||||
_ = st.RandaoMixesLength()
|
||||
_ = st.Slashings()
|
||||
_, err = st.PreviousEpochAttestations()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.CurrentEpochAttestations()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_ = st.JustificationBits()
|
||||
_ = st.PreviousJustifiedCheckpoint()
|
||||
_ = st.CurrentJustifiedCheckpoint()
|
||||
_ = st.FinalizedCheckpoint()
|
||||
_, _, _, err = st.UnrealizedCheckpointBalances()
|
||||
_ = err
|
||||
}
|
||||
|
||||
func TestBeaconState_MatchCurrentJustifiedCheckpt(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateMatchCurrentJustifiedCheckpt(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconState{CurrentJustifiedCheckpoint: cp})
|
||||
},
|
||||
func(i state.BeaconState) {
|
||||
s, ok := i.(*BeaconState)
|
||||
if !ok {
|
||||
panic("error in type assertion in test template")
|
||||
}
|
||||
s.state = nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_MatchPreviousJustifiedCheckpt(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateMatchPreviousJustifiedCheckpt(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconState{PreviousJustifiedCheckpoint: cp})
|
||||
},
|
||||
func(i state.BeaconState) {
|
||||
s, ok := i.(*BeaconState)
|
||||
if !ok {
|
||||
panic("error in type assertion in test template")
|
||||
}
|
||||
s.state = nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_MarshalSSZ_NilState(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateMarshalSSZNilState(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconState{})
|
||||
},
|
||||
func(i state.BeaconState) {
|
||||
s, ok := i.(*BeaconState)
|
||||
if !ok {
|
||||
panic("error in type assertion in test template")
|
||||
}
|
||||
s.state = nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_ValidatorByPubkey(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateValidatorByPubkey(t, func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconState{})
|
||||
})
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package v1_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
||||
return v1.InitializeFromProtoUnsafe(ðpb.BeaconState{
|
||||
Validators: nil,
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package v1_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/trie"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
)
|
||||
|
||||
func TestBeaconStateMerkleProofs(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
st, _ := util.DeterministicGenesisState(t, 256)
|
||||
htr, err := st.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
t.Run("current sync committee", func(t *testing.T) {
|
||||
_, err := st.CurrentSyncCommitteeProof(ctx)
|
||||
require.ErrorContains(t, "unsupported", err)
|
||||
})
|
||||
t.Run("next sync committee", func(t *testing.T) {
|
||||
_, err := st.NextSyncCommitteeProof(ctx)
|
||||
require.ErrorContains(t, "unsupported", err)
|
||||
})
|
||||
t.Run("finalized root", func(t *testing.T) {
|
||||
finalizedRoot := st.FinalizedCheckpoint().Root
|
||||
proof, err := st.FinalizedRootProof(ctx)
|
||||
require.NoError(t, err)
|
||||
gIndex := v1.FinalizedRootGeneralizedIndex()
|
||||
valid := trie.VerifyMerkleProof(htr[:], finalizedRoot, gIndex, proof)
|
||||
require.Equal(t, true, valid)
|
||||
})
|
||||
t.Run("recomputes root on dirty fields", func(t *testing.T) {
|
||||
currentRoot, err := st.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
cpt := st.FinalizedCheckpoint()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Edit the checkpoint.
|
||||
cpt.Epoch = 100
|
||||
require.NoError(t, st.SetFinalizedCheckpoint(cpt))
|
||||
|
||||
// Produce a proof for the finalized root.
|
||||
proof, err := st.FinalizedRootProof(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
// We expect the previous step to have triggered
|
||||
// a recomputation of dirty fields in the beacon state, resulting
|
||||
// in a new hash tree root as the finalized checkpoint had previously
|
||||
// changed and should have been marked as a dirty state field.
|
||||
// The proof validity should be false for the old root, but true for the new.
|
||||
finalizedRoot := st.FinalizedCheckpoint().Root
|
||||
gIndex := v1.FinalizedRootGeneralizedIndex()
|
||||
valid := trie.VerifyMerkleProof(currentRoot[:], finalizedRoot, gIndex, proof)
|
||||
require.Equal(t, false, valid)
|
||||
|
||||
newRoot, err := st.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
valid = trie.VerifyMerkleProof(newRoot[:], finalizedRoot, gIndex, proof)
|
||||
require.Equal(t, true, valid)
|
||||
})
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package v1_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestReadOnlyValidator_ReturnsErrorOnNil(t *testing.T) {
|
||||
if _, err := v1.NewValidator(nil); err != v1.ErrNilWrappedValidator {
|
||||
t.Errorf("Wrong error returned. Got %v, wanted %v", err, v1.ErrNilWrappedValidator)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadOnlyValidator_EffectiveBalance(t *testing.T) {
|
||||
bal := uint64(234)
|
||||
v, err := v1.NewValidator(ðpb.Validator{EffectiveBalance: bal})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, bal, v.EffectiveBalance())
|
||||
}
|
||||
|
||||
func TestReadOnlyValidator_ActivationEligibilityEpoch(t *testing.T) {
|
||||
epoch := types.Epoch(234)
|
||||
v, err := v1.NewValidator(ðpb.Validator{ActivationEligibilityEpoch: epoch})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, epoch, v.ActivationEligibilityEpoch())
|
||||
}
|
||||
|
||||
func TestReadOnlyValidator_ActivationEpoch(t *testing.T) {
|
||||
epoch := types.Epoch(234)
|
||||
v, err := v1.NewValidator(ðpb.Validator{ActivationEpoch: epoch})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, epoch, v.ActivationEpoch())
|
||||
}
|
||||
|
||||
func TestReadOnlyValidator_WithdrawableEpoch(t *testing.T) {
|
||||
epoch := types.Epoch(234)
|
||||
v, err := v1.NewValidator(ðpb.Validator{WithdrawableEpoch: epoch})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, epoch, v.WithdrawableEpoch())
|
||||
}
|
||||
|
||||
func TestReadOnlyValidator_ExitEpoch(t *testing.T) {
|
||||
epoch := types.Epoch(234)
|
||||
v, err := v1.NewValidator(ðpb.Validator{ExitEpoch: epoch})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, epoch, v.ExitEpoch())
|
||||
}
|
||||
|
||||
func TestReadOnlyValidator_PublicKey(t *testing.T) {
|
||||
key := [fieldparams.BLSPubkeyLength]byte{0xFA, 0xCC}
|
||||
v, err := v1.NewValidator(ðpb.Validator{PublicKey: key[:]})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, key, v.PublicKey())
|
||||
}
|
||||
|
||||
func TestReadOnlyValidator_WithdrawalCredentials(t *testing.T) {
|
||||
creds := []byte{0xFA, 0xCC}
|
||||
v, err := v1.NewValidator(ðpb.Validator{WithdrawalCredentials: creds})
|
||||
require.NoError(t, err)
|
||||
assert.DeepEqual(t, creds, v.WithdrawalCredentials())
|
||||
}
|
||||
|
||||
func TestReadOnlyValidator_Slashed(t *testing.T) {
|
||||
v, err := v1.NewValidator(ðpb.Validator{Slashed: true})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, true, v.Slashed())
|
||||
}
|
||||
@@ -1,366 +0,0 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestStateReferenceSharing_Finalizer(t *testing.T) {
|
||||
// This test showcases the logic on a the RandaoMixes field with the GC finalizer.
|
||||
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconState{RandaoMixes: [][]byte{[]byte("foo")}})
|
||||
require.NoError(t, err)
|
||||
a, ok := s.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assert.Equal(t, uint(1), a.sharedFieldReferences[randaoMixes].Refs(), "Expected a single reference for RANDAO mixes")
|
||||
|
||||
func() {
|
||||
// Create object in a different scope for GC
|
||||
b := a.Copy()
|
||||
assert.Equal(t, uint(2), a.sharedFieldReferences[randaoMixes].Refs(), "Expected 2 references to RANDAO mixes")
|
||||
_ = b
|
||||
}()
|
||||
|
||||
runtime.GC() // Should run finalizer on object b
|
||||
assert.Equal(t, uint(1), a.sharedFieldReferences[randaoMixes].Refs(), "Expected 1 shared reference to RANDAO mixes!")
|
||||
|
||||
copied := a.Copy()
|
||||
b, ok := copied.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assert.Equal(t, uint(2), b.sharedFieldReferences[randaoMixes].Refs(), "Expected 2 shared references to RANDAO mixes")
|
||||
require.NoError(t, b.UpdateRandaoMixesAtIndex(0, []byte("bar")))
|
||||
if b.sharedFieldReferences[randaoMixes].Refs() != 1 || a.sharedFieldReferences[randaoMixes].Refs() != 1 {
|
||||
t.Error("Expected 1 shared reference to RANDAO mix for both a and b")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStateReferenceCopy_NoUnexpectedRootsMutation(t *testing.T) {
|
||||
root1, root2 := bytesutil.ToBytes32([]byte("foo")), bytesutil.ToBytes32([]byte("bar"))
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconState{
|
||||
BlockRoots: [][]byte{
|
||||
root1[:],
|
||||
},
|
||||
StateRoots: [][]byte{
|
||||
root1[:],
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
a, ok := s.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
require.NoError(t, err)
|
||||
assertRefCount(t, a, blockRoots, 1)
|
||||
assertRefCount(t, a, stateRoots, 1)
|
||||
|
||||
// Copy, increases reference count.
|
||||
copied := a.Copy()
|
||||
b, ok := copied.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assertRefCount(t, a, blockRoots, 2)
|
||||
assertRefCount(t, a, stateRoots, 2)
|
||||
assertRefCount(t, b, blockRoots, 2)
|
||||
assertRefCount(t, b, stateRoots, 2)
|
||||
assert.Equal(t, 1, len(b.state.GetBlockRoots()), "No block roots found")
|
||||
assert.Equal(t, 1, len(b.state.GetStateRoots()), "No state roots found")
|
||||
|
||||
// Assert shared state.
|
||||
blockRootsA := a.state.GetBlockRoots()
|
||||
stateRootsA := a.state.GetStateRoots()
|
||||
blockRootsB := b.state.GetBlockRoots()
|
||||
stateRootsB := b.state.GetStateRoots()
|
||||
if len(blockRootsA) != len(blockRootsB) || len(blockRootsA) < 1 {
|
||||
t.Errorf("Unexpected number of block roots, want: %v", 1)
|
||||
}
|
||||
if len(stateRootsA) != len(stateRootsB) || len(stateRootsA) < 1 {
|
||||
t.Errorf("Unexpected number of state roots, want: %v", 1)
|
||||
}
|
||||
assertValFound(t, blockRootsA, root1[:])
|
||||
assertValFound(t, blockRootsB, root1[:])
|
||||
assertValFound(t, stateRootsA, root1[:])
|
||||
assertValFound(t, stateRootsB, root1[:])
|
||||
|
||||
// Mutator should only affect calling state: a.
|
||||
require.NoError(t, a.UpdateBlockRootAtIndex(0, root2))
|
||||
require.NoError(t, a.UpdateStateRootAtIndex(0, root2))
|
||||
|
||||
// Assert no shared state mutation occurred only on state a (copy on write).
|
||||
assertValNotFound(t, a.state.GetBlockRoots(), root1[:])
|
||||
assertValNotFound(t, a.state.GetStateRoots(), root1[:])
|
||||
assertValFound(t, a.state.GetBlockRoots(), root2[:])
|
||||
assertValFound(t, a.state.GetStateRoots(), root2[:])
|
||||
assertValFound(t, b.state.GetBlockRoots(), root1[:])
|
||||
assertValFound(t, b.state.GetStateRoots(), root1[:])
|
||||
if len(blockRootsA) != len(blockRootsB) || len(blockRootsA) < 1 {
|
||||
t.Errorf("Unexpected number of block roots, want: %v", 1)
|
||||
}
|
||||
if len(stateRootsA) != len(stateRootsB) || len(stateRootsA) < 1 {
|
||||
t.Errorf("Unexpected number of state roots, want: %v", 1)
|
||||
}
|
||||
assert.DeepEqual(t, root2[:], a.state.GetBlockRoots()[0], "Expected mutation not found")
|
||||
assert.DeepEqual(t, root2[:], a.state.GetStateRoots()[0], "Expected mutation not found")
|
||||
assert.DeepEqual(t, root1[:], blockRootsB[0], "Unexpected mutation found")
|
||||
assert.DeepEqual(t, root1[:], stateRootsB[0], "Unexpected mutation found")
|
||||
|
||||
// Copy on write happened, reference counters are reset.
|
||||
assertRefCount(t, a, blockRoots, 1)
|
||||
assertRefCount(t, a, stateRoots, 1)
|
||||
assertRefCount(t, b, blockRoots, 1)
|
||||
assertRefCount(t, b, stateRoots, 1)
|
||||
}
|
||||
|
||||
func TestStateReferenceCopy_NoUnexpectedRandaoMutation(t *testing.T) {
|
||||
|
||||
val1, val2 := []byte("foo"), []byte("bar")
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconState{
|
||||
RandaoMixes: [][]byte{
|
||||
val1,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
a, ok := s.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
require.NoError(t, err)
|
||||
assertRefCount(t, a, randaoMixes, 1)
|
||||
|
||||
// Copy, increases reference count.
|
||||
copied := a.Copy()
|
||||
b, ok := copied.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assertRefCount(t, a, randaoMixes, 2)
|
||||
assertRefCount(t, b, randaoMixes, 2)
|
||||
assert.Equal(t, 1, len(b.state.GetRandaoMixes()), "No randao mixes found")
|
||||
|
||||
// Assert shared state.
|
||||
mixesA := a.state.GetRandaoMixes()
|
||||
mixesB := b.state.GetRandaoMixes()
|
||||
if len(mixesA) != len(mixesB) || len(mixesA) < 1 {
|
||||
t.Errorf("Unexpected number of mix values, want: %v", 1)
|
||||
}
|
||||
assertValFound(t, mixesA, val1)
|
||||
assertValFound(t, mixesB, val1)
|
||||
|
||||
// Mutator should only affect calling state: a.
|
||||
require.NoError(t, a.UpdateRandaoMixesAtIndex(0, val2))
|
||||
|
||||
// Assert no shared state mutation occurred only on state a (copy on write).
|
||||
if len(mixesA) != len(mixesB) || len(mixesA) < 1 {
|
||||
t.Errorf("Unexpected number of mix values, want: %v", 1)
|
||||
}
|
||||
assertValFound(t, a.state.GetRandaoMixes(), val2)
|
||||
assertValNotFound(t, a.state.GetRandaoMixes(), val1)
|
||||
assertValFound(t, b.state.GetRandaoMixes(), val1)
|
||||
assertValNotFound(t, b.state.GetRandaoMixes(), val2)
|
||||
assertValFound(t, mixesB, val1)
|
||||
assertValNotFound(t, mixesB, val2)
|
||||
assert.DeepEqual(t, val2, a.state.GetRandaoMixes()[0], "Expected mutation not found")
|
||||
assert.DeepEqual(t, val1, mixesB[0], "Unexpected mutation found")
|
||||
|
||||
// Copy on write happened, reference counters are reset.
|
||||
assertRefCount(t, a, randaoMixes, 1)
|
||||
assertRefCount(t, b, randaoMixes, 1)
|
||||
}
|
||||
|
||||
func TestStateReferenceCopy_NoUnexpectedAttestationsMutation(t *testing.T) {
|
||||
assertAttFound := func(vals []*ethpb.PendingAttestation, val uint64) {
|
||||
for i := range vals {
|
||||
if reflect.DeepEqual(vals[i].AggregationBits, bitfield.NewBitlist(val)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Log(string(debug.Stack()))
|
||||
t.Fatalf("Expected attestation not found (%v), want: %v", vals, val)
|
||||
}
|
||||
assertAttNotFound := func(vals []*ethpb.PendingAttestation, val uint64) {
|
||||
for i := range vals {
|
||||
if reflect.DeepEqual(vals[i].AggregationBits, bitfield.NewBitlist(val)) {
|
||||
t.Log(string(debug.Stack()))
|
||||
t.Fatalf("Unexpected attestation found (%v): %v", vals, val)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconState{})
|
||||
require.NoError(t, err)
|
||||
a, ok := s.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assertRefCount(t, a, previousEpochAttestations, 1)
|
||||
assertRefCount(t, a, currentEpochAttestations, 1)
|
||||
|
||||
// Update initial state.
|
||||
atts := []*ethpb.PendingAttestation{
|
||||
{AggregationBits: bitfield.NewBitlist(1)},
|
||||
{AggregationBits: bitfield.NewBitlist(2)},
|
||||
}
|
||||
a.setPreviousEpochAttestations(atts[:1])
|
||||
a.setCurrentEpochAttestations(atts[:1])
|
||||
curAtt, err := a.CurrentEpochAttestations()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(curAtt), "Unexpected number of attestations")
|
||||
preAtt, err := a.PreviousEpochAttestations()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(preAtt), "Unexpected number of attestations")
|
||||
|
||||
// Copy, increases reference count.
|
||||
copied := a.Copy()
|
||||
b, ok := copied.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assertRefCount(t, a, previousEpochAttestations, 2)
|
||||
assertRefCount(t, a, currentEpochAttestations, 2)
|
||||
assertRefCount(t, b, previousEpochAttestations, 2)
|
||||
assertRefCount(t, b, currentEpochAttestations, 2)
|
||||
assert.Equal(t, 1, len(b.state.GetPreviousEpochAttestations()), "Unexpected number of attestations")
|
||||
assert.Equal(t, 1, len(b.state.GetCurrentEpochAttestations()), "Unexpected number of attestations")
|
||||
|
||||
// Assert shared state.
|
||||
curAttsA := a.state.GetCurrentEpochAttestations()
|
||||
prevAttsA := a.state.GetPreviousEpochAttestations()
|
||||
curAttsB := b.state.GetCurrentEpochAttestations()
|
||||
prevAttsB := b.state.GetPreviousEpochAttestations()
|
||||
if len(curAttsA) != len(curAttsB) || len(curAttsA) < 1 {
|
||||
t.Errorf("Unexpected number of attestations, want: %v", 1)
|
||||
}
|
||||
if len(prevAttsA) != len(prevAttsB) || len(prevAttsA) < 1 {
|
||||
t.Errorf("Unexpected number of attestations, want: %v", 1)
|
||||
}
|
||||
assertAttFound(curAttsA, 1)
|
||||
assertAttFound(prevAttsA, 1)
|
||||
assertAttFound(curAttsB, 1)
|
||||
assertAttFound(prevAttsB, 1)
|
||||
|
||||
// Extends state a attestations.
|
||||
require.NoError(t, a.AppendCurrentEpochAttestations(atts[1]))
|
||||
require.NoError(t, a.AppendPreviousEpochAttestations(atts[1]))
|
||||
curAtt, err = a.CurrentEpochAttestations()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 2, len(curAtt), "Unexpected number of attestations")
|
||||
preAtt, err = a.PreviousEpochAttestations()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 2, len(preAtt), "Unexpected number of attestations")
|
||||
assertAttFound(a.state.GetCurrentEpochAttestations(), 1)
|
||||
assertAttFound(a.state.GetPreviousEpochAttestations(), 1)
|
||||
assertAttFound(a.state.GetCurrentEpochAttestations(), 2)
|
||||
assertAttFound(a.state.GetPreviousEpochAttestations(), 2)
|
||||
assertAttFound(b.state.GetCurrentEpochAttestations(), 1)
|
||||
assertAttFound(b.state.GetPreviousEpochAttestations(), 1)
|
||||
assertAttNotFound(b.state.GetCurrentEpochAttestations(), 2)
|
||||
assertAttNotFound(b.state.GetPreviousEpochAttestations(), 2)
|
||||
|
||||
// Mutator should only affect calling state: a.
|
||||
applyToEveryAttestation := func(state *ethpb.BeaconState) {
|
||||
// One MUST copy on write.
|
||||
atts = make([]*ethpb.PendingAttestation, len(state.CurrentEpochAttestations))
|
||||
copy(atts, state.CurrentEpochAttestations)
|
||||
state.CurrentEpochAttestations = atts
|
||||
for i := range state.GetCurrentEpochAttestations() {
|
||||
att := ethpb.CopyPendingAttestation(state.CurrentEpochAttestations[i])
|
||||
att.AggregationBits = bitfield.NewBitlist(3)
|
||||
state.CurrentEpochAttestations[i] = att
|
||||
}
|
||||
|
||||
atts = make([]*ethpb.PendingAttestation, len(state.PreviousEpochAttestations))
|
||||
copy(atts, state.PreviousEpochAttestations)
|
||||
state.PreviousEpochAttestations = atts
|
||||
for i := range state.GetPreviousEpochAttestations() {
|
||||
att := ethpb.CopyPendingAttestation(state.PreviousEpochAttestations[i])
|
||||
att.AggregationBits = bitfield.NewBitlist(3)
|
||||
state.PreviousEpochAttestations[i] = att
|
||||
}
|
||||
}
|
||||
applyToEveryAttestation(a.state)
|
||||
|
||||
// Assert no shared state mutation occurred only on state a (copy on write).
|
||||
assertAttFound(a.state.GetCurrentEpochAttestations(), 3)
|
||||
assertAttFound(a.state.GetPreviousEpochAttestations(), 3)
|
||||
assertAttNotFound(a.state.GetCurrentEpochAttestations(), 1)
|
||||
assertAttNotFound(a.state.GetPreviousEpochAttestations(), 1)
|
||||
assertAttNotFound(a.state.GetCurrentEpochAttestations(), 2)
|
||||
assertAttNotFound(a.state.GetPreviousEpochAttestations(), 2)
|
||||
// State b must be unaffected.
|
||||
assertAttNotFound(b.state.GetCurrentEpochAttestations(), 3)
|
||||
assertAttNotFound(b.state.GetPreviousEpochAttestations(), 3)
|
||||
assertAttFound(b.state.GetCurrentEpochAttestations(), 1)
|
||||
assertAttFound(b.state.GetPreviousEpochAttestations(), 1)
|
||||
assertAttNotFound(b.state.GetCurrentEpochAttestations(), 2)
|
||||
assertAttNotFound(b.state.GetPreviousEpochAttestations(), 2)
|
||||
|
||||
// Copy on write happened, reference counters are reset.
|
||||
assertRefCount(t, a, currentEpochAttestations, 1)
|
||||
assertRefCount(t, b, currentEpochAttestations, 1)
|
||||
assertRefCount(t, a, previousEpochAttestations, 1)
|
||||
assertRefCount(t, b, previousEpochAttestations, 1)
|
||||
}
|
||||
|
||||
func TestValidatorReferences_RemainsConsistent(t *testing.T) {
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconState{
|
||||
Validators: []*ethpb.Validator{
|
||||
{PublicKey: []byte{'A'}},
|
||||
{PublicKey: []byte{'B'}},
|
||||
{PublicKey: []byte{'C'}},
|
||||
{PublicKey: []byte{'D'}},
|
||||
{PublicKey: []byte{'E'}},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
a, ok := s.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
|
||||
// Create a second state.
|
||||
copied := a.Copy()
|
||||
b, ok := copied.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
|
||||
// Update First Validator.
|
||||
assert.NoError(t, a.UpdateValidatorAtIndex(0, ðpb.Validator{PublicKey: []byte{'Z'}}))
|
||||
|
||||
assert.DeepNotEqual(t, a.state.Validators[0], b.state.Validators[0], "validators are equal when they are supposed to be different")
|
||||
// Modify all validators from copied state.
|
||||
assert.NoError(t, b.ApplyToEveryValidator(func(idx int, val *ethpb.Validator) (bool, *ethpb.Validator, error) {
|
||||
return true, ðpb.Validator{PublicKey: []byte{'V'}}, nil
|
||||
}))
|
||||
|
||||
// Ensure reference is properly accounted for.
|
||||
assert.NoError(t, a.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
|
||||
assert.NotEqual(t, bytesutil.ToBytes48([]byte{'V'}), val.PublicKey())
|
||||
return nil
|
||||
}))
|
||||
}
|
||||
|
||||
// assertRefCount checks whether reference count for a given state
|
||||
// at a given index is equal to expected amount.
|
||||
func assertRefCount(t *testing.T, b *BeaconState, idx types.FieldIndex, want uint) {
|
||||
if cnt := b.sharedFieldReferences[idx].Refs(); cnt != want {
|
||||
t.Errorf("Unexpected count of references for index %d, want: %v, got: %v", idx, want, cnt)
|
||||
}
|
||||
}
|
||||
|
||||
// assertValFound checks whether item with a given value exists in list.
|
||||
func assertValFound(t *testing.T, vals [][]byte, val []byte) {
|
||||
for i := range vals {
|
||||
if reflect.DeepEqual(vals[i], val) {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Log(string(debug.Stack()))
|
||||
t.Fatalf("Expected value not found (%v), want: %v", vals, val)
|
||||
}
|
||||
|
||||
// assertValNotFound checks whether item with a given value doesn't exist in list.
|
||||
func assertValNotFound(t *testing.T, vals [][]byte, val []byte) {
|
||||
for i := range vals {
|
||||
if reflect.DeepEqual(vals[i], val) {
|
||||
t.Log(string(debug.Stack()))
|
||||
t.Errorf("Unexpected value found (%v),: %v", vals, val)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
stateTypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_RotateAttestations(t *testing.T) {
|
||||
st, err := InitializeFromProto(ðpb.BeaconState{
|
||||
Slot: 1,
|
||||
CurrentEpochAttestations: []*ethpb.PendingAttestation{{Data: ðpb.AttestationData{Slot: 456}}},
|
||||
PreviousEpochAttestations: []*ethpb.PendingAttestation{{Data: ðpb.AttestationData{Slot: 123}}},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, st.RotateAttestations())
|
||||
s, ok := st.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
require.Equal(t, 0, len(s.currentEpochAttestations()))
|
||||
require.Equal(t, types.Slot(456), s.previousEpochAttestations()[0].Data.Slot)
|
||||
}
|
||||
|
||||
func TestAppendBeyondIndicesLimit(t *testing.T) {
|
||||
zeroHash := params.BeaconConfig().ZeroHash
|
||||
mockblockRoots := make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
|
||||
for i := 0; i < len(mockblockRoots); i++ {
|
||||
mockblockRoots[i] = zeroHash[:]
|
||||
}
|
||||
|
||||
mockstateRoots := make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
|
||||
for i := 0; i < len(mockstateRoots); i++ {
|
||||
mockstateRoots[i] = zeroHash[:]
|
||||
}
|
||||
mockrandaoMixes := make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector)
|
||||
for i := 0; i < len(mockrandaoMixes); i++ {
|
||||
mockrandaoMixes[i] = zeroHash[:]
|
||||
}
|
||||
newState, err := InitializeFromProto(ðpb.BeaconState{
|
||||
Slot: 1,
|
||||
CurrentEpochAttestations: []*ethpb.PendingAttestation{{Data: ðpb.AttestationData{Slot: 456}}},
|
||||
PreviousEpochAttestations: []*ethpb.PendingAttestation{{Data: ðpb.AttestationData{Slot: 123}}},
|
||||
Validators: []*ethpb.Validator{},
|
||||
Eth1Data: ðpb.Eth1Data{},
|
||||
BlockRoots: mockblockRoots,
|
||||
StateRoots: mockstateRoots,
|
||||
RandaoMixes: mockrandaoMixes,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
_, err = newState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
st, ok := newState.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
for i := stateTypes.FieldIndex(0); i < stateTypes.FieldIndex(params.BeaconConfig().BeaconStateFieldCount); i++ {
|
||||
st.dirtyFields[i] = true
|
||||
}
|
||||
_, err = st.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < 10; i++ {
|
||||
assert.NoError(t, st.AppendValidator(ðpb.Validator{}))
|
||||
}
|
||||
assert.Equal(t, false, st.rebuildTrie[validators])
|
||||
assert.NotEqual(t, len(st.dirtyIndices[validators]), 0)
|
||||
|
||||
for i := 0; i < indicesLimit; i++ {
|
||||
assert.NoError(t, st.AppendValidator(ðpb.Validator{}))
|
||||
}
|
||||
assert.Equal(t, true, st.rebuildTrie[validators])
|
||||
assert.Equal(t, len(st.dirtyIndices[validators]), 0)
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
//go:build go1.18
|
||||
|
||||
package v1_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
|
||||
coreState "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition"
|
||||
native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/rand"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
)
|
||||
|
||||
func FuzzV1StateHashTreeRoot(f *testing.F) {
|
||||
gState, _ := util.DeterministicGenesisState(f, 100)
|
||||
output, err := gState.MarshalSSZ()
|
||||
assert.NoError(f, err)
|
||||
randPool := make([]byte, 100)
|
||||
_, err = rand.NewDeterministicGenerator().Read(randPool)
|
||||
assert.NoError(f, err)
|
||||
f.Add(randPool, uint64(10))
|
||||
f.Fuzz(func(t *testing.T, diffBuffer []byte, slotsToTransition uint64) {
|
||||
stateSSZ := bytesutil.SafeCopyBytes(output)
|
||||
for i := 0; i < len(diffBuffer); i += 9 {
|
||||
if i+8 >= len(diffBuffer) {
|
||||
return
|
||||
}
|
||||
num := bytesutil.BytesToUint64BigEndian(diffBuffer[i : i+8])
|
||||
num %= uint64(len(diffBuffer))
|
||||
// Perform a XOR on the byte of the selected index.
|
||||
stateSSZ[num] ^= diffBuffer[i+8]
|
||||
}
|
||||
pbState := ðpb.BeaconState{}
|
||||
err := pbState.UnmarshalSSZ(stateSSZ)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
nativeState, err := native.InitializeFromProtoPhase0(pbState)
|
||||
assert.NoError(t, err)
|
||||
|
||||
slotsToTransition %= 100
|
||||
stateObj, err := v1.InitializeFromProtoUnsafe(pbState)
|
||||
assert.NoError(t, err)
|
||||
for stateObj.Slot() < types.Slot(slotsToTransition) {
|
||||
stateObj, err = coreState.ProcessSlots(context.Background(), stateObj, stateObj.Slot()+1)
|
||||
assert.NoError(t, err)
|
||||
stateObj.Copy()
|
||||
|
||||
nativeState, err = coreState.ProcessSlots(context.Background(), nativeState, nativeState.Slot()+1)
|
||||
assert.NoError(t, err)
|
||||
nativeState.Copy()
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
// Perform a cold HTR calculation by initializing a new state.
|
||||
innerState, ok := stateObj.InnerStateUnsafe().(*ethpb.BeaconState)
|
||||
assert.Equal(t, true, ok, "inner state is a not a beacon state proto")
|
||||
newState, err := v1.InitializeFromProtoUnsafe(innerState)
|
||||
assert.NoError(t, err)
|
||||
|
||||
newRt, newErr := newState.HashTreeRoot(context.Background())
|
||||
rt, err := stateObj.HashTreeRoot(context.Background())
|
||||
nativeRt, nativeErr := nativeState.HashTreeRoot(context.Background())
|
||||
|
||||
assert.Equal(t, newErr != nil, err != nil)
|
||||
assert.Equal(t, newErr != nil, nativeErr != nil)
|
||||
if err == nil {
|
||||
assert.Equal(t, rt, newRt)
|
||||
assert.Equal(t, rt, nativeRt)
|
||||
}
|
||||
|
||||
newSSZ, newErr := newState.MarshalSSZ()
|
||||
stateObjSSZ, err := stateObj.MarshalSSZ()
|
||||
nativeSSZ, nativeErr := nativeState.MarshalSSZ()
|
||||
assert.Equal(t, newErr != nil, err != nil)
|
||||
assert.Equal(t, newErr != nil, nativeErr != nil)
|
||||
if err == nil {
|
||||
assert.DeepEqual(t, newSSZ, stateObjSSZ)
|
||||
assert.DeepEqual(t, newSSZ, nativeSSZ)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzV1StateUnmarshalSSZ(f *testing.F) {
|
||||
// See example in https://github.com/prysmaticlabs/prysm/issues/5167
|
||||
b, err := base64.StdEncoding.DecodeString("AgAGAAAA5AAAAAAAAAAAAAAAAAAAAAAAAAB51og2NJR6COTeAGdBDUL2wythbDd/ntOHzD/JAg6kywEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHnWiDY0lHoI5N4AZ0ENQvbDK2FsN3+e04fMP8kCDqTLti/UWQrIlR5nKGy5okElUBusCaDxo+6f0kX7B54ry9byYg5qzCruPLf/SccXww14BppwTrLrI/CqCbt6AWTO4kS/jz0no8RYv4wBhofviY9/W28LdzMhh6XVRUzK2Us4/wE=")
|
||||
require.NoError(f, err)
|
||||
f.Add(b)
|
||||
|
||||
f.Fuzz(func(t *testing.T, b []byte) {
|
||||
pbState := ðpb.BeaconState{}
|
||||
if err := pbState.UnmarshalSSZ(b); err != nil {
|
||||
return // Do nothing
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,214 +0,0 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestValidatorMap_DistinctCopy(t *testing.T) {
|
||||
count := uint64(100)
|
||||
vals := make([]*ethpb.Validator, 0, count)
|
||||
for i := uint64(1); i < count; i++ {
|
||||
someRoot := [32]byte{}
|
||||
someKey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(someRoot[:], strconv.Itoa(int(i)))
|
||||
copy(someKey[:], strconv.Itoa(int(i)))
|
||||
vals = append(vals, ðpb.Validator{
|
||||
PublicKey: someKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1,
|
||||
ActivationEpoch: 1,
|
||||
ExitEpoch: 1,
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
}
|
||||
handler := stateutil.NewValMapHandler(vals)
|
||||
newHandler := handler.Copy()
|
||||
wantedPubkey := strconv.Itoa(22)
|
||||
handler.Set(bytesutil.ToBytes48([]byte(wantedPubkey)), 27)
|
||||
val1, _ := handler.Get(bytesutil.ToBytes48([]byte(wantedPubkey)))
|
||||
val2, _ := newHandler.Get(bytesutil.ToBytes48([]byte(wantedPubkey)))
|
||||
assert.NotEqual(t, val1, val2, "Values are supposed to be unequal due to copy")
|
||||
}
|
||||
|
||||
func TestBeaconState_NoDeadlock(t *testing.T) {
|
||||
count := uint64(100)
|
||||
vals := make([]*ethpb.Validator, 0, count)
|
||||
for i := uint64(1); i < count; i++ {
|
||||
someRoot := [32]byte{}
|
||||
someKey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(someRoot[:], strconv.Itoa(int(i)))
|
||||
copy(someKey[:], strconv.Itoa(int(i)))
|
||||
vals = append(vals, ðpb.Validator{
|
||||
PublicKey: someKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1,
|
||||
ActivationEpoch: 1,
|
||||
ExitEpoch: 1,
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
}
|
||||
newState, err := InitializeFromProtoUnsafe(ðpb.BeaconState{
|
||||
Validators: vals,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
st, ok := newState.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
|
||||
wg := new(sync.WaitGroup)
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
// Continuously lock and unlock the state
|
||||
// by acquiring the lock.
|
||||
for i := 0; i < 1000; i++ {
|
||||
for _, f := range st.stateFieldLeaves {
|
||||
f.Lock()
|
||||
if f.Empty() {
|
||||
f.InsertFieldLayer(make([][]*[32]byte, 10))
|
||||
}
|
||||
f.Unlock()
|
||||
f.FieldReference().AddRef()
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
// Constantly read from the offending portion
|
||||
// of the code to ensure there is no possible
|
||||
// recursive read locking.
|
||||
for i := 0; i < 1000; i++ {
|
||||
go func() {
|
||||
_ = st.FieldReferencesCount()
|
||||
}()
|
||||
}
|
||||
// Test will not terminate in the event of a deadlock.
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestStateTrie_IsNil(t *testing.T) {
|
||||
var emptyState *BeaconState
|
||||
assert.Equal(t, true, emptyState.IsNil())
|
||||
|
||||
emptyProto := &BeaconState{state: nil}
|
||||
assert.Equal(t, true, emptyProto.IsNil())
|
||||
|
||||
nonNilState := &BeaconState{state: ðpb.BeaconState{}}
|
||||
assert.Equal(t, false, nonNilState.IsNil())
|
||||
}
|
||||
|
||||
func TestBeaconState_AppendBalanceWithTrie(t *testing.T) {
|
||||
count := uint64(100)
|
||||
vals := make([]*ethpb.Validator, 0, count)
|
||||
bals := make([]uint64, 0, count)
|
||||
for i := uint64(1); i < count; i++ {
|
||||
someRoot := [32]byte{}
|
||||
someKey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(someRoot[:], strconv.Itoa(int(i)))
|
||||
copy(someKey[:], strconv.Itoa(int(i)))
|
||||
vals = append(vals, ðpb.Validator{
|
||||
PublicKey: someKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1,
|
||||
ActivationEpoch: 1,
|
||||
ExitEpoch: 1,
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
bals = append(bals, params.BeaconConfig().MaxEffectiveBalance)
|
||||
}
|
||||
zeroHash := params.BeaconConfig().ZeroHash
|
||||
mockblockRoots := make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
|
||||
for i := 0; i < len(mockblockRoots); i++ {
|
||||
mockblockRoots[i] = zeroHash[:]
|
||||
}
|
||||
|
||||
mockstateRoots := make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
|
||||
for i := 0; i < len(mockstateRoots); i++ {
|
||||
mockstateRoots[i] = zeroHash[:]
|
||||
}
|
||||
mockrandaoMixes := make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector)
|
||||
for i := 0; i < len(mockrandaoMixes); i++ {
|
||||
mockrandaoMixes[i] = zeroHash[:]
|
||||
}
|
||||
newState, err := InitializeFromProto(ðpb.BeaconState{
|
||||
Slot: 1,
|
||||
GenesisValidatorsRoot: make([]byte, 32),
|
||||
Fork: ðpb.Fork{
|
||||
PreviousVersion: make([]byte, 4),
|
||||
CurrentVersion: make([]byte, 4),
|
||||
Epoch: 0,
|
||||
},
|
||||
LatestBlockHeader: ðpb.BeaconBlockHeader{
|
||||
ParentRoot: make([]byte, fieldparams.RootLength),
|
||||
StateRoot: make([]byte, fieldparams.RootLength),
|
||||
BodyRoot: make([]byte, fieldparams.RootLength),
|
||||
},
|
||||
Validators: vals,
|
||||
Balances: bals,
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: make([]byte, 32),
|
||||
},
|
||||
BlockRoots: mockblockRoots,
|
||||
StateRoots: mockstateRoots,
|
||||
RandaoMixes: mockrandaoMixes,
|
||||
JustificationBits: bitfield.NewBitvector4(),
|
||||
PreviousJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)},
|
||||
CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)},
|
||||
Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
st, ok := newState.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
_, err = st.HashTreeRoot(context.Background())
|
||||
assert.NoError(t, err)
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
if i%2 == 0 {
|
||||
assert.NoError(t, st.UpdateBalancesAtIndex(types.ValidatorIndex(i), 1000))
|
||||
}
|
||||
if i%3 == 0 {
|
||||
assert.NoError(t, st.AppendBalance(1000))
|
||||
}
|
||||
}
|
||||
_, err = st.HashTreeRoot(context.Background())
|
||||
assert.NoError(t, err)
|
||||
newRt := bytesutil.ToBytes32(st.merkleLayers[0][balances])
|
||||
wantedRt, err := stateutil.Uint64ListRootWithRegistryLimit(st.state.Balances)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, wantedRt, newRt, "state roots are unequal")
|
||||
}
|
||||
|
||||
func TestBeaconState_ModifyPreviousParticipationBits(t *testing.T) {
|
||||
st, err := InitializeFromProtoUnsafe(ðpb.BeaconState{})
|
||||
assert.NoError(t, err)
|
||||
assert.ErrorContains(t, "ModifyPreviousParticipationBits is not supported for phase 0 beacon state", st.ModifyPreviousParticipationBits(func(val []byte) ([]byte, error) {
|
||||
return nil, nil
|
||||
}))
|
||||
}
|
||||
|
||||
func TestBeaconState_ModifyCurrentParticipationBits(t *testing.T) {
|
||||
st, err := InitializeFromProtoUnsafe(ðpb.BeaconState{})
|
||||
assert.NoError(t, err)
|
||||
assert.ErrorContains(t, "ModifyCurrentParticipationBits is not supported for phase 0 beacon state", st.ModifyCurrentParticipationBits(func(val []byte) ([]byte, error) {
|
||||
return nil, nil
|
||||
}))
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/slice"
|
||||
@@ -25,61 +24,13 @@ import (
|
||||
|
||||
// InitializeFromProto the beacon state from a protobuf representation.
|
||||
func InitializeFromProto(st *ethpb.BeaconState) (state.BeaconState, error) {
|
||||
if features.Get().EnableNativeState {
|
||||
return statenative.InitializeFromProtoPhase0(proto.Clone(st).(*ethpb.BeaconState))
|
||||
}
|
||||
return InitializeFromProtoUnsafe(proto.Clone(st).(*ethpb.BeaconState))
|
||||
return statenative.InitializeFromProtoUnsafePhase0(proto.Clone(st).(*ethpb.BeaconState))
|
||||
}
|
||||
|
||||
// InitializeFromProtoUnsafe directly uses the beacon state protobuf pointer
|
||||
// and sets it as the inner state of the BeaconState type.
|
||||
func InitializeFromProtoUnsafe(st *ethpb.BeaconState) (state.BeaconState, error) {
|
||||
if features.Get().EnableNativeState {
|
||||
return statenative.InitializeFromProtoUnsafePhase0(st)
|
||||
}
|
||||
|
||||
if st == nil {
|
||||
return nil, errors.New("received nil state")
|
||||
}
|
||||
|
||||
fieldCount := params.BeaconConfig().BeaconStateFieldCount
|
||||
b := &BeaconState{
|
||||
state: st,
|
||||
dirtyFields: make(map[types.FieldIndex]bool, fieldCount),
|
||||
dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount),
|
||||
stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount),
|
||||
sharedFieldReferences: make(map[types.FieldIndex]*stateutil.Reference, 10),
|
||||
rebuildTrie: make(map[types.FieldIndex]bool, fieldCount),
|
||||
valMapHandler: stateutil.NewValMapHandler(st.Validators),
|
||||
}
|
||||
|
||||
var err error
|
||||
for i := 0; i < fieldCount; i++ {
|
||||
b.dirtyFields[types.FieldIndex(i)] = true
|
||||
b.rebuildTrie[types.FieldIndex(i)] = true
|
||||
b.dirtyIndices[types.FieldIndex(i)] = []uint64{}
|
||||
b.stateFieldLeaves[types.FieldIndex(i)], err = fieldtrie.NewFieldTrie(types.FieldIndex(i), types.BasicArray, nil, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize field reference tracking for shared data.
|
||||
b.sharedFieldReferences[randaoMixes] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[stateRoots] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[blockRoots] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[previousEpochAttestations] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[currentEpochAttestations] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[slashings] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[eth1DataVotes] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[validators] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[balances] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[historicalRoots] = stateutil.NewRef(1)
|
||||
|
||||
state.StateCount.Inc()
|
||||
// Finalizer runs when dst is being destroyed in garbage collection.
|
||||
runtime.SetFinalizer(b, finalizerCleanup)
|
||||
return b, nil
|
||||
return statenative.InitializeFromProtoUnsafePhase0(st)
|
||||
}
|
||||
|
||||
// Copy returns a deep copy of the beacon state.
|
||||
|
||||
@@ -1,338 +0,0 @@
|
||||
package v1_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
)
|
||||
|
||||
func TestInitializeFromProto(t *testing.T) {
|
||||
testState, _ := util.DeterministicGenesisState(t, 64)
|
||||
pbState, err := v1.ProtobufBeaconState(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
type test struct {
|
||||
name string
|
||||
state *ethpb.BeaconState
|
||||
error string
|
||||
}
|
||||
initTests := []test{
|
||||
{
|
||||
name: "nil state",
|
||||
state: nil,
|
||||
error: "received nil state",
|
||||
},
|
||||
{
|
||||
name: "nil validators",
|
||||
state: ðpb.BeaconState{
|
||||
Slot: 4,
|
||||
Validators: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty state",
|
||||
state: ðpb.BeaconState{},
|
||||
},
|
||||
{
|
||||
name: "full state",
|
||||
state: pbState,
|
||||
},
|
||||
}
|
||||
for _, tt := range initTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := v1.InitializeFromProto(tt.state)
|
||||
if tt.error != "" {
|
||||
assert.ErrorContains(t, tt.error, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitializeFromProtoUnsafe(t *testing.T) {
|
||||
testState, _ := util.DeterministicGenesisState(t, 64)
|
||||
pbState, err := v1.ProtobufBeaconState(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
type test struct {
|
||||
name string
|
||||
state *ethpb.BeaconState
|
||||
error string
|
||||
}
|
||||
initTests := []test{
|
||||
{
|
||||
name: "nil state",
|
||||
state: nil,
|
||||
error: "received nil state",
|
||||
},
|
||||
{
|
||||
name: "nil validators",
|
||||
state: ðpb.BeaconState{
|
||||
Slot: 4,
|
||||
Validators: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty state",
|
||||
state: ðpb.BeaconState{},
|
||||
},
|
||||
{
|
||||
name: "full state",
|
||||
state: pbState,
|
||||
},
|
||||
}
|
||||
for _, tt := range initTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := v1.InitializeFromProtoUnsafe(tt.state)
|
||||
if tt.error != "" {
|
||||
assert.ErrorContains(t, tt.error, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBeaconState_HashTreeRoot(t *testing.T) {
|
||||
testState, _ := util.DeterministicGenesisState(t, 64)
|
||||
|
||||
type test struct {
|
||||
name string
|
||||
stateModify func(beaconState state.BeaconState) (state.BeaconState, error)
|
||||
error string
|
||||
}
|
||||
initTests := []test{
|
||||
{
|
||||
name: "unchanged state",
|
||||
stateModify: func(beaconState state.BeaconState) (state.BeaconState, error) {
|
||||
return beaconState, nil
|
||||
},
|
||||
error: "",
|
||||
},
|
||||
{
|
||||
name: "different slot",
|
||||
stateModify: func(beaconState state.BeaconState) (state.BeaconState, error) {
|
||||
if err := beaconState.SetSlot(5); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return beaconState, nil
|
||||
},
|
||||
error: "",
|
||||
},
|
||||
{
|
||||
name: "different validator balance",
|
||||
stateModify: func(beaconState state.BeaconState) (state.BeaconState, error) {
|
||||
val, err := beaconState.ValidatorAtIndex(5)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
val.EffectiveBalance = params.BeaconConfig().MaxEffectiveBalance - params.BeaconConfig().EffectiveBalanceIncrement
|
||||
if err := beaconState.UpdateValidatorAtIndex(5, val); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return beaconState, nil
|
||||
},
|
||||
error: "",
|
||||
},
|
||||
}
|
||||
|
||||
var err error
|
||||
var oldHTR []byte
|
||||
for _, tt := range initTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
testState, err = tt.stateModify(testState)
|
||||
assert.NoError(t, err)
|
||||
root, err := testState.HashTreeRoot(context.Background())
|
||||
if err == nil && tt.error != "" {
|
||||
t.Errorf("Expected error, expected %v, recevied %v", tt.error, err)
|
||||
}
|
||||
pbState, err := v1.ProtobufBeaconState(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
genericHTR, err := pbState.HashTreeRoot()
|
||||
if err == nil && tt.error != "" {
|
||||
t.Errorf("Expected error, expected %v, recevied %v", tt.error, err)
|
||||
}
|
||||
assert.DeepNotEqual(t, []byte{}, root[:], "Received empty hash tree root")
|
||||
assert.DeepEqual(t, genericHTR[:], root[:], "Expected hash tree root to match generic")
|
||||
if len(oldHTR) != 0 && bytes.Equal(root[:], oldHTR) {
|
||||
t.Errorf("Expected HTR to change, received %#x == old %#x", root, oldHTR)
|
||||
}
|
||||
oldHTR = root[:]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBeaconState(b *testing.B) {
|
||||
testState, _ := util.DeterministicGenesisState(b, 16000)
|
||||
pbState, err := v1.ProtobufBeaconState(testState.InnerStateUnsafe())
|
||||
require.NoError(b, err)
|
||||
|
||||
b.Run("Vectorized SHA256", func(b *testing.B) {
|
||||
st, err := v1.InitializeFromProtoUnsafe(pbState)
|
||||
require.NoError(b, err)
|
||||
_, err = st.HashTreeRoot(context.Background())
|
||||
assert.NoError(b, err)
|
||||
})
|
||||
|
||||
b.Run("Current SHA256", func(b *testing.B) {
|
||||
_, err := pbState.HashTreeRoot()
|
||||
require.NoError(b, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_HashTreeRoot_FieldTrie(t *testing.T) {
|
||||
testState, _ := util.DeterministicGenesisState(t, 64)
|
||||
|
||||
type test struct {
|
||||
name string
|
||||
stateModify func(state.BeaconState) (state.BeaconState, error)
|
||||
error string
|
||||
}
|
||||
initTests := []test{
|
||||
{
|
||||
name: "unchanged state",
|
||||
stateModify: func(beaconState state.BeaconState) (state.BeaconState, error) {
|
||||
return beaconState, nil
|
||||
},
|
||||
error: "",
|
||||
},
|
||||
{
|
||||
name: "different slot",
|
||||
stateModify: func(beaconState state.BeaconState) (state.BeaconState, error) {
|
||||
if err := beaconState.SetSlot(5); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return beaconState, nil
|
||||
},
|
||||
error: "",
|
||||
},
|
||||
{
|
||||
name: "different validator balance",
|
||||
stateModify: func(beaconState state.BeaconState) (state.BeaconState, error) {
|
||||
val, err := beaconState.ValidatorAtIndex(5)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
val.EffectiveBalance = params.BeaconConfig().MaxEffectiveBalance - params.BeaconConfig().EffectiveBalanceIncrement
|
||||
if err := beaconState.UpdateValidatorAtIndex(5, val); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return beaconState, nil
|
||||
},
|
||||
error: "",
|
||||
},
|
||||
}
|
||||
|
||||
var err error
|
||||
var oldHTR []byte
|
||||
for _, tt := range initTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
testState, err = tt.stateModify(testState)
|
||||
assert.NoError(t, err)
|
||||
root, err := testState.HashTreeRoot(context.Background())
|
||||
if err == nil && tt.error != "" {
|
||||
t.Errorf("Expected error, expected %v, recevied %v", tt.error, err)
|
||||
}
|
||||
pbState, err := v1.ProtobufBeaconState(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
genericHTR, err := pbState.HashTreeRoot()
|
||||
if err == nil && tt.error != "" {
|
||||
t.Errorf("Expected error, expected %v, recevied %v", tt.error, err)
|
||||
}
|
||||
assert.DeepNotEqual(t, []byte{}, root[:], "Received empty hash tree root")
|
||||
assert.DeepEqual(t, genericHTR[:], root[:], "Expected hash tree root to match generic")
|
||||
if len(oldHTR) != 0 && bytes.Equal(root[:], oldHTR) {
|
||||
t.Errorf("Expected HTR to change, received %#x == old %#x", root, oldHTR)
|
||||
}
|
||||
oldHTR = root[:]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBeaconState_AppendValidator_DoesntMutateCopy(t *testing.T) {
|
||||
st0, err := util.NewBeaconState()
|
||||
require.NoError(t, err)
|
||||
st1 := st0.Copy()
|
||||
originalCount := st1.NumValidators()
|
||||
|
||||
val := ðpb.Validator{Slashed: true}
|
||||
assert.NoError(t, st0.AppendValidator(val))
|
||||
assert.Equal(t, originalCount, st1.NumValidators(), "st1 NumValidators mutated")
|
||||
_, ok := st1.ValidatorIndexByPubkey(bytesutil.ToBytes48(val.PublicKey))
|
||||
assert.Equal(t, false, ok, "Expected no validator index to be present in st1 for the newly inserted pubkey")
|
||||
}
|
||||
|
||||
func TestBeaconState_ValidatorMutation_Phase0(t *testing.T) {
|
||||
testState, _ := util.DeterministicGenesisState(t, 400)
|
||||
pbState, err := v1.ProtobufBeaconState(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
testState, err = v1.InitializeFromProto(pbState)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = testState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
// Reset tries
|
||||
require.NoError(t, testState.UpdateValidatorAtIndex(200, new(ethpb.Validator)))
|
||||
_, err = testState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
newState1 := testState.Copy()
|
||||
_ = testState.Copy()
|
||||
|
||||
require.NoError(t, testState.UpdateValidatorAtIndex(15, ðpb.Validator{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
EffectiveBalance: 1111,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1112,
|
||||
ActivationEpoch: 1114,
|
||||
ExitEpoch: 1116,
|
||||
WithdrawableEpoch: 1117,
|
||||
}))
|
||||
|
||||
rt, err := testState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
pbState, err = v1.ProtobufBeaconState(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
|
||||
copiedTestState, err := v1.InitializeFromProto(pbState)
|
||||
require.NoError(t, err)
|
||||
|
||||
rt2, err := copiedTestState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, rt, rt2)
|
||||
|
||||
require.NoError(t, newState1.UpdateValidatorAtIndex(150, ðpb.Validator{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
EffectiveBalance: 2111,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 2112,
|
||||
ActivationEpoch: 2114,
|
||||
ExitEpoch: 2116,
|
||||
WithdrawableEpoch: 2117,
|
||||
}))
|
||||
|
||||
rt, err = newState1.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
pbState, err = v1.ProtobufBeaconState(newState1.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
|
||||
copiedTestState, err = v1.InitializeFromProto(pbState)
|
||||
require.NoError(t, err)
|
||||
|
||||
rt2, err = copiedTestState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, rt, rt2)
|
||||
}
|
||||
@@ -1,232 +0,0 @@
|
||||
package v1_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/runtime/interop"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func TestBeaconState_ProtoBeaconStateCompatibility(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MinimalSpecConfig())
|
||||
ctx := context.Background()
|
||||
genesis := setupGenesisState(t, 64)
|
||||
customState, err := v1.InitializeFromProto(genesis)
|
||||
require.NoError(t, err)
|
||||
cloned, ok := proto.Clone(genesis).(*ethpb.BeaconState)
|
||||
assert.Equal(t, true, ok, "Object is not of type *ethpb.BeaconState")
|
||||
custom := customState.CloneInnerState()
|
||||
assert.DeepSSZEqual(t, cloned, custom)
|
||||
|
||||
r1, err := customState.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
beaconState, err := v1.InitializeFromProto(genesis)
|
||||
require.NoError(t, err)
|
||||
r2, err := beaconState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, r1, r2, "Mismatched roots")
|
||||
|
||||
// We then write to the the state and compare hash tree roots again.
|
||||
balances := genesis.Balances
|
||||
balances[0] = 3823
|
||||
require.NoError(t, customState.SetBalances(balances))
|
||||
r1, err = customState.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
genesis.Balances = balances
|
||||
beaconState, err = v1.InitializeFromProto(genesis)
|
||||
require.NoError(t, err)
|
||||
r2, err = beaconState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, r1, r2, "Mismatched roots")
|
||||
}
|
||||
|
||||
func setupGenesisState(tb testing.TB, count uint64) *ethpb.BeaconState {
|
||||
genesisState, _, err := interop.GenerateGenesisState(context.Background(), 0, count)
|
||||
require.NoError(tb, err, "Could not generate genesis beacon state")
|
||||
for i := uint64(1); i < count; i++ {
|
||||
someRoot := [32]byte{}
|
||||
someKey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(someRoot[:], strconv.Itoa(int(i)))
|
||||
copy(someKey[:], strconv.Itoa(int(i)))
|
||||
genesisState.Validators = append(genesisState.Validators, ðpb.Validator{
|
||||
PublicKey: someKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1,
|
||||
ActivationEpoch: 1,
|
||||
ExitEpoch: 1,
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
genesisState.Balances = append(genesisState.Balances, params.BeaconConfig().MaxEffectiveBalance)
|
||||
}
|
||||
return genesisState
|
||||
}
|
||||
|
||||
func BenchmarkCloneValidators_Proto(b *testing.B) {
|
||||
b.StopTimer()
|
||||
validators := make([]*ethpb.Validator, 16384)
|
||||
somePubKey := [fieldparams.BLSPubkeyLength]byte{1, 2, 3}
|
||||
someRoot := [32]byte{3, 4, 5}
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
PublicKey: somePubKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
ActivationEpoch: 3,
|
||||
ExitEpoch: 4,
|
||||
WithdrawableEpoch: 5,
|
||||
}
|
||||
}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cloneValidatorsWithProto(validators)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCloneValidators_Manual(b *testing.B) {
|
||||
b.StopTimer()
|
||||
validators := make([]*ethpb.Validator, 16384)
|
||||
somePubKey := [fieldparams.BLSPubkeyLength]byte{1, 2, 3}
|
||||
someRoot := [32]byte{3, 4, 5}
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
PublicKey: somePubKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
ActivationEpoch: 3,
|
||||
ExitEpoch: 4,
|
||||
WithdrawableEpoch: 5,
|
||||
}
|
||||
}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cloneValidatorsManually(validators)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkStateClone_Proto(b *testing.B) {
|
||||
b.StopTimer()
|
||||
params.SetupTestConfigCleanup(b)
|
||||
params.OverrideBeaconConfig(params.MinimalSpecConfig())
|
||||
genesis := setupGenesisState(b, 64)
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, ok := proto.Clone(genesis).(*ethpb.BeaconState)
|
||||
assert.Equal(b, true, ok, "Entity is not of type *ethpb.BeaconState")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkStateClone_Manual(b *testing.B) {
|
||||
b.StopTimer()
|
||||
params.SetupTestConfigCleanup(b)
|
||||
params.OverrideBeaconConfig(params.MinimalSpecConfig())
|
||||
genesis := setupGenesisState(b, 64)
|
||||
st, err := v1.InitializeFromProto(genesis)
|
||||
require.NoError(b, err)
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = st.CloneInnerState()
|
||||
}
|
||||
}
|
||||
|
||||
func cloneValidatorsWithProto(vals []*ethpb.Validator) []*ethpb.Validator {
|
||||
var ok bool
|
||||
res := make([]*ethpb.Validator, len(vals))
|
||||
for i := 0; i < len(res); i++ {
|
||||
res[i], ok = proto.Clone(vals[i]).(*ethpb.Validator)
|
||||
if !ok {
|
||||
log.Debug("Entity is not of type *ethpb.Validator")
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func cloneValidatorsManually(vals []*ethpb.Validator) []*ethpb.Validator {
|
||||
res := make([]*ethpb.Validator, len(vals))
|
||||
for i := 0; i < len(res); i++ {
|
||||
val := vals[i]
|
||||
res[i] = ðpb.Validator{
|
||||
PublicKey: val.PublicKey,
|
||||
WithdrawalCredentials: val.WithdrawalCredentials,
|
||||
EffectiveBalance: val.EffectiveBalance,
|
||||
Slashed: val.Slashed,
|
||||
ActivationEligibilityEpoch: val.ActivationEligibilityEpoch,
|
||||
ActivationEpoch: val.ActivationEpoch,
|
||||
ExitEpoch: val.ExitEpoch,
|
||||
WithdrawableEpoch: val.WithdrawableEpoch,
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func TestBeaconState_ImmutabilityWithSharedResources(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MinimalSpecConfig())
|
||||
genesis := setupGenesisState(t, 64)
|
||||
a, err := v1.InitializeFromProto(genesis)
|
||||
require.NoError(t, err)
|
||||
b := a.Copy()
|
||||
|
||||
// Randao mixes
|
||||
require.DeepEqual(t, a.RandaoMixes(), b.RandaoMixes(), "Test precondition failed, fields are not equal")
|
||||
require.NoError(t, a.UpdateRandaoMixesAtIndex(1, []byte("foo")))
|
||||
if reflect.DeepEqual(a.RandaoMixes(), b.RandaoMixes()) {
|
||||
t.Error("Expect a.RandaoMixes() to be different from b.RandaoMixes()")
|
||||
}
|
||||
|
||||
// Validators
|
||||
require.DeepEqual(t, a.Validators(), b.Validators(), "Test precondition failed, fields are not equal")
|
||||
require.NoError(t, a.UpdateValidatorAtIndex(1, ðpb.Validator{Slashed: true}))
|
||||
if reflect.DeepEqual(a.Validators(), b.Validators()) {
|
||||
t.Error("Expect a.Validators() to be different from b.Validators()")
|
||||
}
|
||||
|
||||
// State Roots
|
||||
require.DeepEqual(t, a.StateRoots(), b.StateRoots(), "Test precondition failed, fields are not equal")
|
||||
require.NoError(t, a.UpdateStateRootAtIndex(1, bytesutil.ToBytes32([]byte("foo"))))
|
||||
if reflect.DeepEqual(a.StateRoots(), b.StateRoots()) {
|
||||
t.Fatal("Expected a.StateRoots() to be different from b.StateRoots()")
|
||||
}
|
||||
|
||||
// Block Roots
|
||||
require.DeepEqual(t, a.BlockRoots(), b.BlockRoots(), "Test precondition failed, fields are not equal")
|
||||
require.NoError(t, a.UpdateBlockRootAtIndex(1, bytesutil.ToBytes32([]byte("foo"))))
|
||||
if reflect.DeepEqual(a.BlockRoots(), b.BlockRoots()) {
|
||||
t.Fatal("Expected a.BlockRoots() to be different from b.BlockRoots()")
|
||||
}
|
||||
}
|
||||
|
||||
func TestForkManualCopy_OK(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MinimalSpecConfig())
|
||||
genesis := setupGenesisState(t, 64)
|
||||
a, err := v1.InitializeFromProto(genesis)
|
||||
require.NoError(t, err)
|
||||
wantedFork := ðpb.Fork{
|
||||
PreviousVersion: []byte{'a', 'b', 'c'},
|
||||
CurrentVersion: []byte{'d', 'e', 'f'},
|
||||
Epoch: 0,
|
||||
}
|
||||
require.NoError(t, a.SetFork(wantedFork))
|
||||
|
||||
pbState, err := v1.ProtobufBeaconState(a.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, pbState.Fork, wantedFork)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
@@ -40,7 +40,6 @@ go_library(
|
||||
"//beacon-chain/state/stateutil:go_default_library",
|
||||
"//beacon-chain/state/types:go_default_library",
|
||||
"//beacon-chain/state/v1:go_default_library",
|
||||
"//config/features:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/interfaces:go_default_library",
|
||||
@@ -58,44 +57,3 @@ go_library(
|
||||
"@org_golang_google_protobuf//proto:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"deprecated_getters_test.go",
|
||||
"deprecated_setters_test.go",
|
||||
"getters_block_test.go",
|
||||
"getters_checkpoint_test.go",
|
||||
"getters_participation_test.go",
|
||||
"getters_test.go",
|
||||
"getters_validator_test.go",
|
||||
"proofs_test.go",
|
||||
"references_test.go",
|
||||
"setters_test.go",
|
||||
"state_fuzz_test.go",
|
||||
"state_test.go",
|
||||
"state_trie_test.go",
|
||||
],
|
||||
data = glob(["testdata/**"]),
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//beacon-chain/core/transition:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/state-native:go_default_library",
|
||||
"//beacon-chain/state/stateutil:go_default_library",
|
||||
"//beacon-chain/state/testing:go_default_library",
|
||||
"//beacon-chain/state/types:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
"//container/trie:go_default_library",
|
||||
"//crypto/bls:go_default_library",
|
||||
"//crypto/rand:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//testing/assert:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
"//testing/util:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_PreviousEpochAttestations(t *testing.T) {
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{})
|
||||
require.NoError(t, err)
|
||||
_, err = s.PreviousEpochAttestations()
|
||||
require.ErrorContains(t, "PreviousEpochAttestations is not supported for hard fork 1 beacon state", err)
|
||||
}
|
||||
|
||||
func TestBeaconState_CurrentEpochAttestations(t *testing.T) {
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{})
|
||||
require.NoError(t, err)
|
||||
_, err = s.CurrentEpochAttestations()
|
||||
require.ErrorContains(t, "CurrentEpochAttestations is not supported for hard fork 1 beacon state", err)
|
||||
}
|
||||
|
||||
func TestBeaconState_LatestExecutionPayloadHeader(t *testing.T) {
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{})
|
||||
require.NoError(t, err)
|
||||
_, err = s.LatestExecutionPayloadHeader()
|
||||
require.ErrorContains(t, "LatestExecutionPayloadHeader is not supported for hard fork 1 beacon state", err)
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_AppendCurrentEpochAttestations(t *testing.T) {
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{})
|
||||
require.NoError(t, err)
|
||||
require.ErrorContains(t, "AppendCurrentEpochAttestations is not supported", s.AppendCurrentEpochAttestations(nil))
|
||||
}
|
||||
|
||||
func TestBeaconState_AppendPreviousEpochAttestations(t *testing.T) {
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{})
|
||||
require.NoError(t, err)
|
||||
require.ErrorContains(t, "AppendPreviousEpochAttestations is not supported", s.AppendPreviousEpochAttestations(nil))
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
func TestBeaconState_LatestBlockHeader(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateLatestBlockHeader(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateAltair{})
|
||||
},
|
||||
func(BH *ethpb.BeaconBlockHeader) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateAltair{LatestBlockHeader: BH})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_BlockRoots(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateBlockRoots(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateAltair{})
|
||||
},
|
||||
func(BR [][]byte) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateAltair{BlockRoots: BR})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_BlockRootAtIndex(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateBlockRootAtIndex(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateAltair{})
|
||||
},
|
||||
func(BR [][]byte) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateAltair{BlockRoots: BR})
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
func TestBeaconState_JustificationBitsNil(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateJustificationBitsNil(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_JustificationBits(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateJustificationBits(
|
||||
t,
|
||||
func(bits bitfield.Bitvector4) (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{JustificationBits: bits})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_PreviousJustifiedCheckpointNil(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStatePreviousJustifiedCheckpointNil(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_PreviousJustifiedCheckpoint(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStatePreviousJustifiedCheckpoint(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{PreviousJustifiedCheckpoint: cp})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_CurrentJustifiedCheckpointNil(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateCurrentJustifiedCheckpointNil(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_CurrentJustifiedCheckpoint(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateCurrentJustifiedCheckpoint(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{CurrentJustifiedCheckpoint: cp})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_FinalizedCheckpointNil(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateFinalizedCheckpointNil(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_FinalizedCheckpoint(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateFinalizedCheckpoint(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{FinalizedCheckpoint: cp})
|
||||
})
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestState_UnrealizedCheckpointBalances(t *testing.T) {
|
||||
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
balances := make([]uint64, params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
}
|
||||
balances[i] = params.BeaconConfig().MaxEffectiveBalance
|
||||
}
|
||||
base := ðpb.BeaconStateAltair{
|
||||
Slot: 2,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
|
||||
Validators: validators,
|
||||
CurrentEpochParticipation: make([]byte, params.BeaconConfig().MinGenesisActiveValidatorCount),
|
||||
PreviousEpochParticipation: make([]byte, params.BeaconConfig().MinGenesisActiveValidatorCount),
|
||||
Balances: balances,
|
||||
}
|
||||
state, err := InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
|
||||
// No one voted in the last two epochs
|
||||
allActive := params.BeaconConfig().MinGenesisActiveValidatorCount * params.BeaconConfig().MaxEffectiveBalance
|
||||
active, previous, current, err := state.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, allActive, active)
|
||||
require.Equal(t, uint64(0), current)
|
||||
require.Equal(t, uint64(0), previous)
|
||||
|
||||
// Add some votes in the last two epochs:
|
||||
base.CurrentEpochParticipation[0] = 0xFF
|
||||
base.PreviousEpochParticipation[0] = 0xFF
|
||||
base.PreviousEpochParticipation[1] = 0xFF
|
||||
|
||||
state, err = InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
active, previous, current, err = state.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, allActive, active)
|
||||
require.Equal(t, params.BeaconConfig().MaxEffectiveBalance, current)
|
||||
require.Equal(t, 2*params.BeaconConfig().MaxEffectiveBalance, previous)
|
||||
|
||||
// Slash some validators
|
||||
validators[0].Slashed = true
|
||||
state, err = InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
active, previous, current, err = state.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, allActive-params.BeaconConfig().MaxEffectiveBalance, active)
|
||||
require.Equal(t, uint64(0), current)
|
||||
require.Equal(t, params.BeaconConfig().MaxEffectiveBalance, previous)
|
||||
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"runtime/debug"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_SlotDataRace(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateSlotDataRace(t, func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateAltair{Slot: 1})
|
||||
})
|
||||
}
|
||||
|
||||
func TestNilState_NoPanic(t *testing.T) {
|
||||
var st *BeaconState
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Errorf("Method panicked when it was not supposed to: %v\n%v\n", r, string(debug.Stack()))
|
||||
}
|
||||
}()
|
||||
// retrieve elements from nil state
|
||||
_ = st.GenesisTime()
|
||||
_ = st.GenesisValidatorsRoot()
|
||||
_ = st.GenesisValidatorsRoot()
|
||||
_ = st.Slot()
|
||||
_ = st.Fork()
|
||||
_ = st.LatestBlockHeader()
|
||||
_ = st.BlockRoots()
|
||||
_, err := st.BlockRootAtIndex(0)
|
||||
_ = err
|
||||
_ = st.StateRoots()
|
||||
_ = st.HistoricalRoots()
|
||||
_ = st.Eth1Data()
|
||||
_ = st.Eth1DataVotes()
|
||||
_ = st.Eth1DepositIndex()
|
||||
_, err = st.ValidatorAtIndex(0)
|
||||
_ = err
|
||||
_, err = st.ValidatorAtIndexReadOnly(0)
|
||||
_ = err
|
||||
_, _ = st.ValidatorIndexByPubkey([fieldparams.BLSPubkeyLength]byte{})
|
||||
_ = st.PubkeyAtIndex(0)
|
||||
_ = st.NumValidators()
|
||||
_ = st.Balances()
|
||||
_, err = st.BalanceAtIndex(0)
|
||||
_ = err
|
||||
_ = st.BalancesLength()
|
||||
_ = st.RandaoMixes()
|
||||
_, err = st.RandaoMixAtIndex(0)
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_ = st.RandaoMixesLength()
|
||||
_ = st.Slashings()
|
||||
_, err = st.CurrentEpochParticipation()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.PreviousEpochParticipation()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_ = st.JustificationBits()
|
||||
_ = err
|
||||
_ = st.PreviousJustifiedCheckpoint()
|
||||
_ = st.CurrentJustifiedCheckpoint()
|
||||
_ = st.FinalizedCheckpoint()
|
||||
_, err = st.CurrentEpochParticipation()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.PreviousEpochParticipation()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.InactivityScores()
|
||||
_ = err
|
||||
_, err = st.CurrentSyncCommittee()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.NextSyncCommittee()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, _, _, err = st.UnrealizedCheckpointBalances()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
}
|
||||
|
||||
func TestBeaconState_MatchCurrentJustifiedCheckpt(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateMatchCurrentJustifiedCheckpt(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateAltair{CurrentJustifiedCheckpoint: cp})
|
||||
},
|
||||
func(i state.BeaconState) {
|
||||
s, ok := i.(*BeaconState)
|
||||
if !ok {
|
||||
panic("error in type assertion in test template")
|
||||
}
|
||||
s.state = nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_MatchPreviousJustifiedCheckpt(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateMatchPreviousJustifiedCheckpt(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateAltair{PreviousJustifiedCheckpoint: cp})
|
||||
},
|
||||
func(i state.BeaconState) {
|
||||
s, ok := i.(*BeaconState)
|
||||
if !ok {
|
||||
panic("error in type assertion in test template")
|
||||
}
|
||||
s.state = nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_MarshalSSZ_NilState(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateMarshalSSZNilState(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateAltair{})
|
||||
},
|
||||
func(i state.BeaconState) {
|
||||
s, ok := i.(*BeaconState)
|
||||
if !ok {
|
||||
panic("error in type assertion in test template")
|
||||
}
|
||||
s.state = nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_ValidatorByPubkey(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateValidatorByPubkey(t, func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateAltair{})
|
||||
})
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package v2_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
||||
return v2.InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{
|
||||
Validators: nil,
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package v2_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/trie"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
)
|
||||
|
||||
func TestBeaconStateMerkleProofs(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
st, _ := util.DeterministicGenesisStateAltair(t, 256)
|
||||
htr, err := st.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
t.Run("current sync committee", func(t *testing.T) {
|
||||
sc, err := st.CurrentSyncCommittee()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify the Merkle proof.
|
||||
scRoot, err := sc.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
proof, err := st.CurrentSyncCommitteeProof(ctx)
|
||||
require.NoError(t, err)
|
||||
valid := trie.VerifyMerkleProof(htr[:], scRoot[:], v2.CurrentSyncCommitteeGeneralizedIndex(), proof)
|
||||
require.Equal(t, true, valid)
|
||||
})
|
||||
t.Run("next sync committee", func(t *testing.T) {
|
||||
nextSC, err := st.NextSyncCommittee()
|
||||
require.NoError(t, err)
|
||||
proof, err := st.NextSyncCommitteeProof(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify the Merkle proof.
|
||||
nextSCRoot, err := nextSC.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
valid := trie.VerifyMerkleProof(htr[:], nextSCRoot[:], v2.NextSyncCommitteeGeneralizedIndex(), proof)
|
||||
require.Equal(t, true, valid)
|
||||
|
||||
// Edit the sync committee.
|
||||
privKey, err := bls.RandKey()
|
||||
require.NoError(t, err)
|
||||
nextSC.AggregatePubkey = privKey.PublicKey().Marshal()
|
||||
require.NoError(t, st.SetNextSyncCommittee(nextSC))
|
||||
|
||||
// Verifying the old Merkle proof for the new value should fail.
|
||||
nextSCRoot, err = nextSC.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
valid = trie.VerifyMerkleProof(htr[:], nextSCRoot[:], v2.NextSyncCommitteeGeneralizedIndex(), proof)
|
||||
require.Equal(t, false, valid)
|
||||
|
||||
// Generating a new, valid proof should pass.
|
||||
proof, err = st.NextSyncCommitteeProof(ctx)
|
||||
require.NoError(t, err)
|
||||
htr, err = st.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
valid = trie.VerifyMerkleProof(htr[:], nextSCRoot[:], v2.NextSyncCommitteeGeneralizedIndex(), proof)
|
||||
require.Equal(t, true, valid)
|
||||
})
|
||||
t.Run("finalized root", func(t *testing.T) {
|
||||
finalizedRoot := st.FinalizedCheckpoint().Root
|
||||
|
||||
// Verify the Merkle proof.
|
||||
htr, err = st.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
proof, err := st.FinalizedRootProof(ctx)
|
||||
require.NoError(t, err)
|
||||
gIndex := v2.FinalizedRootGeneralizedIndex()
|
||||
valid := trie.VerifyMerkleProof(htr[:], finalizedRoot, gIndex, proof)
|
||||
require.Equal(t, true, valid)
|
||||
})
|
||||
t.Run("recomputes root on dirty fields", func(t *testing.T) {
|
||||
currentRoot, err := st.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
cpt := st.FinalizedCheckpoint()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Edit the checkpoint.
|
||||
cpt.Epoch = 100
|
||||
require.NoError(t, st.SetFinalizedCheckpoint(cpt))
|
||||
|
||||
// Produce a proof for the finalized root.
|
||||
proof, err := st.FinalizedRootProof(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
// We expect the previous step to have triggered
|
||||
// a recomputation of dirty fields in the beacon state, resulting
|
||||
// in a new hash tree root as the finalized checkpoint had previously
|
||||
// changed and should have been marked as a dirty state field.
|
||||
// The proof validity should be false for the old root, but true for the new.
|
||||
finalizedRoot := st.FinalizedCheckpoint().Root
|
||||
gIndex := v2.FinalizedRootGeneralizedIndex()
|
||||
valid := trie.VerifyMerkleProof(currentRoot[:], finalizedRoot, gIndex, proof)
|
||||
require.Equal(t, false, valid)
|
||||
|
||||
newRoot, err := st.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
valid = trie.VerifyMerkleProof(newRoot[:], finalizedRoot, gIndex, proof)
|
||||
require.Equal(t, true, valid)
|
||||
})
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestStateReferenceSharing_Finalizer(t *testing.T) {
|
||||
// This test showcases the logic on a the RandaoMixes field with the GC finalizer.
|
||||
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{RandaoMixes: [][]byte{[]byte("foo")}})
|
||||
require.NoError(t, err)
|
||||
a, ok := s.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assert.Equal(t, uint(1), a.sharedFieldReferences[randaoMixes].Refs(), "Expected a single reference for RANDAO mixes")
|
||||
|
||||
func() {
|
||||
// Create object in a different scope for GC
|
||||
b := a.Copy()
|
||||
assert.Equal(t, uint(2), a.sharedFieldReferences[randaoMixes].Refs(), "Expected 2 references to RANDAO mixes")
|
||||
_ = b
|
||||
}()
|
||||
|
||||
runtime.GC() // Should run finalizer on object b
|
||||
assert.Equal(t, uint(1), a.sharedFieldReferences[randaoMixes].Refs(), "Expected 1 shared reference to RANDAO mixes!")
|
||||
|
||||
copied := a.Copy()
|
||||
b, ok := copied.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assert.Equal(t, uint(2), b.sharedFieldReferences[randaoMixes].Refs(), "Expected 2 shared references to RANDAO mixes")
|
||||
require.NoError(t, b.UpdateRandaoMixesAtIndex(0, []byte("bar")))
|
||||
if b.sharedFieldReferences[randaoMixes].Refs() != 1 || a.sharedFieldReferences[randaoMixes].Refs() != 1 {
|
||||
t.Error("Expected 1 shared reference to RANDAO mix for both a and b")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStateReferenceCopy_NoUnexpectedRootsMutation(t *testing.T) {
|
||||
root1, root2 := bytesutil.ToBytes32([]byte("foo")), bytesutil.ToBytes32([]byte("bar"))
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{
|
||||
BlockRoots: [][]byte{
|
||||
root1[:],
|
||||
},
|
||||
StateRoots: [][]byte{
|
||||
root1[:],
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
a, ok := s.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
require.NoError(t, err)
|
||||
assertRefCount(t, a, blockRoots, 1)
|
||||
assertRefCount(t, a, stateRoots, 1)
|
||||
|
||||
// Copy, increases reference count.
|
||||
copied := a.Copy()
|
||||
b, ok := copied.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assertRefCount(t, a, blockRoots, 2)
|
||||
assertRefCount(t, a, stateRoots, 2)
|
||||
assertRefCount(t, b, blockRoots, 2)
|
||||
assertRefCount(t, b, stateRoots, 2)
|
||||
assert.Equal(t, 1, len(b.state.GetBlockRoots()), "No block roots found")
|
||||
assert.Equal(t, 1, len(b.state.GetStateRoots()), "No state roots found")
|
||||
|
||||
// Assert shared state.
|
||||
blockRootsA := a.state.GetBlockRoots()
|
||||
stateRootsA := a.state.GetStateRoots()
|
||||
blockRootsB := b.state.GetBlockRoots()
|
||||
stateRootsB := b.state.GetStateRoots()
|
||||
if len(blockRootsA) != len(blockRootsB) || len(blockRootsA) < 1 {
|
||||
t.Errorf("Unexpected number of block roots, want: %v", 1)
|
||||
}
|
||||
if len(stateRootsA) != len(stateRootsB) || len(stateRootsA) < 1 {
|
||||
t.Errorf("Unexpected number of state roots, want: %v", 1)
|
||||
}
|
||||
assertValFound(t, blockRootsA, root1[:])
|
||||
assertValFound(t, blockRootsB, root1[:])
|
||||
assertValFound(t, stateRootsA, root1[:])
|
||||
assertValFound(t, stateRootsB, root1[:])
|
||||
|
||||
// Mutator should only affect calling state: a.
|
||||
require.NoError(t, a.UpdateBlockRootAtIndex(0, root2))
|
||||
require.NoError(t, a.UpdateStateRootAtIndex(0, root2))
|
||||
|
||||
// Assert no shared state mutation occurred only on state a (copy on write).
|
||||
assertValNotFound(t, a.state.GetBlockRoots(), root1[:])
|
||||
assertValNotFound(t, a.state.GetStateRoots(), root1[:])
|
||||
assertValFound(t, a.state.GetBlockRoots(), root2[:])
|
||||
assertValFound(t, a.state.GetStateRoots(), root2[:])
|
||||
assertValFound(t, b.state.GetBlockRoots(), root1[:])
|
||||
assertValFound(t, b.state.GetStateRoots(), root1[:])
|
||||
if len(blockRootsA) != len(blockRootsB) || len(blockRootsA) < 1 {
|
||||
t.Errorf("Unexpected number of block roots, want: %v", 1)
|
||||
}
|
||||
if len(stateRootsA) != len(stateRootsB) || len(stateRootsA) < 1 {
|
||||
t.Errorf("Unexpected number of state roots, want: %v", 1)
|
||||
}
|
||||
assert.DeepEqual(t, root2[:], a.state.GetBlockRoots()[0], "Expected mutation not found")
|
||||
assert.DeepEqual(t, root2[:], a.state.GetStateRoots()[0], "Expected mutation not found")
|
||||
assert.DeepEqual(t, root1[:], blockRootsB[0], "Unexpected mutation found")
|
||||
assert.DeepEqual(t, root1[:], stateRootsB[0], "Unexpected mutation found")
|
||||
|
||||
// Copy on write happened, reference counters are reset.
|
||||
assertRefCount(t, a, blockRoots, 1)
|
||||
assertRefCount(t, a, stateRoots, 1)
|
||||
assertRefCount(t, b, blockRoots, 1)
|
||||
assertRefCount(t, b, stateRoots, 1)
|
||||
}
|
||||
|
||||
func TestStateReferenceCopy_NoUnexpectedRandaoMutation(t *testing.T) {
|
||||
|
||||
val1, val2 := []byte("foo"), []byte("bar")
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{
|
||||
RandaoMixes: [][]byte{
|
||||
val1,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
a, ok := s.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
require.NoError(t, err)
|
||||
assertRefCount(t, a, randaoMixes, 1)
|
||||
|
||||
// Copy, increases reference count.
|
||||
copied := a.Copy()
|
||||
b, ok := copied.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assertRefCount(t, a, randaoMixes, 2)
|
||||
assertRefCount(t, b, randaoMixes, 2)
|
||||
assert.Equal(t, 1, len(b.state.GetRandaoMixes()), "No randao mixes found")
|
||||
|
||||
// Assert shared state.
|
||||
mixesA := a.state.GetRandaoMixes()
|
||||
mixesB := b.state.GetRandaoMixes()
|
||||
if len(mixesA) != len(mixesB) || len(mixesA) < 1 {
|
||||
t.Errorf("Unexpected number of mix values, want: %v", 1)
|
||||
}
|
||||
assertValFound(t, mixesA, val1)
|
||||
assertValFound(t, mixesB, val1)
|
||||
|
||||
// Mutator should only affect calling state: a.
|
||||
require.NoError(t, a.UpdateRandaoMixesAtIndex(0, val2))
|
||||
|
||||
// Assert no shared state mutation occurred only on state a (copy on write).
|
||||
if len(mixesA) != len(mixesB) || len(mixesA) < 1 {
|
||||
t.Errorf("Unexpected number of mix values, want: %v", 1)
|
||||
}
|
||||
assertValFound(t, a.state.GetRandaoMixes(), val2)
|
||||
assertValNotFound(t, a.state.GetRandaoMixes(), val1)
|
||||
assertValFound(t, b.state.GetRandaoMixes(), val1)
|
||||
assertValNotFound(t, b.state.GetRandaoMixes(), val2)
|
||||
assertValFound(t, mixesB, val1)
|
||||
assertValNotFound(t, mixesB, val2)
|
||||
assert.DeepEqual(t, val2, a.state.GetRandaoMixes()[0], "Expected mutation not found")
|
||||
assert.DeepEqual(t, val1, mixesB[0], "Unexpected mutation found")
|
||||
|
||||
// Copy on write happened, reference counters are reset.
|
||||
assertRefCount(t, a, randaoMixes, 1)
|
||||
assertRefCount(t, b, randaoMixes, 1)
|
||||
}
|
||||
|
||||
func TestValidatorReferences_RemainsConsistent(t *testing.T) {
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{
|
||||
Validators: []*ethpb.Validator{
|
||||
{PublicKey: []byte{'A'}},
|
||||
{PublicKey: []byte{'B'}},
|
||||
{PublicKey: []byte{'C'}},
|
||||
{PublicKey: []byte{'D'}},
|
||||
{PublicKey: []byte{'E'}},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
a, ok := s.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
|
||||
// Create a second state.
|
||||
copied := a.Copy()
|
||||
b, ok := copied.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
|
||||
// Update First Validator.
|
||||
assert.NoError(t, a.UpdateValidatorAtIndex(0, ðpb.Validator{PublicKey: []byte{'Z'}}))
|
||||
|
||||
assert.DeepNotEqual(t, a.state.Validators[0], b.state.Validators[0], "validators are equal when they are supposed to be different")
|
||||
// Modify all validators from copied state.
|
||||
assert.NoError(t, b.ApplyToEveryValidator(func(idx int, val *ethpb.Validator) (bool, *ethpb.Validator, error) {
|
||||
return true, ðpb.Validator{PublicKey: []byte{'V'}}, nil
|
||||
}))
|
||||
|
||||
// Ensure reference is properly accounted for.
|
||||
assert.NoError(t, a.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
|
||||
assert.NotEqual(t, bytesutil.ToBytes48([]byte{'V'}), val.PublicKey())
|
||||
return nil
|
||||
}))
|
||||
}
|
||||
|
||||
// assertRefCount checks whether reference count for a given state
|
||||
// at a given index is equal to expected amount.
|
||||
func assertRefCount(t *testing.T, b *BeaconState, idx types.FieldIndex, want uint) {
|
||||
if cnt := b.sharedFieldReferences[idx].Refs(); cnt != want {
|
||||
t.Errorf("Unexpected count of references for index %d, want: %v, got: %v", idx, want, cnt)
|
||||
}
|
||||
}
|
||||
|
||||
// assertValFound checks whether item with a given value exists in list.
|
||||
func assertValFound(t *testing.T, vals [][]byte, val []byte) {
|
||||
for i := range vals {
|
||||
if reflect.DeepEqual(vals[i], val) {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Log(string(debug.Stack()))
|
||||
t.Fatalf("Expected value not found (%v), want: %v", vals, val)
|
||||
}
|
||||
|
||||
// assertValNotFound checks whether item with a given value doesn't exist in list.
|
||||
func assertValNotFound(t *testing.T, vals [][]byte, val []byte) {
|
||||
for i := range vals {
|
||||
if reflect.DeepEqual(vals[i], val) {
|
||||
t.Log(string(debug.Stack()))
|
||||
t.Errorf("Unexpected value found (%v),: %v", vals, val)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
stateTypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestAppendBeyondIndicesLimit(t *testing.T) {
|
||||
zeroHash := params.BeaconConfig().ZeroHash
|
||||
mockblockRoots := make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
|
||||
for i := 0; i < len(mockblockRoots); i++ {
|
||||
mockblockRoots[i] = zeroHash[:]
|
||||
}
|
||||
|
||||
mockstateRoots := make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
|
||||
for i := 0; i < len(mockstateRoots); i++ {
|
||||
mockstateRoots[i] = zeroHash[:]
|
||||
}
|
||||
mockrandaoMixes := make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector)
|
||||
for i := 0; i < len(mockrandaoMixes); i++ {
|
||||
mockrandaoMixes[i] = zeroHash[:]
|
||||
}
|
||||
st, err := InitializeFromProto(ðpb.BeaconStateAltair{
|
||||
Slot: 1,
|
||||
CurrentEpochParticipation: []byte{},
|
||||
PreviousEpochParticipation: []byte{},
|
||||
Validators: []*ethpb.Validator{},
|
||||
Eth1Data: ðpb.Eth1Data{},
|
||||
BlockRoots: mockblockRoots,
|
||||
StateRoots: mockstateRoots,
|
||||
RandaoMixes: mockrandaoMixes,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
_, err = st.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
s, ok := st.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
for i := stateTypes.FieldIndex(0); i < stateTypes.FieldIndex(params.BeaconConfig().BeaconStateAltairFieldCount); i++ {
|
||||
s.dirtyFields[i] = true
|
||||
}
|
||||
_, err = st.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < 10; i++ {
|
||||
assert.NoError(t, st.AppendValidator(ðpb.Validator{}))
|
||||
}
|
||||
assert.Equal(t, false, s.rebuildTrie[validators])
|
||||
assert.NotEqual(t, len(s.dirtyIndices[validators]), 0)
|
||||
|
||||
for i := 0; i < indicesLimit; i++ {
|
||||
assert.NoError(t, st.AppendValidator(ðpb.Validator{}))
|
||||
}
|
||||
assert.Equal(t, true, s.rebuildTrie[validators])
|
||||
assert.Equal(t, len(s.dirtyIndices[validators]), 0)
|
||||
}
|
||||
|
||||
func TestBeaconState_AppendBalanceWithTrie(t *testing.T) {
|
||||
count := uint64(100)
|
||||
vals := make([]*ethpb.Validator, 0, count)
|
||||
bals := make([]uint64, 0, count)
|
||||
for i := uint64(1); i < count; i++ {
|
||||
someRoot := [32]byte{}
|
||||
someKey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(someRoot[:], strconv.Itoa(int(i)))
|
||||
copy(someKey[:], strconv.Itoa(int(i)))
|
||||
vals = append(vals, ðpb.Validator{
|
||||
PublicKey: someKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1,
|
||||
ActivationEpoch: 1,
|
||||
ExitEpoch: 1,
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
bals = append(bals, params.BeaconConfig().MaxEffectiveBalance)
|
||||
}
|
||||
zeroHash := params.BeaconConfig().ZeroHash
|
||||
mockblockRoots := make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
|
||||
for i := 0; i < len(mockblockRoots); i++ {
|
||||
mockblockRoots[i] = zeroHash[:]
|
||||
}
|
||||
|
||||
mockstateRoots := make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
|
||||
for i := 0; i < len(mockstateRoots); i++ {
|
||||
mockstateRoots[i] = zeroHash[:]
|
||||
}
|
||||
mockrandaoMixes := make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector)
|
||||
for i := 0; i < len(mockrandaoMixes); i++ {
|
||||
mockrandaoMixes[i] = zeroHash[:]
|
||||
}
|
||||
var pubKeys [][]byte
|
||||
for i := uint64(0); i < params.BeaconConfig().SyncCommitteeSize; i++ {
|
||||
pubKeys = append(pubKeys, bytesutil.PadTo([]byte{}, params.BeaconConfig().BLSPubkeyLength))
|
||||
}
|
||||
st, err := InitializeFromProto(ðpb.BeaconStateAltair{
|
||||
Slot: 1,
|
||||
GenesisValidatorsRoot: make([]byte, 32),
|
||||
Fork: ðpb.Fork{
|
||||
PreviousVersion: make([]byte, 4),
|
||||
CurrentVersion: make([]byte, 4),
|
||||
Epoch: 0,
|
||||
},
|
||||
LatestBlockHeader: ðpb.BeaconBlockHeader{
|
||||
ParentRoot: make([]byte, fieldparams.RootLength),
|
||||
StateRoot: make([]byte, fieldparams.RootLength),
|
||||
BodyRoot: make([]byte, fieldparams.RootLength),
|
||||
},
|
||||
CurrentEpochParticipation: []byte{},
|
||||
PreviousEpochParticipation: []byte{},
|
||||
Validators: vals,
|
||||
Balances: bals,
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, fieldparams.RootLength),
|
||||
BlockHash: make([]byte, 32),
|
||||
},
|
||||
BlockRoots: mockblockRoots,
|
||||
StateRoots: mockstateRoots,
|
||||
RandaoMixes: mockrandaoMixes,
|
||||
JustificationBits: bitfield.NewBitvector4(),
|
||||
PreviousJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)},
|
||||
CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)},
|
||||
Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector),
|
||||
CurrentSyncCommittee: ðpb.SyncCommittee{
|
||||
Pubkeys: pubKeys,
|
||||
AggregatePubkey: make([]byte, 48),
|
||||
},
|
||||
NextSyncCommittee: ðpb.SyncCommittee{
|
||||
Pubkeys: pubKeys,
|
||||
AggregatePubkey: make([]byte, 48),
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
_, err = st.HashTreeRoot(context.Background())
|
||||
assert.NoError(t, err)
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
if i%2 == 0 {
|
||||
assert.NoError(t, st.UpdateBalancesAtIndex(types.ValidatorIndex(i), 1000))
|
||||
}
|
||||
if i%3 == 0 {
|
||||
assert.NoError(t, st.AppendBalance(1000))
|
||||
}
|
||||
}
|
||||
_, err = st.HashTreeRoot(context.Background())
|
||||
assert.NoError(t, err)
|
||||
s, ok := st.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
newRt := bytesutil.ToBytes32(s.merkleLayers[0][balances])
|
||||
wantedRt, err := stateutil.Uint64ListRootWithRegistryLimit(s.state.Balances)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, wantedRt, newRt, "state roots are unequal")
|
||||
}
|
||||
|
||||
func TestBeaconState_ModifyPreviousParticipationBits(t *testing.T) {
|
||||
testState := createState(200)
|
||||
testtmpl.VerifyBeaconStateModifyPreviousParticipationField(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(testState)
|
||||
},
|
||||
)
|
||||
testtmpl.VerifyBeaconStateModifyPreviousParticipationField_NestedAction(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(testState)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_ModifyCurrentParticipationBits(t *testing.T) {
|
||||
testState := createState(200)
|
||||
testtmpl.VerifyBeaconStateModifyCurrentParticipationField(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(testState)
|
||||
},
|
||||
)
|
||||
testtmpl.VerifyBeaconStateModifyCurrentParticipationField_NestedAction(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(testState)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func createState(count uint64) *ethpb.BeaconStateAltair {
|
||||
vals := make([]*ethpb.Validator, 0, count)
|
||||
bals := make([]uint64, 0, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
someRoot := [32]byte{}
|
||||
someKey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(someRoot[:], strconv.Itoa(int(i)))
|
||||
copy(someKey[:], strconv.Itoa(int(i)))
|
||||
vals = append(vals, ðpb.Validator{
|
||||
PublicKey: someKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1,
|
||||
ActivationEpoch: 1,
|
||||
ExitEpoch: 1,
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
bals = append(bals, params.BeaconConfig().MaxEffectiveBalance)
|
||||
}
|
||||
return ðpb.BeaconStateAltair{
|
||||
CurrentEpochParticipation: make([]byte, count),
|
||||
PreviousEpochParticipation: make([]byte, count),
|
||||
Validators: vals,
|
||||
Balances: bals,
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
//go:build go1.18
|
||||
|
||||
package v2_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
coreState "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition"
|
||||
native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/rand"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
)
|
||||
|
||||
func FuzzV2StateHashTreeRoot(f *testing.F) {
|
||||
gState, _ := util.DeterministicGenesisStateAltair(f, 100)
|
||||
output, err := gState.MarshalSSZ()
|
||||
assert.NoError(f, err)
|
||||
randPool := make([]byte, 100)
|
||||
_, err = rand.NewDeterministicGenerator().Read(randPool)
|
||||
assert.NoError(f, err)
|
||||
f.Add(randPool, uint64(10))
|
||||
f.Fuzz(func(t *testing.T, diffBuffer []byte, slotsToTransition uint64) {
|
||||
stateSSZ := bytesutil.SafeCopyBytes(output)
|
||||
for i := 0; i < len(diffBuffer); i += 9 {
|
||||
if i+8 >= len(diffBuffer) {
|
||||
return
|
||||
}
|
||||
num := bytesutil.BytesToUint64BigEndian(diffBuffer[i : i+8])
|
||||
num %= uint64(len(diffBuffer))
|
||||
// Perform a XOR on the byte of the selected index.
|
||||
stateSSZ[num] ^= diffBuffer[i+8]
|
||||
}
|
||||
pbState := ðpb.BeaconStateAltair{}
|
||||
err := pbState.UnmarshalSSZ(stateSSZ)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
nativeState, err := native.InitializeFromProtoAltair(pbState)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
slotsToTransition %= 100
|
||||
stateObj, err := v2.InitializeFromProtoUnsafe(pbState)
|
||||
assert.NoError(t, err)
|
||||
for stateObj.Slot() < types.Slot(slotsToTransition) {
|
||||
stateObj, err = coreState.ProcessSlots(context.Background(), stateObj, stateObj.Slot()+1)
|
||||
assert.NoError(t, err)
|
||||
stateObj.Copy()
|
||||
|
||||
nativeState, err = coreState.ProcessSlots(context.Background(), nativeState, nativeState.Slot()+1)
|
||||
assert.NoError(t, err)
|
||||
nativeState.Copy()
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
// Perform a cold HTR calculation by initializing a new state.
|
||||
innerState, ok := stateObj.InnerStateUnsafe().(*ethpb.BeaconStateAltair)
|
||||
assert.Equal(t, true, ok, "inner state is a not a beacon state altair proto")
|
||||
newState, err := v2.InitializeFromProtoUnsafe(innerState)
|
||||
assert.NoError(t, err)
|
||||
|
||||
newRt, newErr := newState.HashTreeRoot(context.Background())
|
||||
rt, err := stateObj.HashTreeRoot(context.Background())
|
||||
nativeRt, nativeErr := nativeState.HashTreeRoot(context.Background())
|
||||
assert.Equal(t, newErr != nil, err != nil)
|
||||
assert.Equal(t, newErr != nil, nativeErr != nil)
|
||||
if err == nil {
|
||||
assert.Equal(t, rt, newRt)
|
||||
assert.Equal(t, rt, nativeRt)
|
||||
}
|
||||
|
||||
newSSZ, newErr := newState.MarshalSSZ()
|
||||
stateObjSSZ, err := stateObj.MarshalSSZ()
|
||||
nativeSSZ, nativeErr := nativeState.MarshalSSZ()
|
||||
assert.Equal(t, newErr != nil, err != nil)
|
||||
assert.Equal(t, newErr != nil, nativeErr != nil)
|
||||
if err == nil {
|
||||
assert.DeepEqual(t, newSSZ, stateObjSSZ)
|
||||
assert.DeepEqual(t, newSSZ, nativeSSZ)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package v2_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
)
|
||||
|
||||
func TestBeaconState_ValidatorMutation_Altair(t *testing.T) {
|
||||
testState, _ := util.DeterministicGenesisStateAltair(t, 400)
|
||||
pbState, err := v2.ProtobufBeaconState(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
testState, err = v2.InitializeFromProto(pbState)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = testState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
// Reset tries
|
||||
require.NoError(t, testState.UpdateValidatorAtIndex(200, new(ethpb.Validator)))
|
||||
_, err = testState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
newState1 := testState.Copy()
|
||||
_ = testState.Copy()
|
||||
|
||||
require.NoError(t, testState.UpdateValidatorAtIndex(15, ðpb.Validator{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
EffectiveBalance: 1111,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1112,
|
||||
ActivationEpoch: 1114,
|
||||
ExitEpoch: 1116,
|
||||
WithdrawableEpoch: 1117,
|
||||
}))
|
||||
|
||||
rt, err := testState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
pbState, err = v2.ProtobufBeaconState(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
|
||||
copiedTestState, err := v2.InitializeFromProto(pbState)
|
||||
require.NoError(t, err)
|
||||
|
||||
rt2, err := copiedTestState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, rt, rt2)
|
||||
|
||||
require.NoError(t, newState1.UpdateValidatorAtIndex(150, ðpb.Validator{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
EffectiveBalance: 2111,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 2112,
|
||||
ActivationEpoch: 2114,
|
||||
ExitEpoch: 2116,
|
||||
WithdrawableEpoch: 2117,
|
||||
}))
|
||||
|
||||
rt, err = newState1.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
pbState, err = v2.ProtobufBeaconState(newState1.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
|
||||
copiedTestState, err = v2.InitializeFromProto(pbState)
|
||||
require.NoError(t, err)
|
||||
|
||||
rt2, err = copiedTestState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, rt, rt2)
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/slice"
|
||||
@@ -25,62 +24,13 @@ import (
|
||||
|
||||
// InitializeFromProto the beacon state from a protobuf representation.
|
||||
func InitializeFromProto(st *ethpb.BeaconStateAltair) (state.BeaconState, error) {
|
||||
if features.Get().EnableNativeState {
|
||||
return statenative.InitializeFromProtoAltair(proto.Clone(st).(*ethpb.BeaconStateAltair))
|
||||
}
|
||||
return InitializeFromProtoUnsafe(proto.Clone(st).(*ethpb.BeaconStateAltair))
|
||||
return statenative.InitializeFromProtoUnsafeAltair(proto.Clone(st).(*ethpb.BeaconStateAltair))
|
||||
}
|
||||
|
||||
// InitializeFromProtoUnsafe directly uses the beacon state protobuf pointer
|
||||
// and sets it as the inner state of the BeaconState type.
|
||||
func InitializeFromProtoUnsafe(st *ethpb.BeaconStateAltair) (state.BeaconState, error) {
|
||||
if features.Get().EnableNativeState {
|
||||
return statenative.InitializeFromProtoUnsafeAltair(st)
|
||||
}
|
||||
|
||||
if st == nil {
|
||||
return nil, errors.New("received nil state")
|
||||
}
|
||||
|
||||
fieldCount := params.BeaconConfig().BeaconStateAltairFieldCount
|
||||
b := &BeaconState{
|
||||
state: st,
|
||||
dirtyFields: make(map[types.FieldIndex]bool, fieldCount),
|
||||
dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount),
|
||||
stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount),
|
||||
sharedFieldReferences: make(map[types.FieldIndex]*stateutil.Reference, 11),
|
||||
rebuildTrie: make(map[types.FieldIndex]bool, fieldCount),
|
||||
valMapHandler: stateutil.NewValMapHandler(st.Validators),
|
||||
}
|
||||
|
||||
var err error
|
||||
for i := 0; i < fieldCount; i++ {
|
||||
b.dirtyFields[types.FieldIndex(i)] = true
|
||||
b.rebuildTrie[types.FieldIndex(i)] = true
|
||||
b.dirtyIndices[types.FieldIndex(i)] = []uint64{}
|
||||
b.stateFieldLeaves[types.FieldIndex(i)], err = fieldtrie.NewFieldTrie(types.FieldIndex(i), types.BasicArray, nil, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize field reference tracking for shared data.
|
||||
b.sharedFieldReferences[randaoMixes] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[stateRoots] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[blockRoots] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[previousEpochParticipationBits] = stateutil.NewRef(1) // New in Altair.
|
||||
b.sharedFieldReferences[currentEpochParticipationBits] = stateutil.NewRef(1) // New in Altair.
|
||||
b.sharedFieldReferences[slashings] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[eth1DataVotes] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[validators] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[balances] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[inactivityScores] = stateutil.NewRef(1) // New in Altair.
|
||||
b.sharedFieldReferences[historicalRoots] = stateutil.NewRef(1)
|
||||
|
||||
state.StateCount.Inc()
|
||||
// Finalizer runs when dst is being destroyed in garbage collection.
|
||||
runtime.SetFinalizer(b, finalizerCleanup)
|
||||
return b, nil
|
||||
return statenative.InitializeFromProtoUnsafeAltair(st)
|
||||
}
|
||||
|
||||
// Copy returns a deep copy of the beacon state.
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestValidatorMap_DistinctCopy(t *testing.T) {
|
||||
count := uint64(100)
|
||||
vals := make([]*ethpb.Validator, 0, count)
|
||||
for i := uint64(1); i < count; i++ {
|
||||
someRoot := [32]byte{}
|
||||
someKey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(someRoot[:], strconv.Itoa(int(i)))
|
||||
copy(someKey[:], strconv.Itoa(int(i)))
|
||||
vals = append(vals, ðpb.Validator{
|
||||
PublicKey: someKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1,
|
||||
ActivationEpoch: 1,
|
||||
ExitEpoch: 1,
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
}
|
||||
handler := stateutil.NewValMapHandler(vals)
|
||||
newHandler := handler.Copy()
|
||||
wantedPubkey := strconv.Itoa(22)
|
||||
handler.Set(bytesutil.ToBytes48([]byte(wantedPubkey)), 27)
|
||||
val1, _ := handler.Get(bytesutil.ToBytes48([]byte(wantedPubkey)))
|
||||
val2, _ := newHandler.Get(bytesutil.ToBytes48([]byte(wantedPubkey)))
|
||||
assert.NotEqual(t, val1, val2, "Values are supposed to be unequal due to copy")
|
||||
}
|
||||
|
||||
func TestInitializeFromProto(t *testing.T) {
|
||||
type test struct {
|
||||
name string
|
||||
state *ethpb.BeaconStateAltair
|
||||
error string
|
||||
}
|
||||
initTests := []test{
|
||||
{
|
||||
name: "nil state",
|
||||
state: nil,
|
||||
error: "received nil state",
|
||||
},
|
||||
{
|
||||
name: "nil validators",
|
||||
state: ðpb.BeaconStateAltair{
|
||||
Slot: 4,
|
||||
Validators: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty state",
|
||||
state: ðpb.BeaconStateAltair{},
|
||||
},
|
||||
// TODO: Add full state. Blocked by testutil migration.
|
||||
}
|
||||
for _, tt := range initTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := InitializeFromProto(tt.state)
|
||||
if tt.error != "" {
|
||||
require.ErrorContains(t, tt.error, err)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBeaconState_NoDeadlock(t *testing.T) {
|
||||
count := uint64(100)
|
||||
vals := make([]*ethpb.Validator, 0, count)
|
||||
for i := uint64(1); i < count; i++ {
|
||||
someRoot := [32]byte{}
|
||||
someKey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(someRoot[:], strconv.Itoa(int(i)))
|
||||
copy(someKey[:], strconv.Itoa(int(i)))
|
||||
vals = append(vals, ðpb.Validator{
|
||||
PublicKey: someKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1,
|
||||
ActivationEpoch: 1,
|
||||
ExitEpoch: 1,
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
}
|
||||
st, err := InitializeFromProtoUnsafe(ðpb.BeaconStateAltair{
|
||||
Validators: vals,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
s, ok := st.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
|
||||
wg := new(sync.WaitGroup)
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
// Continuously lock and unlock the state
|
||||
// by acquiring the lock.
|
||||
for i := 0; i < 1000; i++ {
|
||||
for _, f := range s.stateFieldLeaves {
|
||||
f.Lock()
|
||||
if f.Empty() {
|
||||
f.InsertFieldLayer(make([][]*[32]byte, 10))
|
||||
}
|
||||
f.Unlock()
|
||||
f.FieldReference().AddRef()
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
// Constantly read from the offending portion
|
||||
// of the code to ensure there is no possible
|
||||
// recursive read locking.
|
||||
for i := 0; i < 1000; i++ {
|
||||
go func() {
|
||||
_ = st.FieldReferencesCount()
|
||||
}()
|
||||
}
|
||||
// Test will not terminate in the event of a deadlock.
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestInitializeFromProtoUnsafe(t *testing.T) {
|
||||
type test struct {
|
||||
name string
|
||||
state *ethpb.BeaconStateAltair
|
||||
error string
|
||||
}
|
||||
initTests := []test{
|
||||
{
|
||||
name: "nil state",
|
||||
state: nil,
|
||||
error: "received nil state",
|
||||
},
|
||||
{
|
||||
name: "nil validators",
|
||||
state: ðpb.BeaconStateAltair{
|
||||
Slot: 4,
|
||||
Validators: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty state",
|
||||
state: ðpb.BeaconStateAltair{},
|
||||
},
|
||||
// TODO: Add full state. Blocked by testutil migration.
|
||||
}
|
||||
_ = initTests
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
@@ -42,7 +42,6 @@ go_library(
|
||||
"//beacon-chain/state/stateutil:go_default_library",
|
||||
"//beacon-chain/state/types:go_default_library",
|
||||
"//beacon-chain/state/v1:go_default_library",
|
||||
"//config/features:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/interfaces:go_default_library",
|
||||
@@ -60,44 +59,3 @@ go_library(
|
||||
"@org_golang_google_protobuf//proto:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"deprecated_getters_test.go",
|
||||
"deprecated_setters_test.go",
|
||||
"getters_block_test.go",
|
||||
"getters_checkpoint_test.go",
|
||||
"getters_participation_test.go",
|
||||
"getters_test.go",
|
||||
"getters_validator_test.go",
|
||||
"proofs_test.go",
|
||||
"references_test.go",
|
||||
"setters_test.go",
|
||||
"state_fuzz_test.go",
|
||||
"state_test.go",
|
||||
"state_trie_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//beacon-chain/core/transition:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/state-native:go_default_library",
|
||||
"//beacon-chain/state/stateutil:go_default_library",
|
||||
"//beacon-chain/state/testing:go_default_library",
|
||||
"//beacon-chain/state/types:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
"//container/trie:go_default_library",
|
||||
"//crypto/bls:go_default_library",
|
||||
"//crypto/rand:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//proto/engine/v1:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//testing/assert:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
"//testing/util:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_CurrentEpochAttestations(t *testing.T) {
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{})
|
||||
require.NoError(t, err)
|
||||
_, err = s.CurrentEpochAttestations()
|
||||
require.ErrorContains(t, "CurrentEpochAttestations is not supported for version Bellatrix beacon state", err)
|
||||
}
|
||||
|
||||
func TestBeaconState_PreviousEpochAttestations(t *testing.T) {
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{})
|
||||
require.NoError(t, err)
|
||||
_, err = s.PreviousEpochAttestations()
|
||||
require.ErrorContains(t, "PreviousEpochAttestations is not supported for version Bellatrix beacon state", err)
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_AppendCurrentEpochAttestations(t *testing.T) {
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{})
|
||||
require.NoError(t, err)
|
||||
require.ErrorContains(t, "AppendCurrentEpochAttestations is not supported", s.AppendCurrentEpochAttestations(nil))
|
||||
}
|
||||
|
||||
func TestBeaconState_AppendPreviousEpochAttestations(t *testing.T) {
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{})
|
||||
require.NoError(t, err)
|
||||
require.ErrorContains(t, "AppendPreviousEpochAttestations is not supported", s.AppendPreviousEpochAttestations(nil))
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
func TestBeaconState_LatestBlockHeader(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateLatestBlockHeader(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateBellatrix{})
|
||||
},
|
||||
func(BH *ethpb.BeaconBlockHeader) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateBellatrix{LatestBlockHeader: BH})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_BlockRoots(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateBlockRoots(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateBellatrix{})
|
||||
},
|
||||
func(BR [][]byte) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateBellatrix{BlockRoots: BR})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_BlockRootAtIndex(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateBlockRootAtIndex(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateBellatrix{})
|
||||
},
|
||||
func(BR [][]byte) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateBellatrix{BlockRoots: BR})
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
func TestBeaconState_JustificationBitsNil(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateJustificationBitsNil(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_JustificationBits(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateJustificationBits(
|
||||
t,
|
||||
func(bits bitfield.Bitvector4) (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{JustificationBits: bits})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_PreviousJustifiedCheckpointNil(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStatePreviousJustifiedCheckpointNil(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_PreviousJustifiedCheckpoint(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStatePreviousJustifiedCheckpoint(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{PreviousJustifiedCheckpoint: cp})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_CurrentJustifiedCheckpointNil(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateCurrentJustifiedCheckpointNil(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_CurrentJustifiedCheckpoint(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateCurrentJustifiedCheckpoint(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{CurrentJustifiedCheckpoint: cp})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_FinalizedCheckpointNil(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateFinalizedCheckpointNil(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeaconState_FinalizedCheckpoint(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateFinalizedCheckpoint(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{FinalizedCheckpoint: cp})
|
||||
})
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestState_UnrealizedCheckpointBalances(t *testing.T) {
|
||||
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
balances := make([]uint64, params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
}
|
||||
balances[i] = params.BeaconConfig().MaxEffectiveBalance
|
||||
}
|
||||
base := ðpb.BeaconStateBellatrix{
|
||||
Slot: 2,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
|
||||
Validators: validators,
|
||||
CurrentEpochParticipation: make([]byte, params.BeaconConfig().MinGenesisActiveValidatorCount),
|
||||
PreviousEpochParticipation: make([]byte, params.BeaconConfig().MinGenesisActiveValidatorCount),
|
||||
Balances: balances,
|
||||
}
|
||||
state, err := InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
|
||||
// No one voted in the last two epochs
|
||||
allActive := params.BeaconConfig().MinGenesisActiveValidatorCount * params.BeaconConfig().MaxEffectiveBalance
|
||||
active, previous, current, err := state.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, allActive, active)
|
||||
require.Equal(t, uint64(0), current)
|
||||
require.Equal(t, uint64(0), previous)
|
||||
|
||||
// Add some votes in the last two epochs:
|
||||
base.CurrentEpochParticipation[0] = 0xFF
|
||||
base.PreviousEpochParticipation[0] = 0xFF
|
||||
base.PreviousEpochParticipation[1] = 0xFF
|
||||
|
||||
state, err = InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
active, previous, current, err = state.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, allActive, active)
|
||||
require.Equal(t, params.BeaconConfig().MaxEffectiveBalance, current)
|
||||
require.Equal(t, 2*params.BeaconConfig().MaxEffectiveBalance, previous)
|
||||
|
||||
// Slash some validators
|
||||
validators[0].Slashed = true
|
||||
state, err = InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
active, previous, current, err = state.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, allActive-params.BeaconConfig().MaxEffectiveBalance, active)
|
||||
require.Equal(t, uint64(0), current)
|
||||
require.Equal(t, params.BeaconConfig().MaxEffectiveBalance, previous)
|
||||
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"runtime/debug"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_SlotDataRace(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateSlotDataRace(t, func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateBellatrix{Slot: 1})
|
||||
})
|
||||
}
|
||||
|
||||
func TestNilState_NoPanic(t *testing.T) {
|
||||
var st *BeaconState
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Errorf("Method panicked when it was not supposed to: %v\n%v\n", r, string(debug.Stack()))
|
||||
}
|
||||
}()
|
||||
// retrieve elements from nil state
|
||||
_ = st.GenesisTime()
|
||||
_ = st.GenesisValidatorsRoot()
|
||||
_ = st.GenesisValidatorsRoot()
|
||||
_ = st.Slot()
|
||||
_ = st.Fork()
|
||||
_ = st.LatestBlockHeader()
|
||||
_ = st.BlockRoots()
|
||||
_, err := st.BlockRootAtIndex(0)
|
||||
_ = err
|
||||
_ = st.StateRoots()
|
||||
_ = st.HistoricalRoots()
|
||||
_ = st.Eth1Data()
|
||||
_ = st.Eth1DataVotes()
|
||||
_ = st.Eth1DepositIndex()
|
||||
_, err = st.ValidatorAtIndex(0)
|
||||
_ = err
|
||||
_, err = st.ValidatorAtIndexReadOnly(0)
|
||||
_ = err
|
||||
_, _ = st.ValidatorIndexByPubkey([fieldparams.BLSPubkeyLength]byte{})
|
||||
_ = st.PubkeyAtIndex(0)
|
||||
_ = st.NumValidators()
|
||||
_ = st.Balances()
|
||||
_, err = st.BalanceAtIndex(0)
|
||||
_ = err
|
||||
_ = st.BalancesLength()
|
||||
_ = st.RandaoMixes()
|
||||
_, err = st.RandaoMixAtIndex(0)
|
||||
_ = err
|
||||
_ = st.RandaoMixesLength()
|
||||
_ = st.Slashings()
|
||||
_, err = st.CurrentEpochParticipation()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.PreviousEpochParticipation()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_ = st.JustificationBits()
|
||||
_ = st.PreviousJustifiedCheckpoint()
|
||||
_ = st.CurrentJustifiedCheckpoint()
|
||||
_ = st.FinalizedCheckpoint()
|
||||
_, err = st.CurrentEpochParticipation()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.PreviousEpochParticipation()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.InactivityScores()
|
||||
_ = err
|
||||
_, err = st.CurrentSyncCommittee()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.NextSyncCommittee()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.LatestExecutionPayloadHeader()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, _, _, err = st.UnrealizedCheckpointBalances()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
|
||||
}
|
||||
|
||||
func TestBeaconState_MatchCurrentJustifiedCheckpt(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateMatchCurrentJustifiedCheckpt(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateBellatrix{CurrentJustifiedCheckpoint: cp})
|
||||
},
|
||||
func(i state.BeaconState) {
|
||||
s, ok := i.(*BeaconState)
|
||||
if !ok {
|
||||
panic("error in type assertion in test template")
|
||||
}
|
||||
s.state = nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_MatchPreviousJustifiedCheckpt(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateMatchPreviousJustifiedCheckpt(
|
||||
t,
|
||||
func(cp *ethpb.Checkpoint) (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateBellatrix{PreviousJustifiedCheckpoint: cp})
|
||||
},
|
||||
func(i state.BeaconState) {
|
||||
s, ok := i.(*BeaconState)
|
||||
if !ok {
|
||||
panic("error in type assertion in test template")
|
||||
}
|
||||
s.state = nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_MarshalSSZ_NilState(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateMarshalSSZNilState(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateBellatrix{})
|
||||
},
|
||||
func(i state.BeaconState) {
|
||||
s, ok := i.(*BeaconState)
|
||||
if !ok {
|
||||
panic("error in type assertion in test template")
|
||||
}
|
||||
s.state = nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_ValidatorByPubkey(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateValidatorByPubkey(t, func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(ðpb.BeaconStateBellatrix{})
|
||||
})
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package v3_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice(t *testing.T) {
|
||||
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
||||
return v3.InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{
|
||||
Validators: nil,
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package v3_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/trie"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
)
|
||||
|
||||
func TestBeaconStateMerkleProofs(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
st, _ := util.DeterministicGenesisStateAltair(t, 256)
|
||||
htr, err := st.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
t.Run("current sync committee", func(t *testing.T) {
|
||||
sc, err := st.CurrentSyncCommittee()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify the Merkle proof.
|
||||
scRoot, err := sc.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
proof, err := st.CurrentSyncCommitteeProof(ctx)
|
||||
require.NoError(t, err)
|
||||
valid := trie.VerifyMerkleProof(htr[:], scRoot[:], v3.CurrentSyncCommitteeGeneralizedIndex(), proof)
|
||||
require.Equal(t, true, valid)
|
||||
})
|
||||
t.Run("next sync committee", func(t *testing.T) {
|
||||
nextSC, err := st.NextSyncCommittee()
|
||||
require.NoError(t, err)
|
||||
proof, err := st.NextSyncCommitteeProof(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify the Merkle proof.
|
||||
nextSCRoot, err := nextSC.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
valid := trie.VerifyMerkleProof(htr[:], nextSCRoot[:], v3.NextSyncCommitteeGeneralizedIndex(), proof)
|
||||
require.Equal(t, true, valid)
|
||||
|
||||
// Edit the sync committee.
|
||||
privKey, err := bls.RandKey()
|
||||
require.NoError(t, err)
|
||||
nextSC.AggregatePubkey = privKey.PublicKey().Marshal()
|
||||
require.NoError(t, st.SetNextSyncCommittee(nextSC))
|
||||
|
||||
// Verifying the old Merkle proof for the new value should fail.
|
||||
nextSCRoot, err = nextSC.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
valid = trie.VerifyMerkleProof(htr[:], nextSCRoot[:], v3.NextSyncCommitteeGeneralizedIndex(), proof)
|
||||
require.Equal(t, false, valid)
|
||||
|
||||
// Generating a new, valid proof should pass.
|
||||
proof, err = st.NextSyncCommitteeProof(ctx)
|
||||
require.NoError(t, err)
|
||||
htr, err = st.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
valid = trie.VerifyMerkleProof(htr[:], nextSCRoot[:], v3.NextSyncCommitteeGeneralizedIndex(), proof)
|
||||
require.Equal(t, true, valid)
|
||||
})
|
||||
t.Run("finalized root", func(t *testing.T) {
|
||||
finalizedRoot := st.FinalizedCheckpoint().Root
|
||||
|
||||
// Verify the Merkle proof.
|
||||
htr, err = st.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
proof, err := st.FinalizedRootProof(ctx)
|
||||
require.NoError(t, err)
|
||||
gIndex := v3.FinalizedRootGeneralizedIndex()
|
||||
valid := trie.VerifyMerkleProof(htr[:], finalizedRoot, gIndex, proof)
|
||||
require.Equal(t, true, valid)
|
||||
})
|
||||
t.Run("recomputes root on dirty fields", func(t *testing.T) {
|
||||
currentRoot, err := st.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
cpt := st.FinalizedCheckpoint()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Edit the checkpoint.
|
||||
cpt.Epoch = 100
|
||||
require.NoError(t, st.SetFinalizedCheckpoint(cpt))
|
||||
|
||||
// Produce a proof for the finalized root.
|
||||
proof, err := st.FinalizedRootProof(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
// We expect the previous step to have triggered
|
||||
// a recomputation of dirty fields in the beacon state, resulting
|
||||
// in a new hash tree root as the finalized checkpoint had previously
|
||||
// changed and should have been marked as a dirty state field.
|
||||
// The proof validity should be false for the old root, but true for the new.
|
||||
finalizedRoot := st.FinalizedCheckpoint().Root
|
||||
gIndex := v3.FinalizedRootGeneralizedIndex()
|
||||
valid := trie.VerifyMerkleProof(currentRoot[:], finalizedRoot, gIndex, proof)
|
||||
require.Equal(t, false, valid)
|
||||
|
||||
newRoot, err := st.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
valid = trie.VerifyMerkleProof(newRoot[:], finalizedRoot, gIndex, proof)
|
||||
require.Equal(t, true, valid)
|
||||
})
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestStateReferenceSharing_Finalizer(t *testing.T) {
|
||||
// This test showcases the logic on a the RandaoMixes field with the GC finalizer.
|
||||
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{RandaoMixes: [][]byte{[]byte("foo")}})
|
||||
require.NoError(t, err)
|
||||
a, ok := s.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assert.Equal(t, uint(1), a.sharedFieldReferences[randaoMixes].Refs(), "Expected a single reference for RANDAO mixes")
|
||||
|
||||
func() {
|
||||
// Create object in a different scope for GC
|
||||
b := a.Copy()
|
||||
assert.Equal(t, uint(2), a.sharedFieldReferences[randaoMixes].Refs(), "Expected 2 references to RANDAO mixes")
|
||||
_ = b
|
||||
}()
|
||||
|
||||
runtime.GC() // Should run finalizer on object b
|
||||
assert.Equal(t, uint(1), a.sharedFieldReferences[randaoMixes].Refs(), "Expected 1 shared reference to RANDAO mixes!")
|
||||
|
||||
copied := a.Copy()
|
||||
b, ok := copied.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assert.Equal(t, uint(2), b.sharedFieldReferences[randaoMixes].Refs(), "Expected 2 shared references to RANDAO mixes")
|
||||
require.NoError(t, b.UpdateRandaoMixesAtIndex(0, []byte("bar")))
|
||||
if b.sharedFieldReferences[randaoMixes].Refs() != 1 || a.sharedFieldReferences[randaoMixes].Refs() != 1 {
|
||||
t.Error("Expected 1 shared reference to RANDAO mix for both a and b")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStateReferenceCopy_NoUnexpectedRootsMutation(t *testing.T) {
|
||||
root1, root2 := bytesutil.ToBytes32([]byte("foo")), bytesutil.ToBytes32([]byte("bar"))
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{
|
||||
BlockRoots: [][]byte{
|
||||
root1[:],
|
||||
},
|
||||
StateRoots: [][]byte{
|
||||
root1[:],
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
a, ok := s.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
require.NoError(t, err)
|
||||
assertRefCount(t, a, blockRoots, 1)
|
||||
assertRefCount(t, a, stateRoots, 1)
|
||||
|
||||
// Copy, increases reference count.
|
||||
copied := a.Copy()
|
||||
b, ok := copied.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assertRefCount(t, a, blockRoots, 2)
|
||||
assertRefCount(t, a, stateRoots, 2)
|
||||
assertRefCount(t, b, blockRoots, 2)
|
||||
assertRefCount(t, b, stateRoots, 2)
|
||||
assert.Equal(t, 1, len(b.state.GetBlockRoots()), "No block roots found")
|
||||
assert.Equal(t, 1, len(b.state.GetStateRoots()), "No state roots found")
|
||||
|
||||
// Assert shared state.
|
||||
blockRootsA := a.state.GetBlockRoots()
|
||||
stateRootsA := a.state.GetStateRoots()
|
||||
blockRootsB := b.state.GetBlockRoots()
|
||||
stateRootsB := b.state.GetStateRoots()
|
||||
if len(blockRootsA) != len(blockRootsB) || len(blockRootsA) < 1 {
|
||||
t.Errorf("Unexpected number of block roots, want: %v", 1)
|
||||
}
|
||||
if len(stateRootsA) != len(stateRootsB) || len(stateRootsA) < 1 {
|
||||
t.Errorf("Unexpected number of state roots, want: %v", 1)
|
||||
}
|
||||
assertValFound(t, blockRootsA, root1[:])
|
||||
assertValFound(t, blockRootsB, root1[:])
|
||||
assertValFound(t, stateRootsA, root1[:])
|
||||
assertValFound(t, stateRootsB, root1[:])
|
||||
|
||||
// Mutator should only affect calling state: a.
|
||||
require.NoError(t, a.UpdateBlockRootAtIndex(0, root2))
|
||||
require.NoError(t, a.UpdateStateRootAtIndex(0, root2))
|
||||
|
||||
// Assert no shared state mutation occurred only on state a (copy on write).
|
||||
assertValNotFound(t, a.state.GetBlockRoots(), root1[:])
|
||||
assertValNotFound(t, a.state.GetStateRoots(), root1[:])
|
||||
assertValFound(t, a.state.GetBlockRoots(), root2[:])
|
||||
assertValFound(t, a.state.GetStateRoots(), root2[:])
|
||||
assertValFound(t, b.state.GetBlockRoots(), root1[:])
|
||||
assertValFound(t, b.state.GetStateRoots(), root1[:])
|
||||
if len(blockRootsA) != len(blockRootsB) || len(blockRootsA) < 1 {
|
||||
t.Errorf("Unexpected number of block roots, want: %v", 1)
|
||||
}
|
||||
if len(stateRootsA) != len(stateRootsB) || len(stateRootsA) < 1 {
|
||||
t.Errorf("Unexpected number of state roots, want: %v", 1)
|
||||
}
|
||||
assert.DeepEqual(t, root2[:], a.state.GetBlockRoots()[0], "Expected mutation not found")
|
||||
assert.DeepEqual(t, root2[:], a.state.GetStateRoots()[0], "Expected mutation not found")
|
||||
assert.DeepEqual(t, root1[:], blockRootsB[0], "Unexpected mutation found")
|
||||
assert.DeepEqual(t, root1[:], stateRootsB[0], "Unexpected mutation found")
|
||||
|
||||
// Copy on write happened, reference counters are reset.
|
||||
assertRefCount(t, a, blockRoots, 1)
|
||||
assertRefCount(t, a, stateRoots, 1)
|
||||
assertRefCount(t, b, blockRoots, 1)
|
||||
assertRefCount(t, b, stateRoots, 1)
|
||||
}
|
||||
|
||||
func TestStateReferenceCopy_NoUnexpectedRandaoMutation(t *testing.T) {
|
||||
|
||||
val1, val2 := []byte("foo"), []byte("bar")
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{
|
||||
RandaoMixes: [][]byte{
|
||||
val1,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
a, ok := s.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
require.NoError(t, err)
|
||||
assertRefCount(t, a, randaoMixes, 1)
|
||||
|
||||
// Copy, increases reference count.
|
||||
copied := a.Copy()
|
||||
b, ok := copied.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
assertRefCount(t, a, randaoMixes, 2)
|
||||
assertRefCount(t, b, randaoMixes, 2)
|
||||
assert.Equal(t, 1, len(b.state.GetRandaoMixes()), "No randao mixes found")
|
||||
|
||||
// Assert shared state.
|
||||
mixesA := a.state.GetRandaoMixes()
|
||||
mixesB := b.state.GetRandaoMixes()
|
||||
if len(mixesA) != len(mixesB) || len(mixesA) < 1 {
|
||||
t.Errorf("Unexpected number of mix values, want: %v", 1)
|
||||
}
|
||||
assertValFound(t, mixesA, val1)
|
||||
assertValFound(t, mixesB, val1)
|
||||
|
||||
// Mutator should only affect calling state: a.
|
||||
require.NoError(t, a.UpdateRandaoMixesAtIndex(0, val2))
|
||||
|
||||
// Assert no shared state mutation occurred only on state a (copy on write).
|
||||
if len(mixesA) != len(mixesB) || len(mixesA) < 1 {
|
||||
t.Errorf("Unexpected number of mix values, want: %v", 1)
|
||||
}
|
||||
assertValFound(t, a.state.GetRandaoMixes(), val2)
|
||||
assertValNotFound(t, a.state.GetRandaoMixes(), val1)
|
||||
assertValFound(t, b.state.GetRandaoMixes(), val1)
|
||||
assertValNotFound(t, b.state.GetRandaoMixes(), val2)
|
||||
assertValFound(t, mixesB, val1)
|
||||
assertValNotFound(t, mixesB, val2)
|
||||
assert.DeepEqual(t, val2, a.state.GetRandaoMixes()[0], "Expected mutation not found")
|
||||
assert.DeepEqual(t, val1, mixesB[0], "Unexpected mutation found")
|
||||
|
||||
// Copy on write happened, reference counters are reset.
|
||||
assertRefCount(t, a, randaoMixes, 1)
|
||||
assertRefCount(t, b, randaoMixes, 1)
|
||||
}
|
||||
|
||||
func TestValidatorReferences_RemainsConsistent(t *testing.T) {
|
||||
s, err := InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{
|
||||
Validators: []*ethpb.Validator{
|
||||
{PublicKey: []byte{'A'}},
|
||||
{PublicKey: []byte{'B'}},
|
||||
{PublicKey: []byte{'C'}},
|
||||
{PublicKey: []byte{'D'}},
|
||||
{PublicKey: []byte{'E'}},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
a, ok := s.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
|
||||
// Create a second state.
|
||||
copied := a.Copy()
|
||||
b, ok := copied.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
|
||||
// Update First Validator.
|
||||
assert.NoError(t, a.UpdateValidatorAtIndex(0, ðpb.Validator{PublicKey: []byte{'Z'}}))
|
||||
|
||||
assert.DeepNotEqual(t, a.state.Validators[0], b.state.Validators[0], "validators are equal when they are supposed to be different")
|
||||
// Modify all validators from copied state.
|
||||
assert.NoError(t, b.ApplyToEveryValidator(func(idx int, val *ethpb.Validator) (bool, *ethpb.Validator, error) {
|
||||
return true, ðpb.Validator{PublicKey: []byte{'V'}}, nil
|
||||
}))
|
||||
|
||||
// Ensure reference is properly accounted for.
|
||||
assert.NoError(t, a.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
|
||||
assert.NotEqual(t, bytesutil.ToBytes48([]byte{'V'}), val.PublicKey())
|
||||
return nil
|
||||
}))
|
||||
}
|
||||
|
||||
// assertRefCount checks whether reference count for a given state
|
||||
// at a given index is equal to expected amount.
|
||||
func assertRefCount(t *testing.T, b *BeaconState, idx types.FieldIndex, want uint) {
|
||||
if cnt := b.sharedFieldReferences[idx].Refs(); cnt != want {
|
||||
t.Errorf("Unexpected count of references for index %d, want: %v, got: %v", idx, want, cnt)
|
||||
}
|
||||
}
|
||||
|
||||
// assertValFound checks whether item with a given value exists in list.
|
||||
func assertValFound(t *testing.T, vals [][]byte, val []byte) {
|
||||
for i := range vals {
|
||||
if reflect.DeepEqual(vals[i], val) {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Log(string(debug.Stack()))
|
||||
t.Fatalf("Expected value not found (%v), want: %v", vals, val)
|
||||
}
|
||||
|
||||
// assertValNotFound checks whether item with a given value doesn't exist in list.
|
||||
func assertValNotFound(t *testing.T, vals [][]byte, val []byte) {
|
||||
for i := range vals {
|
||||
if reflect.DeepEqual(vals[i], val) {
|
||||
t.Log(string(debug.Stack()))
|
||||
t.Errorf("Unexpected value found (%v),: %v", vals, val)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,252 +0,0 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
|
||||
stateTypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestAppendBeyondIndicesLimit(t *testing.T) {
|
||||
zeroHash := params.BeaconConfig().ZeroHash
|
||||
mockblockRoots := make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
|
||||
for i := 0; i < len(mockblockRoots); i++ {
|
||||
mockblockRoots[i] = zeroHash[:]
|
||||
}
|
||||
|
||||
mockstateRoots := make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
|
||||
for i := 0; i < len(mockstateRoots); i++ {
|
||||
mockstateRoots[i] = zeroHash[:]
|
||||
}
|
||||
mockrandaoMixes := make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector)
|
||||
for i := 0; i < len(mockrandaoMixes); i++ {
|
||||
mockrandaoMixes[i] = zeroHash[:]
|
||||
}
|
||||
payload := &enginev1.ExecutionPayloadHeader{
|
||||
ParentHash: make([]byte, 32),
|
||||
FeeRecipient: make([]byte, 20),
|
||||
StateRoot: make([]byte, 32),
|
||||
ReceiptsRoot: make([]byte, 32),
|
||||
LogsBloom: make([]byte, 256),
|
||||
PrevRandao: make([]byte, 32),
|
||||
BaseFeePerGas: bytesutil.PadTo([]byte{1, 2, 3, 4}, fieldparams.RootLength),
|
||||
BlockHash: make([]byte, 32),
|
||||
TransactionsRoot: make([]byte, 32),
|
||||
}
|
||||
st, err := InitializeFromProto(ðpb.BeaconStateBellatrix{
|
||||
Slot: 1,
|
||||
CurrentEpochParticipation: []byte{},
|
||||
PreviousEpochParticipation: []byte{},
|
||||
Validators: []*ethpb.Validator{},
|
||||
Eth1Data: ðpb.Eth1Data{},
|
||||
BlockRoots: mockblockRoots,
|
||||
StateRoots: mockstateRoots,
|
||||
RandaoMixes: mockrandaoMixes,
|
||||
LatestExecutionPayloadHeader: payload,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
_, err = st.HashTreeRoot(context.Background())
|
||||
s, ok := st.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
require.NoError(t, err)
|
||||
for i := stateTypes.FieldIndex(0); i < stateTypes.FieldIndex(params.BeaconConfig().BeaconStateBellatrixFieldCount); i++ {
|
||||
s.dirtyFields[i] = true
|
||||
}
|
||||
_, err = st.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < 10; i++ {
|
||||
assert.NoError(t, st.AppendValidator(ðpb.Validator{}))
|
||||
}
|
||||
assert.Equal(t, false, s.rebuildTrie[validators])
|
||||
assert.NotEqual(t, len(s.dirtyIndices[validators]), 0)
|
||||
|
||||
for i := 0; i < indicesLimit; i++ {
|
||||
assert.NoError(t, st.AppendValidator(ðpb.Validator{}))
|
||||
}
|
||||
assert.Equal(t, true, s.rebuildTrie[validators])
|
||||
assert.Equal(t, len(s.dirtyIndices[validators]), 0)
|
||||
}
|
||||
|
||||
func TestBeaconState_AppendBalanceWithTrie(t *testing.T) {
|
||||
count := uint64(100)
|
||||
vals := make([]*ethpb.Validator, 0, count)
|
||||
bals := make([]uint64, 0, count)
|
||||
for i := uint64(1); i < count; i++ {
|
||||
someRoot := [32]byte{}
|
||||
someKey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(someRoot[:], strconv.Itoa(int(i)))
|
||||
copy(someKey[:], strconv.Itoa(int(i)))
|
||||
vals = append(vals, ðpb.Validator{
|
||||
PublicKey: someKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1,
|
||||
ActivationEpoch: 1,
|
||||
ExitEpoch: 1,
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
bals = append(bals, params.BeaconConfig().MaxEffectiveBalance)
|
||||
}
|
||||
zeroHash := params.BeaconConfig().ZeroHash
|
||||
mockblockRoots := make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
|
||||
for i := 0; i < len(mockblockRoots); i++ {
|
||||
mockblockRoots[i] = zeroHash[:]
|
||||
}
|
||||
|
||||
mockstateRoots := make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot)
|
||||
for i := 0; i < len(mockstateRoots); i++ {
|
||||
mockstateRoots[i] = zeroHash[:]
|
||||
}
|
||||
mockrandaoMixes := make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector)
|
||||
for i := 0; i < len(mockrandaoMixes); i++ {
|
||||
mockrandaoMixes[i] = zeroHash[:]
|
||||
}
|
||||
var pubKeys [][]byte
|
||||
for i := uint64(0); i < params.BeaconConfig().SyncCommitteeSize; i++ {
|
||||
pubKeys = append(pubKeys, bytesutil.PadTo([]byte{}, params.BeaconConfig().BLSPubkeyLength))
|
||||
}
|
||||
payload := &enginev1.ExecutionPayloadHeader{
|
||||
ParentHash: make([]byte, 32),
|
||||
FeeRecipient: make([]byte, 20),
|
||||
StateRoot: make([]byte, 32),
|
||||
ReceiptsRoot: make([]byte, 32),
|
||||
LogsBloom: make([]byte, 256),
|
||||
PrevRandao: make([]byte, 32),
|
||||
BaseFeePerGas: bytesutil.PadTo([]byte{1, 2, 3, 4}, fieldparams.RootLength),
|
||||
BlockHash: make([]byte, 32),
|
||||
TransactionsRoot: make([]byte, 32),
|
||||
}
|
||||
st, err := InitializeFromProto(ðpb.BeaconStateBellatrix{
|
||||
Slot: 1,
|
||||
GenesisValidatorsRoot: make([]byte, 32),
|
||||
Fork: ðpb.Fork{
|
||||
PreviousVersion: make([]byte, 4),
|
||||
CurrentVersion: make([]byte, 4),
|
||||
Epoch: 0,
|
||||
},
|
||||
LatestBlockHeader: ðpb.BeaconBlockHeader{
|
||||
ParentRoot: make([]byte, 32),
|
||||
StateRoot: make([]byte, 32),
|
||||
BodyRoot: make([]byte, 32),
|
||||
},
|
||||
CurrentEpochParticipation: []byte{},
|
||||
PreviousEpochParticipation: []byte{},
|
||||
Validators: vals,
|
||||
Balances: bals,
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: make([]byte, 32),
|
||||
},
|
||||
BlockRoots: mockblockRoots,
|
||||
StateRoots: mockstateRoots,
|
||||
RandaoMixes: mockrandaoMixes,
|
||||
JustificationBits: bitfield.NewBitvector4(),
|
||||
PreviousJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector),
|
||||
CurrentSyncCommittee: ðpb.SyncCommittee{
|
||||
Pubkeys: pubKeys,
|
||||
AggregatePubkey: make([]byte, 48),
|
||||
},
|
||||
NextSyncCommittee: ðpb.SyncCommittee{
|
||||
Pubkeys: pubKeys,
|
||||
AggregatePubkey: make([]byte, 48),
|
||||
},
|
||||
LatestExecutionPayloadHeader: payload,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
_, err = st.HashTreeRoot(context.Background())
|
||||
assert.NoError(t, err)
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
if i%2 == 0 {
|
||||
assert.NoError(t, st.UpdateBalancesAtIndex(types.ValidatorIndex(i), 1000))
|
||||
}
|
||||
if i%3 == 0 {
|
||||
assert.NoError(t, st.AppendBalance(1000))
|
||||
}
|
||||
}
|
||||
_, err = st.HashTreeRoot(context.Background())
|
||||
assert.NoError(t, err)
|
||||
s, ok := st.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
newRt := bytesutil.ToBytes32(s.merkleLayers[0][balances])
|
||||
wantedRt, err := stateutil.Uint64ListRootWithRegistryLimit(s.state.Balances)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, wantedRt, newRt, "state roots are unequal")
|
||||
}
|
||||
|
||||
func TestBeaconState_ModifyPreviousParticipationBits(t *testing.T) {
|
||||
testState := createState(200)
|
||||
testtmpl.VerifyBeaconStateModifyPreviousParticipationField(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(testState)
|
||||
},
|
||||
)
|
||||
testtmpl.VerifyBeaconStateModifyPreviousParticipationField_NestedAction(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(testState)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestBeaconState_ModifyCurrentParticipationBits(t *testing.T) {
|
||||
testState := createState(200)
|
||||
testtmpl.VerifyBeaconStateModifyCurrentParticipationField(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(testState)
|
||||
},
|
||||
)
|
||||
testtmpl.VerifyBeaconStateModifyCurrentParticipationField_NestedAction(
|
||||
t,
|
||||
func() (state.BeaconState, error) {
|
||||
return InitializeFromProto(testState)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func createState(count uint64) *ethpb.BeaconStateBellatrix {
|
||||
vals := make([]*ethpb.Validator, 0, count)
|
||||
bals := make([]uint64, 0, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
someRoot := [32]byte{}
|
||||
someKey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(someRoot[:], strconv.Itoa(int(i)))
|
||||
copy(someKey[:], strconv.Itoa(int(i)))
|
||||
vals = append(vals, ðpb.Validator{
|
||||
PublicKey: someKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1,
|
||||
ActivationEpoch: 1,
|
||||
ExitEpoch: 1,
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
bals = append(bals, params.BeaconConfig().MaxEffectiveBalance)
|
||||
}
|
||||
return ðpb.BeaconStateBellatrix{
|
||||
CurrentEpochParticipation: make([]byte, count),
|
||||
PreviousEpochParticipation: make([]byte, count),
|
||||
Validators: vals,
|
||||
Balances: bals,
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
//go:build go1.18
|
||||
|
||||
package v3_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
coreState "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition"
|
||||
native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/rand"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
)
|
||||
|
||||
func FuzzV3StateHashTreeRoot(f *testing.F) {
|
||||
gState, _ := util.DeterministicGenesisStateBellatrix(f, 100)
|
||||
output, err := gState.MarshalSSZ()
|
||||
assert.NoError(f, err)
|
||||
randPool := make([]byte, 100)
|
||||
_, err = rand.NewDeterministicGenerator().Read(randPool)
|
||||
assert.NoError(f, err)
|
||||
f.Add(randPool, uint64(10))
|
||||
f.Fuzz(func(t *testing.T, diffBuffer []byte, slotsToTransition uint64) {
|
||||
stateSSZ := bytesutil.SafeCopyBytes(output)
|
||||
for i := 0; i < len(diffBuffer); i += 9 {
|
||||
if i+8 >= len(diffBuffer) {
|
||||
return
|
||||
}
|
||||
num := bytesutil.BytesToUint64BigEndian(diffBuffer[i : i+8])
|
||||
num %= uint64(len(diffBuffer))
|
||||
// Perform a XOR on the byte of the selected index.
|
||||
stateSSZ[num] ^= diffBuffer[i+8]
|
||||
}
|
||||
pbState := ðpb.BeaconStateBellatrix{}
|
||||
err := pbState.UnmarshalSSZ(stateSSZ)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
nativeState, err := native.InitializeFromProtoBellatrix(pbState)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
slotsToTransition %= 100
|
||||
stateObj, err := v3.InitializeFromProtoUnsafe(pbState)
|
||||
assert.NoError(t, err)
|
||||
for stateObj.Slot() < types.Slot(slotsToTransition) {
|
||||
stateObj, err = coreState.ProcessSlots(context.Background(), stateObj, stateObj.Slot()+1)
|
||||
assert.NoError(t, err)
|
||||
stateObj.Copy()
|
||||
|
||||
nativeState, err = coreState.ProcessSlots(context.Background(), nativeState, nativeState.Slot()+1)
|
||||
assert.NoError(t, err)
|
||||
nativeState.Copy()
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
// Perform a cold HTR calculation by initializing a new state.
|
||||
innerState, ok := stateObj.InnerStateUnsafe().(*ethpb.BeaconStateBellatrix)
|
||||
assert.Equal(t, true, ok, "inner state is a not a beacon state bellatrix proto")
|
||||
newState, err := v3.InitializeFromProtoUnsafe(innerState)
|
||||
assert.NoError(t, err)
|
||||
|
||||
newRt, newErr := newState.HashTreeRoot(context.Background())
|
||||
rt, err := stateObj.HashTreeRoot(context.Background())
|
||||
nativeRt, nativeErr := nativeState.HashTreeRoot(context.Background())
|
||||
assert.Equal(t, newErr != nil, err != nil)
|
||||
assert.Equal(t, newErr != nil, nativeErr != nil)
|
||||
if err == nil {
|
||||
assert.Equal(t, rt, newRt)
|
||||
assert.Equal(t, rt, nativeRt)
|
||||
}
|
||||
|
||||
newSSZ, newErr := newState.MarshalSSZ()
|
||||
stateObjSSZ, err := stateObj.MarshalSSZ()
|
||||
nativeSSZ, nativeErr := nativeState.MarshalSSZ()
|
||||
assert.Equal(t, newErr != nil, err != nil)
|
||||
assert.Equal(t, newErr != nil, nativeErr != nil)
|
||||
if err == nil {
|
||||
assert.DeepEqual(t, newSSZ, stateObjSSZ)
|
||||
assert.DeepEqual(t, newSSZ, nativeSSZ)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package v3_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
)
|
||||
|
||||
func TestBeaconState_ValidatorMutation_Bellatrix(t *testing.T) {
|
||||
testState, _ := util.DeterministicGenesisStateBellatrix(t, 400)
|
||||
pbState, err := v3.ProtobufBeaconState(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
testState, err = v3.InitializeFromProto(pbState)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = testState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
// Reset tries
|
||||
require.NoError(t, testState.UpdateValidatorAtIndex(200, new(ethpb.Validator)))
|
||||
_, err = testState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
newState1 := testState.Copy()
|
||||
_ = testState.Copy()
|
||||
|
||||
require.NoError(t, testState.UpdateValidatorAtIndex(15, ðpb.Validator{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
EffectiveBalance: 1111,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1112,
|
||||
ActivationEpoch: 1114,
|
||||
ExitEpoch: 1116,
|
||||
WithdrawableEpoch: 1117,
|
||||
}))
|
||||
|
||||
rt, err := testState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
pbState, err = v3.ProtobufBeaconState(testState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
|
||||
copiedTestState, err := v3.InitializeFromProtoUnsafe(pbState)
|
||||
require.NoError(t, err)
|
||||
|
||||
rt2, err := copiedTestState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, rt, rt2)
|
||||
|
||||
require.NoError(t, newState1.UpdateValidatorAtIndex(150, ðpb.Validator{
|
||||
PublicKey: make([]byte, 48),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
EffectiveBalance: 2111,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 2112,
|
||||
ActivationEpoch: 2114,
|
||||
ExitEpoch: 2116,
|
||||
WithdrawableEpoch: 2117,
|
||||
}))
|
||||
|
||||
rt, err = newState1.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
pbState, err = v3.ProtobufBeaconState(newState1.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
|
||||
copiedTestState, err = v3.InitializeFromProto(pbState)
|
||||
require.NoError(t, err)
|
||||
|
||||
rt2, err = copiedTestState.HashTreeRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, rt, rt2)
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/slice"
|
||||
@@ -25,62 +24,13 @@ import (
|
||||
|
||||
// InitializeFromProto the beacon state from a protobuf representation.
|
||||
func InitializeFromProto(st *ethpb.BeaconStateBellatrix) (state.BeaconState, error) {
|
||||
if features.Get().EnableNativeState {
|
||||
return statenative.InitializeFromProtoBellatrix(proto.Clone(st).(*ethpb.BeaconStateBellatrix))
|
||||
}
|
||||
return InitializeFromProtoUnsafe(proto.Clone(st).(*ethpb.BeaconStateBellatrix))
|
||||
return statenative.InitializeFromProtoUnsafeBellatrix(proto.Clone(st).(*ethpb.BeaconStateBellatrix))
|
||||
}
|
||||
|
||||
// InitializeFromProtoUnsafe directly uses the beacon state protobuf pointer
|
||||
// and sets it as the inner state of the BeaconState type.
|
||||
func InitializeFromProtoUnsafe(st *ethpb.BeaconStateBellatrix) (state.BeaconState, error) {
|
||||
if features.Get().EnableNativeState {
|
||||
return statenative.InitializeFromProtoUnsafeBellatrix(st)
|
||||
}
|
||||
|
||||
if st == nil {
|
||||
return nil, errors.New("received nil state")
|
||||
}
|
||||
|
||||
fieldCount := params.BeaconConfig().BeaconStateBellatrixFieldCount
|
||||
b := &BeaconState{
|
||||
state: st,
|
||||
dirtyFields: make(map[types.FieldIndex]bool, fieldCount),
|
||||
dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount),
|
||||
stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount),
|
||||
sharedFieldReferences: make(map[types.FieldIndex]*stateutil.Reference, 11),
|
||||
rebuildTrie: make(map[types.FieldIndex]bool, fieldCount),
|
||||
valMapHandler: stateutil.NewValMapHandler(st.Validators),
|
||||
}
|
||||
|
||||
var err error
|
||||
for i := 0; i < fieldCount; i++ {
|
||||
b.dirtyFields[types.FieldIndex(i)] = true
|
||||
b.rebuildTrie[types.FieldIndex(i)] = true
|
||||
b.dirtyIndices[types.FieldIndex(i)] = []uint64{}
|
||||
b.stateFieldLeaves[types.FieldIndex(i)], err = fieldtrie.NewFieldTrie(types.FieldIndex(i), types.BasicArray, nil, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize field reference tracking for shared data.
|
||||
b.sharedFieldReferences[randaoMixes] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[stateRoots] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[blockRoots] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[previousEpochParticipationBits] = stateutil.NewRef(1) // New in Altair.
|
||||
b.sharedFieldReferences[currentEpochParticipationBits] = stateutil.NewRef(1) // New in Altair.
|
||||
b.sharedFieldReferences[slashings] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[eth1DataVotes] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[validators] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[balances] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[inactivityScores] = stateutil.NewRef(1) // New in Altair.
|
||||
b.sharedFieldReferences[historicalRoots] = stateutil.NewRef(1)
|
||||
b.sharedFieldReferences[latestExecutionPayloadHeader] = stateutil.NewRef(1) // New in Bellatrix.
|
||||
state.StateCount.Inc()
|
||||
// Finalizer runs when dst is being destroyed in garbage collection.
|
||||
runtime.SetFinalizer(b, finalizerCleanup)
|
||||
return b, nil
|
||||
return statenative.InitializeFromProtoUnsafeBellatrix(st)
|
||||
}
|
||||
|
||||
// Copy returns a deep copy of the beacon state.
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestValidatorMap_DistinctCopy(t *testing.T) {
|
||||
count := uint64(100)
|
||||
vals := make([]*ethpb.Validator, 0, count)
|
||||
for i := uint64(1); i < count; i++ {
|
||||
someRoot := [32]byte{}
|
||||
someKey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(someRoot[:], strconv.Itoa(int(i)))
|
||||
copy(someKey[:], strconv.Itoa(int(i)))
|
||||
vals = append(vals, ðpb.Validator{
|
||||
PublicKey: someKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1,
|
||||
ActivationEpoch: 1,
|
||||
ExitEpoch: 1,
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
}
|
||||
handler := stateutil.NewValMapHandler(vals)
|
||||
newHandler := handler.Copy()
|
||||
wantedPubkey := strconv.Itoa(22)
|
||||
handler.Set(bytesutil.ToBytes48([]byte(wantedPubkey)), 27)
|
||||
val1, _ := handler.Get(bytesutil.ToBytes48([]byte(wantedPubkey)))
|
||||
val2, _ := newHandler.Get(bytesutil.ToBytes48([]byte(wantedPubkey)))
|
||||
assert.NotEqual(t, val1, val2, "Values are supposed to be unequal due to copy")
|
||||
}
|
||||
|
||||
func TestInitializeFromProto(t *testing.T) {
|
||||
type test struct {
|
||||
name string
|
||||
state *ethpb.BeaconStateBellatrix
|
||||
error string
|
||||
}
|
||||
initTests := []test{
|
||||
{
|
||||
name: "nil state",
|
||||
state: nil,
|
||||
error: "received nil state",
|
||||
},
|
||||
{
|
||||
name: "nil validators",
|
||||
state: ðpb.BeaconStateBellatrix{
|
||||
Slot: 4,
|
||||
Validators: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty state",
|
||||
state: ðpb.BeaconStateBellatrix{},
|
||||
},
|
||||
}
|
||||
for _, tt := range initTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := InitializeFromProto(tt.state)
|
||||
if tt.error != "" {
|
||||
require.ErrorContains(t, tt.error, err)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBeaconState_NoDeadlock(t *testing.T) {
|
||||
count := uint64(100)
|
||||
vals := make([]*ethpb.Validator, 0, count)
|
||||
for i := uint64(1); i < count; i++ {
|
||||
someRoot := [32]byte{}
|
||||
someKey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(someRoot[:], strconv.Itoa(int(i)))
|
||||
copy(someKey[:], strconv.Itoa(int(i)))
|
||||
vals = append(vals, ðpb.Validator{
|
||||
PublicKey: someKey[:],
|
||||
WithdrawalCredentials: someRoot[:],
|
||||
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Slashed: false,
|
||||
ActivationEligibilityEpoch: 1,
|
||||
ActivationEpoch: 1,
|
||||
ExitEpoch: 1,
|
||||
WithdrawableEpoch: 1,
|
||||
})
|
||||
}
|
||||
st, err := InitializeFromProtoUnsafe(ðpb.BeaconStateBellatrix{
|
||||
Validators: vals,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
s, ok := st.(*BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
|
||||
wg := new(sync.WaitGroup)
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
// Continuously lock and unlock the state
|
||||
// by acquiring the lock.
|
||||
for i := 0; i < 1000; i++ {
|
||||
for _, f := range s.stateFieldLeaves {
|
||||
f.Lock()
|
||||
if f.Empty() {
|
||||
f.InsertFieldLayer(make([][]*[32]byte, 10))
|
||||
}
|
||||
f.Unlock()
|
||||
f.FieldReference().AddRef()
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
// Constantly read from the offending portion
|
||||
// of the code to ensure there is no possible
|
||||
// recursive read locking.
|
||||
for i := 0; i < 1000; i++ {
|
||||
go func() {
|
||||
_ = st.FieldReferencesCount()
|
||||
}()
|
||||
}
|
||||
// Test will not terminate in the event of a deadlock.
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestInitializeFromProtoUnsafe(t *testing.T) {
|
||||
type test struct {
|
||||
name string
|
||||
state *ethpb.BeaconStateBellatrix
|
||||
error string
|
||||
}
|
||||
initTests := []test{
|
||||
{
|
||||
name: "nil state",
|
||||
state: nil,
|
||||
error: "received nil state",
|
||||
},
|
||||
{
|
||||
name: "nil validators",
|
||||
state: ðpb.BeaconStateBellatrix{
|
||||
Slot: 4,
|
||||
Validators: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty state",
|
||||
state: ðpb.BeaconStateBellatrix{},
|
||||
},
|
||||
// TODO: Add full state. Blocked by testutil migration.
|
||||
}
|
||||
_ = initTests
|
||||
}
|
||||
@@ -60,7 +60,6 @@ type Flags struct {
|
||||
// EnableSlashingProtectionPruning for the validator client.
|
||||
EnableSlashingProtectionPruning bool
|
||||
|
||||
EnableNativeState bool // EnableNativeState defines whether the beacon state will be represented as a pure Go struct or a Go struct that wraps a proto struct.
|
||||
DisablePullTips bool // DisablePullTips disables experimental disabling of boundary checks.
|
||||
EnableDefensivePull bool // EnableDefensivePull enables exerimental back boundary checks.
|
||||
EnableVectorizedHTR bool // EnableVectorizedHTR specifies whether the beacon state will use the optimized sha256 routines.
|
||||
@@ -202,12 +201,6 @@ func ConfigureBeaconChain(ctx *cli.Context) error {
|
||||
log.WithField(enableHistoricalSpaceRepresentation.Name, enableHistoricalSpaceRepresentation.Usage).Warn(enabledFeatureFlag)
|
||||
cfg.EnableHistoricalSpaceRepresentation = true
|
||||
}
|
||||
cfg.EnableNativeState = true
|
||||
if ctx.Bool(disableNativeState.Name) {
|
||||
logDisabled(disableNativeState)
|
||||
cfg.EnableNativeState = false
|
||||
}
|
||||
|
||||
if ctx.Bool(disablePullTips.Name) {
|
||||
logEnabled(disablePullTips)
|
||||
cfg.DisablePullTips = true
|
||||
|
||||
@@ -77,6 +77,11 @@ var (
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedDisableNativeState = &cli.StringFlag{
|
||||
Name: "disable-native-state",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
)
|
||||
|
||||
// Deprecated flags for both the beacon node and validator client.
|
||||
@@ -94,6 +99,7 @@ var deprecatedFlags = []cli.Flag{
|
||||
deprecatedEnableLargerGossipHistory,
|
||||
deprecatedFallbackProvider,
|
||||
deprecatedEnableDefensivePull,
|
||||
deprecatedDisableNativeState,
|
||||
}
|
||||
|
||||
// deprecatedBeaconFlags contains flags that are still used by other components
|
||||
|
||||
@@ -93,10 +93,6 @@ var (
|
||||
" (Warning): Once enabled, this feature migrates your database in to a new schema and " +
|
||||
"there is no going back. At worst, your entire database might get corrupted.",
|
||||
}
|
||||
disableNativeState = &cli.BoolFlag{
|
||||
Name: "disable-native-state",
|
||||
Usage: "Disables representing the beacon state as a pure Go struct.",
|
||||
}
|
||||
disablePullTips = &cli.BoolFlag{
|
||||
Name: "experimental-enable-boundary-checks",
|
||||
Usage: "Experimental enable of boundary checks, useful for debugging, may cause bad votes.",
|
||||
@@ -165,7 +161,6 @@ var BeaconChainFlags = append(deprecatedBeaconFlags, append(deprecatedFlags, []c
|
||||
disableBroadcastSlashingFlag,
|
||||
enableSlasherFlag,
|
||||
enableHistoricalSpaceRepresentation,
|
||||
disableNativeState,
|
||||
disablePullTips,
|
||||
disableVecHTR,
|
||||
disableForkChoiceDoublyLinkedTree,
|
||||
|
||||
@@ -3,24 +3,26 @@
|
||||
package field_params
|
||||
|
||||
const (
|
||||
Preset = "mainnet"
|
||||
BlockRootsLength = 8192 // SLOTS_PER_HISTORICAL_ROOT
|
||||
StateRootsLength = 8192 // SLOTS_PER_HISTORICAL_ROOT
|
||||
RandaoMixesLength = 65536 // EPOCHS_PER_HISTORICAL_VECTOR
|
||||
HistoricalRootsLength = 16777216 // HISTORICAL_ROOTS_LIMIT
|
||||
ValidatorRegistryLimit = 1099511627776 // VALIDATOR_REGISTRY_LIMIT
|
||||
Eth1DataVotesLength = 2048 // SLOTS_PER_ETH1_VOTING_PERIOD
|
||||
PreviousEpochAttestationsLength = 4096 // MAX_ATTESTATIONS * SLOTS_PER_EPOCH
|
||||
CurrentEpochAttestationsLength = 4096 // MAX_ATTESTATIONS * SLOTS_PER_EPOCH
|
||||
SlashingsLength = 8192 // EPOCHS_PER_SLASHINGS_VECTOR
|
||||
SyncCommitteeLength = 512 // SYNC_COMMITTEE_SIZE
|
||||
RootLength = 32 // RootLength defines the byte length of a Merkle root.
|
||||
BLSSignatureLength = 96 // BLSSignatureLength defines the byte length of a BLSSignature.
|
||||
BLSPubkeyLength = 48 // BLSPubkeyLength defines the byte length of a BLSSignature.
|
||||
MaxTxsPerPayloadLength = 1048576 // MaxTxsPerPayloadLength defines the maximum number of transactions that can be included in a payload.
|
||||
MaxBytesPerTxLength = 1073741824 // MaxBytesPerTxLength defines the maximum number of bytes that can be included in a transaction.
|
||||
FeeRecipientLength = 20 // FeeRecipientLength defines the byte length of a fee recipient.
|
||||
LogsBloomLength = 256 // LogsBloomLength defines the byte length of a logs bloom.
|
||||
VersionLength = 4 // VersionLength defines the byte length of a fork version number.
|
||||
SlotsPerEpoch = 32 // SlotsPerEpoch defines the number of slots per epoch.
|
||||
Preset = "mainnet"
|
||||
BlockRootsLength = 8192 // SLOTS_PER_HISTORICAL_ROOT
|
||||
StateRootsLength = 8192 // SLOTS_PER_HISTORICAL_ROOT
|
||||
RandaoMixesLength = 65536 // EPOCHS_PER_HISTORICAL_VECTOR
|
||||
HistoricalRootsLength = 16777216 // HISTORICAL_ROOTS_LIMIT
|
||||
ValidatorRegistryLimit = 1099511627776 // VALIDATOR_REGISTRY_LIMIT
|
||||
Eth1DataVotesLength = 2048 // SLOTS_PER_ETH1_VOTING_PERIOD
|
||||
PreviousEpochAttestationsLength = 4096 // MAX_ATTESTATIONS * SLOTS_PER_EPOCH
|
||||
CurrentEpochAttestationsLength = 4096 // MAX_ATTESTATIONS * SLOTS_PER_EPOCH
|
||||
SlashingsLength = 8192 // EPOCHS_PER_SLASHINGS_VECTOR
|
||||
SyncCommitteeLength = 512 // SYNC_COMMITTEE_SIZE
|
||||
RootLength = 32 // RootLength defines the byte length of a Merkle root.
|
||||
BLSSignatureLength = 96 // BLSSignatureLength defines the byte length of a BLSSignature.
|
||||
BLSPubkeyLength = 48 // BLSPubkeyLength defines the byte length of a BLSSignature.
|
||||
MaxTxsPerPayloadLength = 1048576 // MaxTxsPerPayloadLength defines the maximum number of transactions that can be included in a payload.
|
||||
MaxBytesPerTxLength = 1073741824 // MaxBytesPerTxLength defines the maximum number of bytes that can be included in a transaction.
|
||||
FeeRecipientLength = 20 // FeeRecipientLength defines the byte length of a fee recipient.
|
||||
LogsBloomLength = 256 // LogsBloomLength defines the byte length of a logs bloom.
|
||||
VersionLength = 4 // VersionLength defines the byte length of a fork version number.
|
||||
SlotsPerEpoch = 32 // SlotsPerEpoch defines the number of slots per epoch.
|
||||
SyncCommitteeAggregationBytesLength = 16 // SyncCommitteeAggregationBytesLength defines the length of sync committee aggregate bytes.
|
||||
SyncAggregateSyncCommitteeBytesLength = 64 // SyncAggregateSyncCommitteeBytesLength defines the length of sync committee bytes in a sync aggregate.
|
||||
)
|
||||
|
||||
@@ -3,24 +3,26 @@
|
||||
package field_params
|
||||
|
||||
const (
|
||||
Preset = "minimal"
|
||||
BlockRootsLength = 64 // SLOTS_PER_HISTORICAL_ROOT
|
||||
StateRootsLength = 64 // SLOTS_PER_HISTORICAL_ROOT
|
||||
RandaoMixesLength = 64 // EPOCHS_PER_HISTORICAL_VECTOR
|
||||
HistoricalRootsLength = 16777216 // HISTORICAL_ROOTS_LIMIT
|
||||
ValidatorRegistryLimit = 1099511627776 // VALIDATOR_REGISTRY_LIMIT
|
||||
Eth1DataVotesLength = 32 // SLOTS_PER_ETH1_VOTING_PERIOD
|
||||
PreviousEpochAttestationsLength = 1024 // MAX_ATTESTATIONS * SLOTS_PER_EPOCH
|
||||
CurrentEpochAttestationsLength = 1024 // MAX_ATTESTATIONS * SLOTS_PER_EPOCH
|
||||
SlashingsLength = 64 // EPOCHS_PER_SLASHINGS_VECTOR
|
||||
SyncCommitteeLength = 32 // SYNC_COMMITTEE_SIZE
|
||||
RootLength = 32 // RootLength defines the byte length of a Merkle root.
|
||||
BLSSignatureLength = 96 // BLSSignatureLength defines the byte length of a BLSSignature.
|
||||
BLSPubkeyLength = 48 // BLSPubkeyLength defines the byte length of a BLSSignature.
|
||||
MaxTxsPerPayloadLength = 1048576 // MaxTxsPerPayloadLength defines the maximum number of transactions that can be included in a payload.
|
||||
MaxBytesPerTxLength = 1073741824 // MaxBytesPerTxLength defines the maximum number of bytes that can be included in a transaction.
|
||||
FeeRecipientLength = 20 // FeeRecipientLength defines the byte length of a fee recipient.
|
||||
LogsBloomLength = 256 // LogsBloomLength defines the byte length of a logs bloom.
|
||||
VersionLength = 4 // VersionLength defines the byte length of a fork version number.
|
||||
SlotsPerEpoch = 8 // SlotsPerEpoch defines the number of slots per epoch.
|
||||
Preset = "minimal"
|
||||
BlockRootsLength = 64 // SLOTS_PER_HISTORICAL_ROOT
|
||||
StateRootsLength = 64 // SLOTS_PER_HISTORICAL_ROOT
|
||||
RandaoMixesLength = 64 // EPOCHS_PER_HISTORICAL_VECTOR
|
||||
HistoricalRootsLength = 16777216 // HISTORICAL_ROOTS_LIMIT
|
||||
ValidatorRegistryLimit = 1099511627776 // VALIDATOR_REGISTRY_LIMIT
|
||||
Eth1DataVotesLength = 32 // SLOTS_PER_ETH1_VOTING_PERIOD
|
||||
PreviousEpochAttestationsLength = 1024 // MAX_ATTESTATIONS * SLOTS_PER_EPOCH
|
||||
CurrentEpochAttestationsLength = 1024 // MAX_ATTESTATIONS * SLOTS_PER_EPOCH
|
||||
SlashingsLength = 64 // EPOCHS_PER_SLASHINGS_VECTOR
|
||||
SyncCommitteeLength = 32 // SYNC_COMMITTEE_SIZE
|
||||
RootLength = 32 // RootLength defines the byte length of a Merkle root.
|
||||
BLSSignatureLength = 96 // BLSSignatureLength defines the byte length of a BLSSignature.
|
||||
BLSPubkeyLength = 48 // BLSPubkeyLength defines the byte length of a BLSSignature.
|
||||
MaxTxsPerPayloadLength = 1048576 // MaxTxsPerPayloadLength defines the maximum number of transactions that can be included in a payload.
|
||||
MaxBytesPerTxLength = 1073741824 // MaxBytesPerTxLength defines the maximum number of bytes that can be included in a transaction.
|
||||
FeeRecipientLength = 20 // FeeRecipientLength defines the byte length of a fee recipient.
|
||||
LogsBloomLength = 256 // LogsBloomLength defines the byte length of a logs bloom.
|
||||
VersionLength = 4 // VersionLength defines the byte length of a fork version number.
|
||||
SlotsPerEpoch = 8 // SlotsPerEpoch defines the number of slots per epoch.
|
||||
SyncCommitteeAggregationBytesLength = 1 // SyncCommitteeAggregationBytesLength defines the sync committee aggregate bytes.
|
||||
SyncAggregateSyncCommitteeBytesLength = 4 // SyncAggregateSyncCommitteeBytesLength defines the length of sync committee bytes in a sync aggregate.
|
||||
)
|
||||
|
||||
@@ -567,9 +567,12 @@ func TestBeaconStateToProto(t *testing.T) {
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("lbhparentroot"), 32), resultLatestBlockHeader.ParentRoot)
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("lbhstateroot"), 32), resultLatestBlockHeader.StateRoot)
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("lbhbodyroot"), 32), resultLatestBlockHeader.BodyRoot)
|
||||
assert.DeepEqual(t, [][]byte{bytesutil.PadTo([]byte("blockroots"), 32)}, result.BlockRoots)
|
||||
assert.DeepEqual(t, [][]byte{bytesutil.PadTo([]byte("stateroots"), 32)}, result.StateRoots)
|
||||
assert.DeepEqual(t, [][]byte{bytesutil.PadTo([]byte("historicalroots"), 32)}, result.HistoricalRoots)
|
||||
assert.Equal(t, 8192, len(result.BlockRoots))
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("blockroots"), 32), result.BlockRoots[0])
|
||||
assert.Equal(t, 8192, len(result.StateRoots))
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("stateroots"), 32), result.StateRoots[0])
|
||||
assert.Equal(t, 1, len(result.HistoricalRoots))
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("historicalroots"), 32), result.HistoricalRoots[0])
|
||||
resultEth1Data := result.Eth1Data
|
||||
require.NotNil(t, resultEth1Data)
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("e1ddepositroot"), 32), resultEth1Data.DepositRoot)
|
||||
@@ -594,7 +597,8 @@ func TestBeaconStateToProto(t *testing.T) {
|
||||
assert.Equal(t, types.Epoch(12), resultValidator.ExitEpoch)
|
||||
assert.Equal(t, types.Epoch(13), resultValidator.WithdrawableEpoch)
|
||||
assert.DeepEqual(t, []uint64{14}, result.Balances)
|
||||
assert.DeepEqual(t, [][]byte{bytesutil.PadTo([]byte("randaomixes"), 32)}, result.RandaoMixes)
|
||||
assert.Equal(t, 65536, len(result.RandaoMixes))
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("randaomixes"), 32), result.RandaoMixes[0])
|
||||
assert.DeepEqual(t, []uint64{15}, result.Slashings)
|
||||
require.Equal(t, 1, len(result.PreviousEpochAttestations))
|
||||
resultPrevEpochAtt := result.PreviousEpochAttestations[0]
|
||||
|
||||
@@ -340,9 +340,12 @@ func TestBeaconStateAltairToProto(t *testing.T) {
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("lbhparentroot"), 32), resultLatestBlockHeader.ParentRoot)
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("lbhstateroot"), 32), resultLatestBlockHeader.StateRoot)
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("lbhbodyroot"), 32), resultLatestBlockHeader.BodyRoot)
|
||||
assert.DeepEqual(t, [][]byte{bytesutil.PadTo([]byte("blockroots"), 32)}, result.BlockRoots)
|
||||
assert.DeepEqual(t, [][]byte{bytesutil.PadTo([]byte("stateroots"), 32)}, result.StateRoots)
|
||||
assert.DeepEqual(t, [][]byte{bytesutil.PadTo([]byte("historicalroots"), 32)}, result.HistoricalRoots)
|
||||
assert.Equal(t, 8192, len(result.BlockRoots))
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("blockroots"), 32), result.BlockRoots[0])
|
||||
assert.Equal(t, 8192, len(result.StateRoots))
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("stateroots"), 32), result.StateRoots[0])
|
||||
assert.Equal(t, 1, len(result.HistoricalRoots))
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("historicalroots"), 32), result.HistoricalRoots[0])
|
||||
resultEth1Data := result.Eth1Data
|
||||
require.NotNil(t, resultEth1Data)
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("e1ddepositroot"), 32), resultEth1Data.DepositRoot)
|
||||
@@ -367,7 +370,8 @@ func TestBeaconStateAltairToProto(t *testing.T) {
|
||||
assert.Equal(t, types.Epoch(12), resultValidator.ExitEpoch)
|
||||
assert.Equal(t, types.Epoch(13), resultValidator.WithdrawableEpoch)
|
||||
assert.DeepEqual(t, []uint64{14}, result.Balances)
|
||||
assert.DeepEqual(t, [][]byte{bytesutil.PadTo([]byte("randaomixes"), 32)}, result.RandaoMixes)
|
||||
assert.Equal(t, 65536, len(result.RandaoMixes))
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("randaomixes"), 32), result.RandaoMixes[0])
|
||||
assert.DeepEqual(t, []uint64{15}, result.Slashings)
|
||||
assert.DeepEqual(t, bitfield.Bitvector4{1}, result.JustificationBits)
|
||||
resultPrevJustifiedCheckpoint := result.PreviousJustifiedCheckpoint
|
||||
@@ -499,9 +503,12 @@ func TestBeaconStateBellatrixToProto(t *testing.T) {
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("lbhparentroot"), 32), resultLatestBlockHeader.ParentRoot)
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("lbhstateroot"), 32), resultLatestBlockHeader.StateRoot)
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("lbhbodyroot"), 32), resultLatestBlockHeader.BodyRoot)
|
||||
assert.DeepEqual(t, [][]byte{bytesutil.PadTo([]byte("blockroots"), 32)}, result.BlockRoots)
|
||||
assert.DeepEqual(t, [][]byte{bytesutil.PadTo([]byte("stateroots"), 32)}, result.StateRoots)
|
||||
assert.DeepEqual(t, [][]byte{bytesutil.PadTo([]byte("historicalroots"), 32)}, result.HistoricalRoots)
|
||||
assert.Equal(t, 8192, len(result.BlockRoots))
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("blockroots"), 32), result.BlockRoots[0])
|
||||
assert.Equal(t, 8192, len(result.StateRoots))
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("stateroots"), 32), result.StateRoots[0])
|
||||
assert.Equal(t, 1, len(result.HistoricalRoots))
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("historicalroots"), 32), result.HistoricalRoots[0])
|
||||
resultEth1Data := result.Eth1Data
|
||||
require.NotNil(t, resultEth1Data)
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("e1ddepositroot"), 32), resultEth1Data.DepositRoot)
|
||||
@@ -526,7 +533,8 @@ func TestBeaconStateBellatrixToProto(t *testing.T) {
|
||||
assert.Equal(t, types.Epoch(12), resultValidator.ExitEpoch)
|
||||
assert.Equal(t, types.Epoch(13), resultValidator.WithdrawableEpoch)
|
||||
assert.DeepEqual(t, []uint64{14}, result.Balances)
|
||||
assert.DeepEqual(t, [][]byte{bytesutil.PadTo([]byte("randaomixes"), 32)}, result.RandaoMixes)
|
||||
assert.Equal(t, 65536, len(result.RandaoMixes))
|
||||
assert.DeepEqual(t, bytesutil.PadTo([]byte("randaomixes"), 32), result.RandaoMixes[0])
|
||||
assert.DeepEqual(t, []uint64{15}, result.Slashings)
|
||||
assert.DeepEqual(t, bitfield.Bitvector4{1}, result.JustificationBits)
|
||||
resultPrevJustifiedCheckpoint := result.PreviousJustifiedCheckpoint
|
||||
|
||||
@@ -13,8 +13,6 @@ go_library(
|
||||
"//beacon-chain/core/signing:go_default_library",
|
||||
"//beacon-chain/core/transition:go_default_library",
|
||||
"//beacon-chain/state/state-native:go_default_library",
|
||||
"//beacon-chain/state/v1:go_default_library",
|
||||
"//config/features:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//container/trie:go_default_library",
|
||||
"//crypto/bls:go_default_library",
|
||||
|
||||
@@ -11,8 +11,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing"
|
||||
coreState "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition"
|
||||
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/trie"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
|
||||
@@ -70,12 +68,7 @@ func GenerateGenesisStateFromDepositData(
|
||||
return nil, nil, errors.Wrap(err, "could not generate genesis state")
|
||||
}
|
||||
|
||||
var pbState *ethpb.BeaconState
|
||||
if features.Get().EnableNativeState {
|
||||
pbState, err = statenative.ProtobufBeaconStatePhase0(beaconState.InnerStateUnsafe())
|
||||
} else {
|
||||
pbState, err = v1.ProtobufBeaconState(beaconState.InnerStateUnsafe())
|
||||
}
|
||||
pbState, err := statenative.ProtobufBeaconStatePhase0(beaconState.InnerStateUnsafe())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
dbtest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
|
||||
mockslashings "github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/slashings/mock"
|
||||
mockstategen "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
@@ -46,6 +47,9 @@ func (mockSyncChecker) IsSynced(_ context.Context) (bool, error) {
|
||||
}
|
||||
|
||||
func TestEndToEnd_SlasherSimulator(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.E2ETestConfig().Copy())
|
||||
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ go_library(
|
||||
"//beacon-chain/core/epoch/precompute:go_default_library",
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/v2:go_default_library",
|
||||
"//beacon-chain/state/state-native:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
||||
"github.com/golang/snappy"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
stateAltair "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2"
|
||||
state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
@@ -34,7 +34,7 @@ func RunEpochOperationTest(
|
||||
if err := preBeaconStateBase.UnmarshalSSZ(preBeaconStateSSZ); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
preBeaconState, err := stateAltair.InitializeFromProto(preBeaconStateBase)
|
||||
preBeaconState, err := state_native.InitializeFromProtoAltair(preBeaconStateBase)
|
||||
require.NoError(t, err)
|
||||
|
||||
// If the post.ssz is not present, it means the test should fail on our end.
|
||||
@@ -59,7 +59,7 @@ func RunEpochOperationTest(
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
pbState, err := stateAltair.ProtobufBeaconState(beaconState.InnerStateUnsafe())
|
||||
pbState, err := state_native.ProtobufBeaconStateAltair(beaconState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
if !proto.Equal(pbState, postBeaconState) {
|
||||
diff, _ := messagediff.PrettyDiff(beaconState.InnerStateUnsafe(), postBeaconState)
|
||||
|
||||
@@ -10,7 +10,7 @@ go_library(
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/core/transition:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/v2:go_default_library",
|
||||
"//beacon-chain/state/state-native:go_default_library",
|
||||
"//consensus-types/blocks:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
stateAltair "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2"
|
||||
state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
@@ -40,7 +40,7 @@ func RunFinalityTest(t *testing.T, config string) {
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
beaconStateBase := ðpb.BeaconStateAltair{}
|
||||
require.NoError(t, beaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
|
||||
beaconState, err := stateAltair.InitializeFromProto(beaconStateBase)
|
||||
beaconState, err := state_native.InitializeFromProtoAltair(beaconStateBase)
|
||||
require.NoError(t, err)
|
||||
|
||||
file, err := util.BazelFileBytes(testsFolderPath, folder.Name(), "meta.yaml")
|
||||
@@ -63,7 +63,7 @@ func RunFinalityTest(t *testing.T, config string) {
|
||||
require.NoError(t, err)
|
||||
processedState, err = transition.ExecuteStateTransition(context.Background(), beaconState, wsb)
|
||||
require.NoError(t, err)
|
||||
beaconState, ok = processedState.(*stateAltair.BeaconState)
|
||||
beaconState, ok = processedState.(*state_native.BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func RunFinalityTest(t *testing.T, config string) {
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
postBeaconState := ðpb.BeaconStateAltair{}
|
||||
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal")
|
||||
pbState, err := stateAltair.ProtobufBeaconState(beaconState.InnerStateUnsafe())
|
||||
pbState, err := state_native.ProtobufBeaconStateAltair(beaconState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
if !proto.Equal(pbState, postBeaconState) {
|
||||
t.Fatal("Post state does not match expected")
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user