mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 07:28:06 -05:00
Thread Context for HTR Methods (#8770)
Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package stateV0
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"sync"
|
||||
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/htrutils"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -47,14 +49,17 @@ type stateRootHasher struct {
|
||||
|
||||
// computeFieldRoots returns the hash tree root computations of every field in
|
||||
// the beacon state as a list of 32 byte roots.
|
||||
func computeFieldRoots(state *pb.BeaconState) ([][]byte, error) {
|
||||
func computeFieldRoots(ctx context.Context, state *pb.BeaconState) ([][]byte, error) {
|
||||
if featureconfig.Get().EnableSSZCache {
|
||||
return cachedHasher.computeFieldRootsWithHasher(state)
|
||||
return cachedHasher.computeFieldRootsWithHasher(ctx, state)
|
||||
}
|
||||
return nocachedHasher.computeFieldRootsWithHasher(state)
|
||||
return nocachedHasher.computeFieldRootsWithHasher(ctx, state)
|
||||
}
|
||||
|
||||
func (h *stateRootHasher) computeFieldRootsWithHasher(state *pb.BeaconState) ([][]byte, error) {
|
||||
func (h *stateRootHasher) computeFieldRootsWithHasher(ctx context.Context, state *pb.BeaconState) ([][]byte, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "beaconState.computeFieldRootsWithHasher")
|
||||
defer span.End()
|
||||
|
||||
if state == nil {
|
||||
return nil, errors.New("nil state")
|
||||
}
|
||||
|
||||
@@ -197,14 +197,14 @@ func (b *BeaconState) Copy() iface.BeaconState {
|
||||
// HashTreeRoot of the beacon state retrieves the Merkle root of the trie
|
||||
// representation of the beacon state based on the eth2 Simple Serialize specification.
|
||||
func (b *BeaconState) HashTreeRoot(ctx context.Context) ([32]byte, error) {
|
||||
_, span := trace.StartSpan(ctx, "beaconState.HashTreeRoot")
|
||||
ctx, span := trace.StartSpan(ctx, "beaconState.HashTreeRoot")
|
||||
defer span.End()
|
||||
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
if b.merkleLayers == nil || len(b.merkleLayers) == 0 {
|
||||
fieldRoots, err := computeFieldRoots(b.state)
|
||||
fieldRoots, err := computeFieldRoots(ctx, b.state)
|
||||
if err != nil {
|
||||
return [32]byte{}, err
|
||||
}
|
||||
@@ -214,7 +214,7 @@ func (b *BeaconState) HashTreeRoot(ctx context.Context) ([32]byte, error) {
|
||||
}
|
||||
|
||||
for field := range b.dirtyFields {
|
||||
root, err := b.rootSelector(field)
|
||||
root, err := b.rootSelector(ctx, field)
|
||||
if err != nil {
|
||||
return [32]byte{}, err
|
||||
}
|
||||
@@ -379,7 +379,11 @@ func (b *BeaconState) FieldReferencesCount() map[string]uint64 {
|
||||
return refMap
|
||||
}
|
||||
|
||||
func (b *BeaconState) rootSelector(field fieldIndex) ([32]byte, error) {
|
||||
func (b *BeaconState) rootSelector(ctx context.Context, field fieldIndex) ([32]byte, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "beaconState.rootSelector")
|
||||
defer span.End()
|
||||
span.AddAttributes(trace.StringAttribute("field", field.String()))
|
||||
|
||||
hasher := hashutil.CustomSHA256Hasher()
|
||||
switch field {
|
||||
case genesisTime:
|
||||
|
||||
Reference in New Issue
Block a user