2019-02-26 03:42:31 +00:00
|
|
|
package hashutil
|
|
|
|
|
|
|
|
import (
|
2019-04-01 15:45:15 +00:00
|
|
|
"reflect"
|
|
|
|
|
2019-02-26 03:42:31 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
// HashBeaconBlock hashes the full block without the proposer signature.
|
|
|
|
// The proposer signature is ignored in order obtain the same block hash used
|
|
|
|
// as the "block_root" property in the proposer signature data.
|
|
|
|
func HashBeaconBlock(bb *pb.BeaconBlock) ([32]byte, error) {
|
2019-04-01 15:45:15 +00:00
|
|
|
if bb == nil || reflect.ValueOf(bb).IsNil() {
|
|
|
|
return [32]byte{}, ErrNilProto
|
|
|
|
}
|
2019-02-26 03:42:31 +00:00
|
|
|
// Ignore the proposer signature by temporarily deleting it.
|
|
|
|
sig := bb.Signature
|
|
|
|
bb.Signature = nil
|
|
|
|
defer func() { bb.Signature = sig }()
|
|
|
|
|
2019-03-07 16:32:01 +00:00
|
|
|
return HashProto(bb)
|
2019-02-26 03:42:31 +00:00
|
|
|
}
|