mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-04 00:44:27 +00:00
5374350a1c
* move shuffling to core * remove old utils * move flags to top level * package lvl comment removal * fix up references to flags * revert node.go * revert p2p_config.go * revert main.go * revert validator node.go * revert validator main.go * add flags pkg * viz * goimports
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
// Package blocks contains block processing libraries. These libraries
|
|
// process and verify block specific messages such as PoW receipt root,
|
|
// RANDAO, validator deposits, exits and slashing proofs.
|
|
package blocks
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/prysmaticlabs/go-ssz"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
)
|
|
|
|
// NewGenesisBlock returns the canonical, genesis block for the beacon chain protocol.
|
|
func NewGenesisBlock(stateRoot []byte) *ethpb.BeaconBlock {
|
|
zeroHash := params.BeaconConfig().ZeroHash[:]
|
|
genBlock := ðpb.BeaconBlock{
|
|
ParentRoot: zeroHash,
|
|
StateRoot: stateRoot,
|
|
Body: ðpb.BeaconBlockBody{},
|
|
Signature: params.BeaconConfig().EmptySignature[:],
|
|
}
|
|
return genBlock
|
|
}
|
|
|
|
// BlockFromHeader manufactures a block from its header. It contains all its fields,
|
|
// except for the block body.
|
|
func BlockFromHeader(header *ethpb.BeaconBlockHeader) *ethpb.BeaconBlock {
|
|
return ðpb.BeaconBlock{
|
|
StateRoot: header.StateRoot,
|
|
Slot: header.Slot,
|
|
Signature: header.Signature,
|
|
ParentRoot: header.ParentRoot,
|
|
}
|
|
}
|
|
|
|
// HeaderFromBlock extracts the block header from a block.
|
|
func HeaderFromBlock(block *ethpb.BeaconBlock) (*ethpb.BeaconBlockHeader, error) {
|
|
header := ðpb.BeaconBlockHeader{
|
|
Slot: block.Slot,
|
|
ParentRoot: block.ParentRoot,
|
|
Signature: block.Signature,
|
|
StateRoot: block.StateRoot,
|
|
}
|
|
root, err := ssz.HashTreeRoot(block.Body)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not tree hash block body %v", err)
|
|
}
|
|
header.BodyRoot = root[:]
|
|
return header, nil
|
|
}
|