prysm-pulse/shared/blockutil/block_utils.go

48 lines
1.4 KiB
Go
Raw Normal View History

package blockutil
import (
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
)
External slashing protection not requiring signature (#6252) * validation without signature * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * validation and update funcs * Merge branch 'slashing_protection_no_sign' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge branch 'master' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * Merge branch 'slashing_protection_no_sign' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * change order error handling * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * ivan feedback * Merge branch 'slashing_protection_no_sign' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * add tests to blocks utils * terence feedback * reduce visibility * Merge branch 'master' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign # Conflicts: # validator/client/polling/validator_attest.go # validator/client/polling/validator_propose.go * fix metrics * fix error * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * copy behaviour to streaming * Merge branch 'slashing_protection_no_sign' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign
2020-06-23 16:46:48 +00:00
// SignedBeaconBlockHeaderFromBlock function to retrieve signed block header from block.
func SignedBeaconBlockHeaderFromBlock(block *ethpb.SignedBeaconBlock) (*ethpb.SignedBeaconBlockHeader, error) {
if block.Block == nil || block.Block.Body == nil {
return nil, errors.New("nil block")
}
bodyRoot, err := block.Block.Body.HashTreeRoot()
if err != nil {
return nil, errors.Wrap(err, "failed to get body root of block")
}
return &ethpb.SignedBeaconBlockHeader{
Header: &ethpb.BeaconBlockHeader{
Slot: block.Block.Slot,
ProposerIndex: block.Block.ProposerIndex,
ParentRoot: block.Block.ParentRoot,
StateRoot: block.Block.StateRoot,
BodyRoot: bodyRoot[:],
},
Signature: block.Signature,
}, nil
}
External slashing protection not requiring signature (#6252) * validation without signature * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * validation and update funcs * Merge branch 'slashing_protection_no_sign' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge branch 'master' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * Merge branch 'slashing_protection_no_sign' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * change order error handling * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * ivan feedback * Merge branch 'slashing_protection_no_sign' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * add tests to blocks utils * terence feedback * reduce visibility * Merge branch 'master' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign # Conflicts: # validator/client/polling/validator_attest.go # validator/client/polling/validator_propose.go * fix metrics * fix error * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * copy behaviour to streaming * Merge branch 'slashing_protection_no_sign' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign
2020-06-23 16:46:48 +00:00
// BeaconBlockHeaderFromBlock function to retrieve block header from block.
func BeaconBlockHeaderFromBlock(block *ethpb.BeaconBlock) (*ethpb.BeaconBlockHeader, error) {
if block.Body == nil {
return nil, errors.New("nil block body")
}
bodyRoot, err := block.Body.HashTreeRoot()
External slashing protection not requiring signature (#6252) * validation without signature * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * validation and update funcs * Merge branch 'slashing_protection_no_sign' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge branch 'master' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * Merge branch 'slashing_protection_no_sign' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * change order error handling * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * ivan feedback * Merge branch 'slashing_protection_no_sign' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * add tests to blocks utils * terence feedback * reduce visibility * Merge branch 'master' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign # Conflicts: # validator/client/polling/validator_attest.go # validator/client/polling/validator_propose.go * fix metrics * fix error * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * copy behaviour to streaming * Merge branch 'slashing_protection_no_sign' of github.com:prysmaticlabs/prysm into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign * Merge refs/heads/master into slashing_protection_no_sign
2020-06-23 16:46:48 +00:00
if err != nil {
return nil, errors.Wrap(err, "failed to get body root of block")
}
return &ethpb.BeaconBlockHeader{
Slot: block.Slot,
ProposerIndex: block.ProposerIndex,
ParentRoot: block.ParentRoot,
StateRoot: block.StateRoot,
BodyRoot: bodyRoot[:],
}, nil
}