Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:prysmaticlabs/prysm into hf1
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Aug 30, 2021
2 parents 0b7f2b3 + 5164015 commit 49dce52
Show file tree
Hide file tree
Showing 18 changed files with 186 additions and 18 deletions.
10 changes: 5 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ filegroup(
url = "https://github.com/eth2-clients/slashing-protection-interchange-tests/archive/b8413ca42dc92308019d0d4db52c87e9e125c4e9.tar.gz",
)

consensus_spec_version = "v1.1.0-beta.1"
consensus_spec_version = "v1.1.0-beta.3"

http_archive(
name = "consensus_spec_tests_general",
Expand All @@ -211,7 +211,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
sha256 = "e9b4cc60a3e676c6b4a9348424e44cff1ebada603ffb31b0df600dbd70e7fbf6",
sha256 = "9a60392cbf06e2a6e17e46d8bdca3d56b9db7e261fad6085db6851f9b5b35008",
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/general.tar.gz" % consensus_spec_version,
)

Expand All @@ -227,7 +227,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
sha256 = "cf82dc729ffe7b924f852e57d1973e1a6377c5b52acc903c953277fa9b4e6de8",
sha256 = "4df4d4c56c95853d423ac48e886c3d5fa258c39c47267c0c6afdc8566fa8c323",
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/minimal.tar.gz" % consensus_spec_version,
)

Expand All @@ -243,7 +243,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
sha256 = "6c6792375b81858037014e282d28a64b0cf12e12daf16054265c85403b8b329f",
sha256 = "bc8a081beeeef5bf49aa903c431a86409acd6876f02bf23f44d92f7e70c1d9e9",
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/mainnet.tar.gz" % consensus_spec_version,
)

