From 816aac82d5155ad7d644f424a2d5ce6f23105dd7 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Wed, 28 Aug 2019 15:14:00 -0500 Subject: [PATCH] clone read access to head state and block (#3350) --- beacon-chain/blockchain/BUILD.bazel | 1 + beacon-chain/blockchain/chain_info.go | 5 +++-- beacon-chain/blockchain/service.go | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index f61c5ff22..bcac77f55 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -27,6 +27,7 @@ go_library( "//proto/eth/v1alpha1:go_default_library", "//shared/bytesutil:go_default_library", "//shared/event:go_default_library", + "@com_github_gogo_protobuf//proto:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library", "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", diff --git a/beacon-chain/blockchain/chain_info.go b/beacon-chain/blockchain/chain_info.go index 4ba78690d..90ba04417 100644 --- a/beacon-chain/blockchain/chain_info.go +++ b/beacon-chain/blockchain/chain_info.go @@ -3,6 +3,7 @@ package blockchain import ( "time" + "github.com/gogo/protobuf/proto" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" ) @@ -57,12 +58,12 @@ func (c *ChainService) HeadRoot() []byte { // HeadBlock returns the head block of the chain. func (c *ChainService) HeadBlock() *ethpb.BeaconBlock { - return c.headBlock + return proto.Clone(c.headBlock).(*ethpb.BeaconBlock) } // HeadState returns the head state of the chain. func (c *ChainService) HeadState() *pb.BeaconState { - return c.headState + return proto.Clone(c.headState).(*pb.BeaconState) } // CanonicalRoot returns the canonical root of a given slot. diff --git a/beacon-chain/blockchain/service.go b/beacon-chain/blockchain/service.go index 860402f57..b9419e064 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -212,7 +212,6 @@ func (c *ChainService) saveHead(ctx context.Context, b *ethpb.BeaconBlock, r [32 "slots": b.Slot, "root": hex.EncodeToString(r[:]), }).Debug("Saved head info") - return nil }