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(firewall): remove decoding bundle for expired message #1682

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
30 changes: 4 additions & 26 deletions sync/firewall/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,35 +217,13 @@ func (f *Firewall) isExpiredMessage(msgData []byte) bool {
return true
}

// TODO: we remove on the version v1.8.0
consensusHeightExtracted := false
var consensusHeight uint32
consensusHeightBytes := msgData[msgLen-6:]
// Check if consensus height is set. Refer to the bundle encoding for more details.
if consensusHeightBytes[0] == 0x04 && consensusHeightBytes[1] == 0x1a {
consensusHeight = binary.BigEndian.Uint32(consensusHeightBytes[2:])

if consensusHeight > 2_900_000 {
consensusHeightExtracted = true
}
}
if !consensusHeightExtracted {
// Decoding the message at this level is costly, and we should avoid it.
// In future versions, this code can be removed.
// However, at the time of writing this code, we need it to prevent replay attacks.
bdl := new(bundle.Bundle)
_, err := bdl.Decode(bytes.NewReader(msgData))
if err != nil {
return true
}

consensusHeight = bdl.Message.ConsensusHeight()
}
consensusHeightRaw := msgData[msgLen-6:]
consensusHeight := binary.BigEndian.Uint32(consensusHeightRaw[2:])

// The message is expired, or the consensus height is behind the network's current height.
// In either case, the message is dropped and won't be propagated.
if f.state.LastBlockHeight() > 0 && consensusHeight < f.state.LastBlockHeight()-1 {
f.logger.Warn("firewall: expired message", "message height", consensusHeight, "our height", f.state.LastBlockHeight())
f.logger.Warn("firewall: expired message", "message height", consensusHeight,
"our height", f.state.LastBlockHeight())

return true
}
Expand Down
Loading