From 5e839750438b814e22bf5ccbee4b64d5fb4fe38a Mon Sep 17 00:00:00 2001 From: gop Date: Tue, 29 Oct 2024 12:21:32 -0500 Subject: [PATCH] Reject block responses if the block is not on the new fork --- p2p/node/p2p_services.go | 10 ++++++++++ p2p/quality_scores.go | 3 +++ 2 files changed, 13 insertions(+) diff --git a/p2p/node/p2p_services.go b/p2p/node/p2p_services.go index 18ef94d431..4e62419c3d 100644 --- a/p2p/node/p2p_services.go +++ b/p2p/node/p2p_services.go @@ -19,6 +19,7 @@ import ( "github.com/dominant-strategies/go-quai/p2p/node/requestManager" "github.com/dominant-strategies/go-quai/p2p/pb" "github.com/dominant-strategies/go-quai/p2p/protocol" + "github.com/dominant-strategies/go-quai/params" ) // Opens a stream to the given peer and request some data for the given hash at the given location @@ -125,6 +126,15 @@ func (p *P2PNode) requestFromPeer(peerID peer.ID, topic *pubsubManager.Topic, re return recvdType, nil } case []*types.WorkObjectBlockView: + for _, block := range recvdType.([]*types.WorkObjectBlockView) { + // If a block is received which has a number greater than + // the goldenage fork number and does not have the updated + // gas limit, reject the response + if block != nil && block.NumberU64(common.ZONE_CTX) > params.GoldenAgeForkNumberV1 && block.GasLimit() < params.MinGasLimit(params.GoldenAgeForkNumberV1) { + p.AdjustPeerQuality(peerID, topic.String(), p2p.QualityAdjOnBadResponse) + return nil, errors.New("invalid response") + } + } return recvdType, nil default: return nil, errors.New("invalid response") diff --git a/p2p/quality_scores.go b/p2p/quality_scores.go index 2f10f2cf93..4df17d1ece 100644 --- a/p2p/quality_scores.go +++ b/p2p/quality_scores.go @@ -25,3 +25,6 @@ func QualityAdjOnNack(current int) int { func QualityAdjOnTimeout(current int) int { return boundedAdj(current, -20) } +func QualityAdjOnBadResponse(curent int) int { + return boundedAdj(curent, -40) +}