Expand All @@ -258,7 +258,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
sha256 = "6a039696cefe9c1a35f677d118880afa71bbd487f75110a943618872ccdde170",
sha256 = "cea2a6c91d565660f54735f6be2bdea2ef91fe8ac71bff8f37866ae3a0f3af8a",
strip_prefix = "consensus-specs-" + consensus_spec_version[1:],
url = "https://github.com/ethereum/consensus-specs/archive/refs/tags/%s.tar.gz" % consensus_spec_version,
)
Expand Down
16 changes: 12 additions & 4 deletions beacon-chain/core/altair/epoch_precompute.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ func ProcessInactivityScores(

// ProcessEpochParticipation processes the epoch participation in state and updates individual validator's pre computes,
// it also tracks and updates epoch attesting balances.
// Spec code:
// if epoch == get_current_epoch(state):
// epoch_participation = state.current_epoch_participation
// else:
// epoch_participation = state.previous_epoch_participation
// active_validator_indices = get_active_validator_indices(state, epoch)
// participating_indices = [i for i in active_validator_indices if has_flag(epoch_participation[i], flag_index)]
// return set(filter(lambda index: not state.validators[index].slashed, participating_indices))
func ProcessEpochParticipation(
ctx context.Context,
state state.BeaconState,
Expand All @@ -147,7 +155,7 @@ func ProcessEpochParticipation(
sourceIdx := cfg.TimelySourceFlagIndex
headIdx := cfg.TimelyHeadFlagIndex
for i, b := range cp {
if HasValidatorFlag(b, targetIdx) {
if HasValidatorFlag(b, targetIdx) && vals[i].IsActiveCurrentEpoch {
vals[i].IsCurrentEpochTargetAttester = true
}
}
Expand All @@ -156,13 +164,13 @@ func ProcessEpochParticipation(
return nil, nil, err
}
for i, b := range pp {
if HasValidatorFlag(b, sourceIdx) {
if HasValidatorFlag(b, sourceIdx) && vals[i].IsActivePrevEpoch {
vals[i].IsPrevEpochAttester = true
}
if HasValidatorFlag(b, targetIdx) {
if HasValidatorFlag(b, targetIdx) && vals[i].IsActivePrevEpoch {
vals[i].IsPrevEpochTargetAttester = true
}
if HasValidatorFlag(b, headIdx) {
if HasValidatorFlag(b, headIdx) && vals[i].IsActivePrevEpoch {
vals[i].IsPrevEpochHeadAttester = true
}
}
Expand Down
62 changes: 62 additions & 0 deletions beacon-chain/core/altair/epoch_precompute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,68 @@ func TestProcessEpochParticipation(t *testing.T) {
require.Equal(t, balance.PrevEpochHeadAttested, params.BeaconConfig().MaxEffectiveBalance*1)
}

func TestProcessEpochParticipation_InactiveValidator(t *testing.T) {
generateParticipation := func(flags ...uint8) byte {
b := byte(0)
for _, flag := range flags {
b = AddValidatorFlag(b, flag)
}
return b
}
st, err := stateAltair.InitializeFromProto(&ethpb.BeaconStateAltair{
Slot: 2 * params.BeaconConfig().SlotsPerEpoch,
Validators: []*ethpb.Validator{
{EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance}, // Inactive
{EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance, ExitEpoch: 2}, // Inactive current epoch, active previous epoch
{EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance, ExitEpoch: params.BeaconConfig().FarFutureEpoch}, // Active
},
CurrentEpochParticipation: []byte{
generateParticipation(params.BeaconConfig().TimelySourceFlagIndex),
generateParticipation(params.BeaconConfig().TimelySourceFlagIndex, params.BeaconConfig().TimelyTargetFlagIndex),
generateParticipation(params.BeaconConfig().TimelySourceFlagIndex, params.BeaconConfig().TimelyTargetFlagIndex, params.BeaconConfig().TimelyHeadFlagIndex),
},
PreviousEpochParticipation: []byte{
generateParticipation(params.BeaconConfig().TimelySourceFlagIndex),
generateParticipation(params.BeaconConfig().TimelySourceFlagIndex, params.BeaconConfig().TimelyTargetFlagIndex),
generateParticipation(params.BeaconConfig().TimelySourceFlagIndex, params.BeaconConfig().TimelyTargetFlagIndex, params.BeaconConfig().TimelyHeadFlagIndex),
},
InactivityScores: []uint64{0, 0, 0},
})
require.NoError(t, err)
validators, balance, err := InitializeEpochValidators(context.Background(), st)
require.NoError(t, err)
validators, balance, err = ProcessEpochParticipation(context.Background(), st, balance, validators)
require.NoError(t, err)
require.DeepEqual(t, &precompute.Validator{
IsActiveCurrentEpoch: false,
IsActivePrevEpoch: false,
IsWithdrawableCurrentEpoch: true,
CurrentEpochEffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
}, validators[0])
require.DeepEqual(t, &precompute.Validator{
IsActiveCurrentEpoch: false,
IsActivePrevEpoch: true,
IsPrevEpochAttester: true,
IsPrevEpochTargetAttester: true,
IsWithdrawableCurrentEpoch: true,
CurrentEpochEffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
}, validators[1])
require.DeepEqual(t, &precompute.Validator{
IsActiveCurrentEpoch: true,
IsActivePrevEpoch: true,
IsWithdrawableCurrentEpoch: true,
CurrentEpochEffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
IsPrevEpochAttester: true,
IsCurrentEpochTargetAttester: true,
IsPrevEpochTargetAttester: true,
IsPrevEpochHeadAttester: true,
}, validators[2])
require.Equal(t, balance.PrevEpochAttested, 2*params.BeaconConfig().MaxEffectiveBalance)
require.Equal(t, balance.CurrentEpochTargetAttested, params.BeaconConfig().MaxEffectiveBalance)
require.Equal(t, balance.PrevEpochTargetAttested, 2*params.BeaconConfig().MaxEffectiveBalance)
require.Equal(t, balance.PrevEpochHeadAttested, params.BeaconConfig().MaxEffectiveBalance)
}

func TestAttestationsDelta(t *testing.T) {
s, err := testState()
require.NoError(t, err)
Expand Down
12 changes: 12 additions & 0 deletions spectest/mainnet/altair/random/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@prysm//tools/go:def.bzl", "go_test")

go_test(
name = "go_default_test",
size = "small",
srcs = ["random_test.go"],
data = glob(["*.yaml"]) + [
"@consensus_spec_tests_mainnet//:test_data",
],
tags = ["spectest"],
deps = ["//spectest/shared/altair/sanity:go_default_library"],
)
11 changes: 11 additions & 0 deletions spectest/mainnet/altair/random/random_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package random

import (
"testing"

"github.com/prysmaticlabs/prysm/spectest/shared/altair/sanity"
)

func TestMainnet_Altair_Random(t *testing.T) {
sanity.RunBlockProcessingTest(t, "mainnet", "random/random/pyspec_tests")
}
2 changes: 1 addition & 1 deletion spectest/mainnet/altair/sanity/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

func TestMainnet_Altair_Sanity_Blocks(t *testing.T) {
sanity.RunBlockProcessingTest(t, "mainnet")
sanity.RunBlockProcessingTest(t, "mainnet", "sanity/blocks/pyspec_tests")
}
12 changes: 12 additions & 0 deletions spectest/mainnet/phase0/random/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@prysm//tools/go:def.bzl", "go_test")

go_test(
name = "go_default_test",
size = "small",
srcs = ["random_test.go"],
data = glob(["*.yaml"]) + [
"@consensus_spec_tests_mainnet//:test_data",
],
tags = ["spectest"],
deps = ["//spectest/shared/phase0/sanity:go_default_library"],
)
11 changes: 11 additions & 0 deletions spectest/mainnet/phase0/random/random_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package random

import (
"testing"

"github.com/prysmaticlabs/prysm/spectest/shared/phase0/sanity"
)

func TestMainnet_Phase0_Random(t *testing.T) {
sanity.RunBlockProcessingTest(t, "mainnet", "random/random/pyspec_tests")
}
2 changes: 1 addition & 1 deletion spectest/mainnet/phase0/sanity/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

func TestMainnet_Phase0_Sanity_Blocks(t *testing.T) {
sanity.RunBlockProcessingTest(t, "mainnet")
sanity.RunBlockProcessingTest(t, "mainnet", "sanity/blocks/pyspec_tests")
}
13 changes: 13 additions & 0 deletions spectest/minimal/altair/random/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@prysm//tools/go:def.bzl", "go_test")

go_test(
name = "go_default_test",
size = "small",
srcs = ["random_test.go"],
data = glob(["*.yaml"]) + [
"@consensus_spec_tests_minimal//:test_data",
],
eth_network = "minimal",
tags = ["spectest"],
deps = ["//spectest/shared/altair/sanity:go_default_library"],
)
11 changes: 11 additions & 0 deletions spectest/minimal/altair/random/random_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package random

import (
"testing"

"github.com/prysmaticlabs/prysm/spectest/shared/altair/sanity"
)

func TestMinimal_Altair_Random(t *testing.T) {
sanity.RunBlockProcessingTest(t, "minimal", "random/random/pyspec_tests")
}
2 changes: 1 addition & 1 deletion spectest/minimal/altair/sanity/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

func TestMinimal_Altair_Sanity_Blocks(t *testing.T) {
sanity.RunBlockProcessingTest(t, "minimal")
sanity.RunBlockProcessingTest(t, "minimal", "sanity/blocks/pyspec_tests")
}
16 changes: 16 additions & 0 deletions spectest/minimal/phase0/random/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@prysm//tools/go:def.bzl", "go_test")

go_test(
name = "go_default_test",
size = "small",
srcs = ["random_test.go"],
data = glob(["*.yaml"]) + [
"@consensus_spec_tests_minimal//:test_data",
],
eth_network = "minimal",
tags = [
"minimal",
"spectest",
],
deps = ["//spectest/shared/phase0/sanity:go_default_library"],
)
11 changes: 11 additions & 0 deletions spectest/minimal/phase0/random/random_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package random

import (
"testing"

"github.com/prysmaticlabs/prysm/spectest/shared/phase0/sanity"
)

func TestMinimal_Phase0_Random(t *testing.T) {
sanity.RunBlockProcessingTest(t, "minimal", "random/random/pyspec_tests")
}
2 changes: 1 addition & 1 deletion spectest/minimal/phase0/sanity/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

func TestMinimal_Phase0_Sanity_Blocks(t *testing.T) {
sanity.RunBlockProcessingTest(t, "minimal")
sanity.RunBlockProcessingTest(t, "minimal", "sanity/blocks/pyspec_tests")
}
1 change: 1 addition & 0 deletions spectest/shared/altair/sanity/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ go_library(
"//shared/testutil:go_default_library",
"//shared/testutil/require:go_default_library",
"//spectest/utils:go_default_library",
"@com_github_d4l3k_messagediff//:go_default_library",
"@com_github_golang_snappy//:go_default_library",
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
Expand Down
6 changes: 3 additions & 3 deletions spectest/shared/altair/sanity/block_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/d4l3k/messagediff"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
core "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
Expand All @@ -20,18 +21,17 @@ import (
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/spectest/utils"
"google.golang.org/protobuf/proto"
"gopkg.in/d4l3k/messagediff.v1"
)

func init() {
core.SkipSlotCache.Disable()
}

// RunBlockProcessingTest executes "sanity/blocks" tests.
func RunBlockProcessingTest(t *testing.T, config string) {
func RunBlockProcessingTest(t *testing.T, config, folderPath string) {
require.NoError(t, utils.SetConfig(t, config))

testFolders, testsFolderPath := utils.TestFolders(t, config, "altair", "sanity/blocks/pyspec_tests")
testFolders, testsFolderPath := utils.TestFolders(t, config, "altair", folderPath)
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
helpers.ClearCache()
Expand Down
4 changes: 2 additions & 2 deletions spectest/shared/phase0/sanity/block_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ func init() {
}

// RunBlockProcessingTest executes "sanity/blocks" tests.
func RunBlockProcessingTest(t *testing.T, config string) {
func RunBlockProcessingTest(t *testing.T, config, folderPath string) {
require.NoError(t, utils.SetConfig(t, config))

testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "sanity/blocks/pyspec_tests")
testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", folderPath)
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
helpers.ClearCache()
Expand Down

0 comments on commit 49dce52

Please sign in to comment.