Skip to content

Commit

Permalink
Fix Fork Copying (prysmaticlabs#4922)
Browse files Browse the repository at this point in the history
* add fix and reg test

* goimports
  • Loading branch information
nisdas authored and cryptomental committed Feb 28, 2020
1 parent ca8ed62 commit 720115b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
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)
}

}

0 comments on commit 720115b

Please sign in to comment.