cache successful block signature validation
This commit is contained in:
parent
50e05ae1ba
commit
81bc159b3e
@ -69,6 +69,9 @@ type BlockHeader struct {
|
|||||||
BlockSig *crypto.Signature // 13
|
BlockSig *crypto.Signature // 13
|
||||||
|
|
||||||
ForkSignaling uint64 // 14
|
ForkSignaling uint64 // 14
|
||||||
|
|
||||||
|
// internal
|
||||||
|
validated bool // true if the signature has been validated
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BlockHeader) ToStorageBlock() (block.Block, error) {
|
func (b *BlockHeader) ToStorageBlock() (block.Block, error) {
|
||||||
@ -124,6 +127,14 @@ func (blk *BlockHeader) SigningBytes() ([]byte, error) {
|
|||||||
return blkcopy.Serialize()
|
return blkcopy.Serialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (blk *BlockHeader) SetValidated() {
|
||||||
|
blk.validated = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (blk *BlockHeader) IsValidated() bool {
|
||||||
|
return blk.validated
|
||||||
|
}
|
||||||
|
|
||||||
type MsgMeta struct {
|
type MsgMeta struct {
|
||||||
BlsMessages cid.Cid
|
BlsMessages cid.Cid
|
||||||
SecpkMessages cid.Cid
|
SecpkMessages cid.Cid
|
||||||
|
@ -72,6 +72,10 @@ func CheckBlockSignature(blk *types.BlockHeader, ctx context.Context, worker add
|
|||||||
_, span := trace.StartSpan(ctx, "checkBlockSignature")
|
_, span := trace.StartSpan(ctx, "checkBlockSignature")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
|
if blk.IsValidated() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if blk.BlockSig == nil {
|
if blk.BlockSig == nil {
|
||||||
return xerrors.New("block signature not present")
|
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)
|
return xerrors.Errorf("failed to get block signing bytes: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = sigb
|
err = Verify(blk.BlockSig, worker, sigb)
|
||||||
return Verify(blk.BlockSig, worker, sigb)
|
if err == nil {
|
||||||
|
blk.SetValidated()
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// SigShim is used for introducing signature functions
|
// SigShim is used for introducing signature functions
|
||||||
|
Loading…
Reference in New Issue
Block a user