Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slot processing spec test #2813

Merged
merged 37 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
013cb25
update PrevEpoch
terencechain Jun 12, 2019
9a9a7ce
Merge branch 'spec-v0.6' of https://github.com/prysmaticlabs/prysm in…
terencechain Jun 12, 2019
68990ec
Merge branch 'spec-v0.6' of https://github.com/prysmaticlabs/prysm in…
terencechain Jun 13, 2019
b6adeac
Merge branch 'spec-v0.6' of https://github.com/prysmaticlabs/prysm in…
terencechain Jun 16, 2019
42ddcb1
Merge branch 'spec-v0.6' of https://github.com/prysmaticlabs/prysm in…
terencechain Jun 17, 2019
23a4068
quick commit to get feedback
terencechain Jun 17, 2019
47913c2
done
terencechain Jun 17, 2019
5c295d5
update BUILD
terencechain Jun 17, 2019
b4e61c7
update yaml
terencechain Jun 17, 2019
ca739fd
update yaml
terencechain Jun 17, 2019
7fbf90f
error unmarshaling json
terencechain Jun 18, 2019
6b55531
error unmarshaling json
terencechain Jun 18, 2019
8d01800
started fixing tests ^_^
terencechain Jun 18, 2019
d41b65a
Merge branch 'spec-v0.6' of https://github.com/prysmaticlabs/prysm in…
terencechain Jun 18, 2019
90a4298
convert gen state
terencechain Jun 18, 2019
042babf
add config
nisdas Jun 18, 2019
73bda80
gaz
nisdas Jun 18, 2019
e838691
lint
nisdas Jun 18, 2019
5ec3027
Merge remote-tracking branch 'origin/specConfig' into slot-processing…
terencechain Jun 18, 2019
385a1c8
move
nisdas Jun 18, 2019
cd84625
add test
nisdas Jun 18, 2019
75b591e
Merge remote-tracking branch 'origin/specConfig' into slot-processing…
terencechain Jun 18, 2019
5abe328
fix test
nisdas Jun 18, 2019
e153b2a
add test target
nisdas Jun 18, 2019
292aaf5
remove extra files
nisdas Jun 18, 2019
35928f7
Merge branch 'spec-v0.6' into specConfig
rauljordan Jun 18, 2019
f90e7ba
abs filepaths
nisdas Jun 18, 2019
0065a91
remove yamls
nisdas Jun 18, 2019
19cfb66
Merge branch 'specConfig' of https://github.com/prysmaticlabs/geth-sh…
nisdas Jun 18, 2019
a6a47e3
gaz
nisdas Jun 18, 2019
4cf8054
aligned with the spec
terencechain Jun 18, 2019
4fb2669
merged 0.6
terencechain Jun 18, 2019
509b518
merged 0.6
terencechain Jun 18, 2019
d2209dd
updated test with new protobuf name
terencechain Jun 19, 2019
057f5c4
done
terencechain Jun 25, 2019
c474ce7
fixed visibility
terencechain Jun 25, 2019
f884a9e
removed size
terencechain Jun 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
sha256 = "d297d5df03d1a635450cdb6d746e585485529ce13f121fffc375ad12470ae32f",
sha256 = "56847989737e816ab7d23f3bb2422347dfa81271bae81a94de512c01461fab25",
url = "https://github.com/prysmaticlabs/eth2.0-spec-tests/releases/download/v0.7.1/base64_encoded_archive.tar.gz",
)

Expand Down
1 change: 1 addition & 0 deletions beacon-chain/core/blocks/block_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func ProcessBlockHeader(
if beaconState.Slot != block.Slot {
return nil, fmt.Errorf("state slot: %d is different then block slot: %d", beaconState.Slot, block.Slot)
}

parentRoot, err := ssz.SigningRoot(beaconState.LatestBlockHeader)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/core/epoch/epoch_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ func crosslinkDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
}
}
}

return rewards, penalties, nil
}

Expand Down
28 changes: 28 additions & 0 deletions beacon-chain/core/state/spectest/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = ["sanity_slots_test.yaml.go"],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/core/state/spectest",
visibility = ["//visibility:public"],
)

