Skip to content

Commit

Permalink
Reject block responses if the block is not on the new fork
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Oct 29, 2024
1 parent 832c53a commit 5dcf67b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions p2p/node/p2p_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions p2p/quality_scores.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 5dcf67b

Please sign in to comment.