diff --git a/README.md b/README.md index 62f639bdc..ce3fb5f51 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build status](https://badge.buildkite.com/b555891daf3614bae4284dcf365b2340cefc0089839526f096.svg?branch=master)](https://buildkite.com/prysmatic-labs/prysm) [![fuzzit](https://app.fuzzit.dev/badge?org_id=prysmaticlabs-gh)](https://app.fuzzit.dev/orgs/prysmaticlabs-gh/dashboard) -[![ETH2.0_Spec_Version 0.11.2](https://img.shields.io/badge/ETH2.0%20Spec%20Version-v0.11.2-blue.svg)](https://github.com/ethereum/eth2.0-specs/tree/v0.11.2) +[![ETH2.0_Spec_Version 0.11.3](https://img.shields.io/badge/ETH2.0%20Spec%20Version-v0.11.3-blue.svg)](https://github.com/ethereum/eth2.0-specs/tree/v0.11.3) [![Discord](https://user-images.githubusercontent.com/7288322/34471967-1df7808a-efbb-11e7-9088-ed0b04151291.png)](https://discord.gg/KSA7rPr) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/prysmaticlabs/geth-sharding?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) diff --git a/WORKSPACE b/WORKSPACE index 6e1df6192..b9201da81 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -214,8 +214,8 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "e31f491682a7b5bcf48250efefd150e6dcf0b2d7658d0ec5407c053fb84cbad0", - url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.11.2/general.tar.gz", + sha256 = "489f85d7c17a901b9069c95f656154fdf1385db00f3aeb3e0319aed8745f9453", + url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.11.3/general.tar.gz", ) http_archive( @@ -230,8 +230,8 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "1d978d482cd680f99dfc808ccfd59c88e33089450ffc1e283041cbf6dc8982db", - url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.11.2/minimal.tar.gz", + sha256 = "b83000fbcb60b7a5b8c0e805f3fee6953b17bfe0fe6658416e7d99e6d261f284", + url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.11.3/minimal.tar.gz", ) http_archive( @@ -246,8 +246,8 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "ac68dcd5c3a78a7a51e86b61131f71683d844c81b79547029cc6dfa259c3c6dd", - url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.11.2/mainnet.tar.gz", + sha256 = "ae0c09ab49afa69085c91f9e2f2f4de6526d43b927609839b1597c674b4dccde", + url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.11.3/mainnet.tar.gz", ) http_archive( diff --git a/beacon-chain/core/state/transition.go b/beacon-chain/core/state/transition.go index f75f98f70..451d060f1 100644 --- a/beacon-chain/core/state/transition.go +++ b/beacon-chain/core/state/transition.go @@ -257,16 +257,13 @@ func ProcessSlots(ctx context.Context, state *stateTrie.BeaconState, slot uint64 } span.AddAttributes(trace.Int64Attribute("slots", int64(slot)-int64(state.Slot()))) - if state.Slot() > slot { + // The block must have a higher slot than parent state. + if state.Slot() >= slot { err := fmt.Errorf("expected state.slot %d < slot %d", state.Slot(), slot) traceutil.AnnotateError(span, err) return nil, err } - if state.Slot() == slot { - return state, nil - } - highestSlot := state.Slot() key := state.Slot() diff --git a/beacon-chain/core/state/transition_test.go b/beacon-chain/core/state/transition_test.go index 37c19607f..4e7c98337 100644 --- a/beacon-chain/core/state/transition_test.go +++ b/beacon-chain/core/state/transition_test.go @@ -481,7 +481,7 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) { aggBits.SetBitAt(0, true) blockAtt := ðpb.Attestation{ Data: ðpb.AttestationData{ - Slot: beaconState.Slot() - 1, + Slot: beaconState.Slot(), Target: ðpb.Checkpoint{Epoch: helpers.CurrentEpoch(beaconState)}, Source: ðpb.Checkpoint{ Epoch: 0, @@ -525,20 +525,32 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) { } exit.Signature = privKeys[exit.Exit.ValidatorIndex].Sign(signingRoot[:]).Marshal()[:] + header := beaconState.LatestBlockHeader() + prevStateRoot, err := beaconState.HashTreeRoot(context.Background()) + if err != nil { + t.Fatal(err) + } + header.StateRoot = prevStateRoot[:] + if err := beaconState.SetLatestBlockHeader(header); err != nil { + t.Fatal(err) + } parentRoot, err := stateutil.BlockHeaderRoot(beaconState.LatestBlockHeader()) if err != nil { t.Fatal(err) } - - randaoReveal, err := testutil.RandaoReveal(beaconState, currentEpoch, privKeys) + copied := beaconState.Copy() + if err := copied.SetSlot(beaconState.Slot() + 1); err != nil { + t.Fatal(err) + } + randaoReveal, err := testutil.RandaoReveal(copied, currentEpoch, privKeys) if err != nil { t.Fatal(err) } block := ðpb.SignedBeaconBlock{ Block: ðpb.BeaconBlock{ ParentRoot: parentRoot[:], - Slot: beaconState.Slot(), - ProposerIndex: 17, + Slot: beaconState.Slot() + 1, + ProposerIndex: 13, Body: ðpb.BeaconBlockBody{ RandaoReveal: randaoReveal, ProposerSlashings: proposerSlashings, @@ -559,6 +571,9 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) { } block.Signature = sig.Marshal() + if beaconState.SetSlot(block.Block.Slot) != nil { + t.Fatal(err) + } beaconState, err = state.ProcessBlock(context.Background(), beaconState, block) if err != nil { t.Fatalf("Expected block to pass processing conditions: %v", err) @@ -829,6 +844,7 @@ func TestProcessBlk_AttsBasedOnValidatorCount(t *testing.T) { for i := 0; i < len(atts); i++ { att := ðpb.Attestation{ Data: ðpb.AttestationData{ + Slot: 1, Source: ðpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]}, Target: ðpb.Checkpoint{Epoch: 0}}, AggregationBits: aggBits, @@ -859,18 +875,33 @@ func TestProcessBlk_AttsBasedOnValidatorCount(t *testing.T) { atts[i] = att } - epochSignature, err := testutil.RandaoReveal(s, helpers.CurrentEpoch(s), privKeys) + copied := s.Copy() + if err := copied.SetSlot(s.Slot() + 1); err != nil { + t.Fatal(err) + } + epochSignature, err := testutil.RandaoReveal(copied, helpers.CurrentEpoch(copied), privKeys) if err != nil { t.Fatal(err) } + header := s.LatestBlockHeader() + prevStateRoot, err := s.HashTreeRoot(context.Background()) + if err != nil { + t.Fatal(err) + } + header.StateRoot = prevStateRoot[:] + if err := s.SetLatestBlockHeader(header); err != nil { + t.Fatal(err) + } + parentRoot, err := stateutil.BlockHeaderRoot(s.LatestBlockHeader()) if err != nil { t.Fatal(err) } + blk := ðpb.SignedBeaconBlock{ Block: ðpb.BeaconBlock{ - ProposerIndex: 72, - Slot: s.Slot(), + ProposerIndex: 156, + Slot: s.Slot() + 1, ParentRoot: parentRoot[:], Body: ðpb.BeaconBlockBody{ Eth1Data: ðpb.Eth1Data{}, @@ -890,6 +921,9 @@ func TestProcessBlk_AttsBasedOnValidatorCount(t *testing.T) { config.MinAttestationInclusionDelay = 0 params.OverrideBeaconConfig(config) + if s.SetSlot(s.Slot()+1) != nil { + t.Fatal(err) + } if _, err := state.ProcessBlock(context.Background(), s, blk); err != nil { t.Fatal(err) } @@ -1036,3 +1070,29 @@ func TestProcessOperations_IncorrectDeposits(t *testing.T) { t.Errorf("Expected %s, received %v", want, err) } } + +func TestProcessSlots_SameSlotAsParentState(t *testing.T) { + slot := uint64(2) + parentState, err := beaconstate.InitializeFromProto(&pb.BeaconState{Slot: slot}) + if err != nil { + t.Fatal(err) + } + + wanted := "expected state.slot 2 < slot 2" + if _, err := state.ProcessSlots(context.Background(), parentState, slot); err.Error() != wanted { + t.Error("Did not get wanted error") + } +} + +func TestProcessSlots_LowerSlotAsParentState(t *testing.T) { + slot := uint64(2) + parentState, err := beaconstate.InitializeFromProto(&pb.BeaconState{Slot: slot}) + if err != nil { + t.Fatal(err) + } + + wanted := "expected state.slot 2 < slot 1" + if _, err := state.ProcessSlots(context.Background(), parentState, slot-1); err.Error() != wanted { + t.Error("Did not get wanted error") + } +}