Merge pull request #3171 from filecoin-project/feat/max-block-size-sanity-check

add sanity check for maximum block size
This commit is contained in:
Łukasz Magiera 2020-11-18 00:49:35 +01:00 committed by GitHub
commit 9328d98f84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -340,6 +340,13 @@ func (bv *BlockValidator) Validate(ctx context.Context, pid peer.ID, msg *pubsub
func (bv *BlockValidator) validateLocalBlock(ctx context.Context, msg *pubsub.Message) pubsub.ValidationResult {
stats.Record(ctx, metrics.BlockPublished.M(1))
if size := msg.Size(); size > 1<<20-1<<15 {
log.Errorf("ignoring oversize block (%dB)", size)
ctx, _ = tag.New(ctx, tag.Insert(metrics.FailureType, "oversize_block"))
stats.Record(ctx, metrics.BlockValidationFailure.M(1))
return pubsub.ValidationIgnore
}
blk, what, err := bv.decodeAndCheckBlock(msg)
if err != nil {
log.Errorf("got invalid local block: %s", err)