From 5dcf67b8557eaa138d8ee2ed32889cab3e39e0e0 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 | 17 +++++++++++++++++ p2p/quality_scores.go | 3 +++ 2 files changed, 20 insertions(+) diff --git a/p2p/node/p2p_services.go b/p2p/node/p2p_services.go index 18ef94d431..32f3852616 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 @@ -102,10 +103,17 @@ func (p *P2PNode) requestFromPeer(peerID peer.ID, topic *pubsubManager.Topic, re // Finally, BlockView and HeaderView have different hash functions case *types.WorkObjectBlockView: if reqData == recvdType.Hash() { + // 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 recvdType.NumberU64(common.ZONE_CTX) > params.GoldenAgeForkNumberV1 && recvdType.GasLimit() < params.MinGasLimit(params.GoldenAgeForkNumberV1) { + return nil, errors.New("invalid response") + } return recvdType, nil } case *types.WorkObjectHeaderView: if reqData == recvdType.Hash() { + return recvdType, nil } default: @@ -125,6 +133,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) +}