More instrumentation in state transitions (#3667)

* more instrumentation in state transitions

* gofmt gaz

* more

* more
This commit is contained in:
Preston Van Loon 2019-09-30 11:28:41 -07:00 committed by GitHub
parent 8ece8fb44b
commit a2a66e7cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -24,6 +24,7 @@ go_library(
"//shared/hashutil:go_default_library",
"//shared/mathutil:go_default_library",
"//shared/params:go_default_library",
"//shared/traceutil:go_default_library",
"//shared/trieutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_pkg_errors//:go_default_library",

View File

@ -20,6 +20,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/mathutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/traceutil"
"go.opencensus.io/trace"
)
@ -145,16 +146,17 @@ func CalculateStateRoot(
state *pb.BeaconState,
block *ethpb.BeaconBlock,
) ([32]byte, error) {
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.CalculateStateRoot")
defer span.End()
if ctx.Err() != nil {
traceutil.AnnotateError(span, ctx.Err())
return [32]byte{}, ctx.Err()
}
stateCopy := proto.Clone(state).(*pb.BeaconState)
b.ClearEth1DataVoteCache()
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.CalculateStateRoot")
defer span.End()
var err error
var err error
// Execute per slots transition.
stateCopy, err = ProcessSlots(ctx, stateCopy, block.Slot)
if err != nil {
@ -200,6 +202,7 @@ func ProcessSlot(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState, e
prevStateRoot, err := ssz.HashTreeRoot(state)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not tree hash prev state root")
}
state.StateRoots[state.Slot%params.BeaconConfig().SlotsPerHistoricalRoot] = prevStateRoot[:]
@ -211,6 +214,7 @@ func ProcessSlot(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState, e
}
prevBlockRoot, err := ssz.SigningRoot(state.LatestBlockHeader)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not determine prev block root")
}
// Cache the block root.
@ -231,20 +235,28 @@ func ProcessSlot(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState, e
// state.slot += 1
// ]
func ProcessSlots(ctx context.Context, state *pb.BeaconState, slot uint64) (*pb.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.ProcessSlots")
defer span.End()
span.AddAttributes(trace.Int64Attribute("slots", int64(state.Slot)-int64(slot)))
if state.Slot > slot {
return nil, fmt.Errorf("expected state.slot %d < slot %d", state.Slot, slot)
err := fmt.Errorf("expected state.slot %d < slot %d", state.Slot, slot)
traceutil.AnnotateError(span, err)
return nil, err
}
for state.Slot < slot {
if ctx.Err() != nil {
traceutil.AnnotateError(span, ctx.Err())
return nil, ctx.Err()
}
state, err := ProcessSlot(ctx, state)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not process slot")
}
if CanProcessEpoch(state) {
state, err = ProcessEpoch(ctx, state)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not process epoch")
}
}
@ -274,21 +286,25 @@ func ProcessBlock(
state, err := b.ProcessBlockHeader(state, block)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not process block header")
}
state, err = b.ProcessRandao(state, block.Body)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not verify and process randao")
}
state, err = b.ProcessEth1DataInBlock(state, block)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not process eth1 data")
}
state, err = ProcessOperations(ctx, state, block.Body)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not process block operation")
}
@ -320,21 +336,25 @@ func processBlockNoVerify(
state, err := b.ProcessBlockHeaderNoVerify(state, block)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not process block header")
}
state, err = b.ProcessRandaoNoVerify(state, block.Body)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not verify and process randao")
}
state, err = b.ProcessEth1DataInBlock(state, block)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not process eth1 data")
}
state, err = processOperationsNoVerify(ctx, state, block.Body)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not process block operation")
}