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

Fix Fork Copying #4922

Merged
merged 2 commits into from Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions beacon-chain/state/BUILD.bazel
Expand Up @@ -46,5 +46,6 @@ go_test(
"//shared/stateutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
],
)
4 changes: 2 additions & 2 deletions beacon-chain/state/getters.go
Expand Up @@ -135,8 +135,8 @@ func (b *BeaconState) Fork() *pbp2p.Fork {

prevVersion := make([]byte, len(b.state.Fork.PreviousVersion))
copy(prevVersion, b.state.Fork.PreviousVersion)
currVersion := make([]byte, len(b.state.Fork.PreviousVersion))
copy(currVersion, b.state.Fork.PreviousVersion)
currVersion := make([]byte, len(b.state.Fork.CurrentVersion))
copy(currVersion, b.state.Fork.CurrentVersion)
return &pbp2p.Fork{
PreviousVersion: prevVersion,
CurrentVersion: currVersion,
Expand Down
22 changes: 22 additions & 0 deletions beacon-chain/state/types_test.go
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
Expand Down Expand Up @@ -226,3 +227,24 @@ func TestBeaconState_ImmutabilityWithSharedResources(t *testing.T) {
t.Fatal("Expected a.BlockRoots() to be different from b.BlockRoots()")
}
}

func TestForkManualCopy_OK(t *testing.T) {
params.UseMinimalConfig()
genesis := setupGenesisState(t, 64)
a, err := stateTrie.InitializeFromProto(genesis)
if err != nil {
t.Fatal(err)
}
wantedFork := &pb.Fork{
PreviousVersion: []byte{'a', 'b', 'c'},
CurrentVersion: []byte{'d', 'e', 'f'},
Epoch: 0,
}
a.SetFork(wantedFork)

newState := a.CloneInnerState()
if !ssz.DeepEqual(newState.Fork, wantedFork) {
t.Errorf("Wanted %v but got %v", wantedFork, newState.Fork)
}

}