clone read access to head state and block (#3350)

This commit is contained in:
Raul Jordan 2019-08-28 15:14:00 -05:00 committed by terence tsao
parent 9e5864fc61
commit 816aac82d5
3 changed files with 4 additions and 3 deletions

View File

@ -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",

View File

@ -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.

View File

@ -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
}