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,18 +194,31 @@ func (v *validator) signBlock(ctx context.Context, pubKey [48]byte, epoch uint64
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get domain data") 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 var sig *bls.Signature
if protectingKeymanager, supported := v.keyManager.(keymanager.ProtectingKeyManager); supported { if protectingKeymanager, supported := v.keyManager.(keymanager.ProtectingKeyManager); supported {
sig, err = protectingKeymanager.SignProposal(pubKey, domain.SignatureDomain, b) 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 { } else {
sig, err = v.keyManager.Sign(pubKey, root, domain.SignatureDomain) blockRoot, err := ssz.HashTreeRoot(b)
} if err != nil {
if err != nil { return nil, errors.Wrap(err, "could not get signing root")
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 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. // ProtectingKeyManager provides access to a keymanager that protects its clients from slashing events.
type ProtectingKeyManager interface { type ProtectingKeyManager interface {
// SignProposal signs a block proposal for the validator to broadcast. // 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 signs an attestation for the validator to broadcast.
SignAttestation(pubKey [48]byte, domain uint64, data *ethpb.AttestationData) (*bls.Signature, error) SignAttestation(pubKey [48]byte, domain uint64, data *ethpb.AttestationData) (*bls.Signature, error)