go_test(
name = "go_default_test",
size = "small",
srcs = ["slot_processing_test.go"],
data = [
"@eth2_spec_tests//:test_data",
],
embed = [":go_default_library"],
tags = ["spectest"],
deps = [
"//beacon-chain/core/state:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/params/spectest:go_default_library",
"//shared/testutil:go_default_library",
"@com_github_ghodss_yaml//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)
146 changes: 146 additions & 0 deletions beacon-chain/core/state/spectest/sanity_slots_test.yaml.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions beacon-chain/core/state/spectest/slot_processing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package spectest

import (
"context"
"io/ioutil"
"testing"

"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/ghodss/yaml"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/params/spectest"
"github.com/prysmaticlabs/prysm/shared/testutil"
)

func TestSlotProcessingMainnet(t *testing.T) {
filepath, err := bazel.Runfile("/eth2_spec_tests/tests/sanity/slots/sanity_slots_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
file, err := ioutil.ReadFile(filepath)
if err != nil {
t.Fatalf("Could not load file %v", err)
}

s := &SanitySlotsTest{}
if err := yaml.Unmarshal(file, s); err != nil {
t.Fatalf("Failed to Unmarshal: %v", err)
}

if err := spectest.SetConfig(s.Config); err != nil {
t.Fatal(err)
}

for _, tt := range s.TestCases {
t.Run(tt.Description, func(t *testing.T) {
preState := &pb.BeaconState{}
if err := testutil.ConvertToPb(tt.Pre, preState); err != nil {
t.Fatal(err)
}

var postState *pb.BeaconState

postState, err = state.ProcessSlots(context.Background(), preState, preState.Slot+tt.Slots)
if err != nil {
t.Fatal(err)
}

expectedPostState := &pb.BeaconState{}
if err := testutil.ConvertToPb(tt.Post, expectedPostState); err != nil {
t.Fatal(err)
}

expected, err := ssz.HashTreeRoot(expectedPostState)
if err != nil {
t.Fatal(err)
}
received, err := ssz.HashTreeRoot(postState)
if err != nil {
t.Fatal(err)
}
if expected != received {
t.Fatal("post state does not match")
}
})
}
}
18 changes: 17 additions & 1 deletion beacon-chain/core/state/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,37 @@ func ExecuteStateTransition(

// ProcessSlot happens every slot and focuses on the slot counter and block roots record updates.
// It happens regardless if there's an incoming block or not.
// Spec pseudocode definition:
//
// def process_slot(state: BeaconState) -> None:
// # Cache state root
// previous_state_root = hash_tree_root(state)
// state.state_roots[state.slot % SLOTS_PER_HISTORICAL_ROOT] = previous_state_root
//
// # Cache latest block header state root
// if state.latest_block_header.state_root == ZERO_HASH:
// state.latest_block_header.state_root = previous_state_root
//
// # Cache block root
// previous_block_root = signing_root(state.latest_block_header)
// state.block_roots[state.slot % SLOTS_PER_HISTORICAL_ROOT] = previous_block_root
func ProcessSlot(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.state.ProcessSlot")
defer span.End()
prevStateRoot, err := ssz.HashTreeRoot(state)
if err != nil {
return nil, fmt.Errorf("could not tree hash prev state root: %v", err)
}

state.LatestStateRoots[state.Slot%params.BeaconConfig().SlotsPerHistoricalRoot] = prevStateRoot[:]
zeroHash := params.BeaconConfig().ZeroHash

// Cache latest block header state root.
if bytes.Equal(state.LatestBlockHeader.StateRoot, zeroHash[:]) {
state.LatestBlockHeader.StateRoot = prevStateRoot[:]
}
prevBlockRoot, err := ssz.HashTreeRoot(state.LatestBlockHeader)

prevBlockRoot, err := ssz.SigningRoot(state.LatestBlockHeader)
if err != nil {
return nil, fmt.Errorf("could not determine prev block root: %v", err)
}
Expand Down