Use BeaconBlockHeader in place of BeaconBlock (#5049)

This commit is contained in:
Jim McDonald 2020-03-09 13:08:30 +00:00 committed by GitHub
parent 01cb01a8f2
commit 0c3af32274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 10 deletions

View File

@ -194,19 +194,32 @@ func (v *validator) signBlock(ctx context.Context, pubKey [48]byte, epoch uint64
if err != nil {
return nil, errors.Wrap(err, "could not get domain data")
}
root, err := ssz.HashTreeRoot(b)
if err != nil {
return nil, errors.Wrap(err, "could not get signing root")
}
var sig *bls.Signature
if protectingKeymanager, supported := v.keyManager.(keymanager.ProtectingKeyManager); supported {
sig, err = protectingKeymanager.SignProposal(pubKey, domain.SignatureDomain, b)
} else {
sig, err = v.keyManager.Sign(pubKey, root, domain.SignatureDomain)
}
bodyRoot, err := ssz.HashTreeRoot(b.Body)
if err != nil {
return nil, errors.Wrap(err, "could not get signing root")
}
blockHeader := &ethpb.BeaconBlockHeader{
Slot: b.Slot,
StateRoot: b.StateRoot,
ParentRoot: b.ParentRoot,
BodyRoot: bodyRoot[:],
}
sig, err = protectingKeymanager.SignProposal(pubKey, domain.SignatureDomain, blockHeader)
if err != nil {
return nil, errors.Wrap(err, "could not sign block proposal")
}
} else {
blockRoot, err := ssz.HashTreeRoot(b)
if err != nil {
return nil, errors.Wrap(err, "could not get signing root")
}
sig, err = v.keyManager.Sign(pubKey, blockRoot, domain.SignatureDomain)
if err != nil {
return nil, errors.Wrap(err, "could not sign block proposal")
}
}
return sig.Marshal(), nil
}

View File

@ -27,7 +27,7 @@ type KeyManager interface {
// ProtectingKeyManager provides access to a keymanager that protects its clients from slashing events.
type ProtectingKeyManager interface {
// SignProposal signs a block proposal for the validator to broadcast.
SignProposal(pubKey [48]byte, domain uint64, data *ethpb.BeaconBlock) (*bls.Signature, error)
SignProposal(pubKey [48]byte, domain uint64, data *ethpb.BeaconBlockHeader) (*bls.Signature, error)
// SignAttestation signs an attestation for the validator to broadcast.
SignAttestation(pubKey [48]byte, domain uint64, data *ethpb.AttestationData) (*bls.Signature, error)