Skip to content

Commit

Permalink
chore: add network upgrade for extract consensus height
Browse files Browse the repository at this point in the history
  • Loading branch information
Ja7ad committed Dec 21, 2024
1 parent ddf2e35 commit 5e3a5c8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sync/firewall/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,18 @@ func (f *Firewall) isExpiredMessage(msgData []byte) bool {
return true
}

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:])
} else {

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.
Expand All @@ -238,10 +244,8 @@ func (f *Firewall) isExpiredMessage(msgData []byte) bool {

// 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 consensusHeight < f.state.LastBlockHeight()-1 ||
consensusHeight > f.state.LastBlockHeight()+1 {
f.logger.Debug("firewall: expired message", "message height", consensusHeight,
"our height", f.state.LastBlockHeight())
if consensusHeight < f.state.LastBlockHeight()-1 {
f.logger.Warn("firewall: expired message", "message height", consensusHeight, "our height", f.state.LastBlockHeight())

return true
}
Expand Down

0 comments on commit 5e3a5c8

Please sign in to comment.