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 8d12728
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 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,22 @@ 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() {
// 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
}
default:
Expand Down

0 comments on commit 8d12728

Please sign in to comment.