cache successful block signature validation

This commit is contained in:
vyzo 2020-05-14 19:41:10 +03:00
parent 50e05ae1ba
commit 81bc159b3e
2 changed files with 21 additions and 2 deletions

View File

@ -69,6 +69,9 @@ type BlockHeader struct {
BlockSig *crypto.Signature // 13
ForkSignaling uint64 // 14
// internal
validated bool // true if the signature has been validated
}
func (b *BlockHeader) ToStorageBlock() (block.Block, error) {
@ -124,6 +127,14 @@ func (blk *BlockHeader) SigningBytes() ([]byte, error) {
return blkcopy.Serialize()
}
func (blk *BlockHeader) SetValidated() {
blk.validated = true
}
func (blk *BlockHeader) IsValidated() bool {
return blk.validated
}
type MsgMeta struct {
BlsMessages cid.Cid
SecpkMessages cid.Cid

View File

@ -72,6 +72,10 @@ func CheckBlockSignature(blk *types.BlockHeader, ctx context.Context, worker add
_, span := trace.StartSpan(ctx, "checkBlockSignature")
defer span.End()
if blk.IsValidated() {
return nil
}
if blk.BlockSig == nil {
return xerrors.New("block signature not present")
}
@ -81,8 +85,12 @@ func CheckBlockSignature(blk *types.BlockHeader, ctx context.Context, worker add
return xerrors.Errorf("failed to get block signing bytes: %w", err)
}
_ = sigb
return Verify(blk.BlockSig, worker, sigb)
err = Verify(blk.BlockSig, worker, sigb)
if err == nil {
blk.SetValidated()
}
return err
}
// SigShim is used for introducing signature functions