Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix BuildBlocksValidator: use bytes buffer pool correctly #10965

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions op-node/p2p/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,15 @@ func BuildBlocksValidator(log log.Logger, cfg *rollup.Config, runCfg GossipRunti

res := msgBufPool.Get().(*[]byte)
defer msgBufPool.Put(res)
data, err := snappy.Decode((*res)[:0], message.Data)
data, err := snappy.Decode(*res, message.Data)
if err != nil {
log.Warn("invalid snappy compression", "err", err, "peer", id)
return pubsub.ValidationReject
}
*res = data // if we ended up growing the slice capacity, fine, keep the larger one.
// if we ended up growing the slice capacity, fine, keep the larger one.
if len(data) > len(*res) {
*res = data
}

// message starts with compact-encoding secp256k1 encoded signature
signatureBytes, payloadBytes := data[:65], data[65:]
Expand Down Expand Up @@ -336,13 +339,13 @@ func BuildBlocksValidator(log log.Logger, cfg *rollup.Config, runCfg GossipRunti
return pubsub.ValidationReject
}

// [REJECT] if a V2 Block does not have withdrawals
// [REJECT] if a >= V2 Block does not have withdrawals
if blockVersion.HasWithdrawals() && payload.Withdrawals == nil {
log.Warn("payload is on v2/v3 topic, but does not have withdrawals", "bad_hash", payload.BlockHash.String())
return pubsub.ValidationReject
}

// [REJECT] if a V2 Block has non-empty withdrawals
// [REJECT] if a >= V2 Block has non-empty withdrawals
if blockVersion.HasWithdrawals() && len(*payload.Withdrawals) != 0 {
log.Warn("payload is on v2/v3 topic, but has non-empty withdrawals", "bad_hash", payload.BlockHash.String(), "withdrawal_count", len(*payload.Withdrawals))
return pubsub.ValidationReject
Expand All @@ -362,13 +365,13 @@ func BuildBlocksValidator(log log.Logger, cfg *rollup.Config, runCfg GossipRunti

if blockVersion.HasBlobProperties() {
// [REJECT] if the block is on a topic >= V3 and has a blob gas used value that is not zero
if payload.BlobGasUsed == nil || (payload.BlobGasUsed != nil && *payload.BlobGasUsed != 0) {
if payload.BlobGasUsed == nil || *payload.BlobGasUsed != 0 {
log.Warn("payload is on v3 topic, but has non-zero blob gas used", "bad_hash", payload.BlockHash.String(), "blob_gas_used", payload.BlobGasUsed)
return pubsub.ValidationReject
}

// [REJECT] if the block is on a topic >= V3 and has an excess blob gas value that is not zero
if payload.ExcessBlobGas == nil || (payload.ExcessBlobGas != nil && *payload.ExcessBlobGas != 0) {
if payload.ExcessBlobGas == nil || *payload.ExcessBlobGas != 0 {
log.Warn("payload is on v3 topic, but has non-zero excess blob gas", "bad_hash", payload.BlockHash.String(), "excess_blob_gas", payload.ExcessBlobGas)
return pubsub.ValidationReject
}
Expand Down