mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 04:00:05 +00:00
37bc407b56
* initial changes * gaz * unexport and add in godoc * nocache * fix edge case * fix bad implementation * fix build file * add it in * terence's review * gaz * fix build * Apply suggestions from code review remove assigned ctx Co-authored-by: terence tsao <terence@prysmaticlabs.com>
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package stateutil
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/config/features"
|
|
"github.com/prysmaticlabs/prysm/encoding/ssz"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
)
|
|
|
|
// Eth1Root computes the HashTreeRoot Merkleization of
|
|
// a BeaconBlockHeader struct according to the eth2
|
|
// Simple Serialize specification.
|
|
func Eth1Root(hasher ssz.HashFn, eth1Data *ethpb.Eth1Data) ([32]byte, error) {
|
|
if eth1Data == nil {
|
|
return [32]byte{}, errors.New("nil eth1 data")
|
|
}
|
|
|
|
enc := eth1DataEncKey(eth1Data)
|
|
if features.Get().EnableSSZCache {
|
|
if found, ok := CachedHasher.rootsCache.Get(string(enc)); ok && found != nil {
|
|
return found.([32]byte), nil
|
|
}
|
|
}
|
|
|
|
root, err := Eth1DataRootWithHasher(hasher, eth1Data)
|
|
if err != nil {
|
|
return [32]byte{}, err
|
|
}
|
|
|
|
if features.Get().EnableSSZCache {
|
|
CachedHasher.rootsCache.Set(string(enc), root, 32)
|
|
}
|
|
return root, nil
|
|
}
|
|
|
|
// eth1DataVotesRoot computes the HashTreeRoot Merkleization of
|
|
// a list of Eth1Data structs according to the eth2
|
|
// Simple Serialize specification.
|
|
func eth1DataVotesRoot(eth1DataVotes []*ethpb.Eth1Data) ([32]byte, error) {
|
|
hashKey, err := Eth1DatasEncKey(eth1DataVotes)
|
|
if err != nil {
|
|
return [32]byte{}, err
|
|
}
|
|
|
|
if features.Get().EnableSSZCache {
|
|
if found, ok := CachedHasher.rootsCache.Get(string(hashKey[:])); ok && found != nil {
|
|
return found.([32]byte), nil
|
|
}
|
|
}
|
|
root, err := Eth1DatasRoot(eth1DataVotes)
|
|
if err != nil {
|
|
return [32]byte{}, err
|
|
}
|
|
if features.Get().EnableSSZCache {
|
|
CachedHasher.rootsCache.Set(string(hashKey[:]), root, 32)
|
|
}
|
|
return root, nil
|
|
}
|