Skip to content

Commit a513ba8

Browse files
authored
Prevent Explorer Nodes from Adding Future Blocks (#4845)
2 parents 0da69c1 + 100fcba commit a513ba8

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

node/harmony/node_explorer.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ func (node *Node) explorerMessageHandler(ctx context.Context, msg *msg_pb.Messag
4343
Msg("[Explorer] onCommitted unable to parse msg")
4444
return err
4545
}
46-
46+
// If a future block is received, it logs a warning and discards the block
47+
// TODO: can be done with isRightBlockNumAndViewID(recvMsg)
48+
if current := node.Blockchain().CurrentBlock().NumberU64(); recvMsg.BlockNum != current+1 {
49+
utils.Logger().Debug().
50+
Uint64("Received BlockNum", recvMsg.BlockNum).
51+
Uint64("Current Block Number", current).
52+
Msg("[Explorer] received a future block on COMMIT phase")
53+
return nil
54+
}
4755
aggSig, mask, err := node.Consensus.ReadSignatureBitmapPayload(
4856
recvMsg.Payload, 0,
4957
)
@@ -88,6 +96,15 @@ func (node *Node) explorerMessageHandler(ctx context.Context, msg *msg_pb.Messag
8896
utils.Logger().Error().Err(err).Msg("[Explorer] Unable to parse Prepared msg")
8997
return err
9098
}
99+
// If a future block is received, it logs a warning and discards the block
100+
// TODO: can be done with isRightBlockNumAndViewID(recvMsg)
101+
if current := node.Blockchain().CurrentBlock().NumberU64(); recvMsg.BlockNum != current+1 {
102+
utils.Logger().Debug().
103+
Uint64("Received BlockNum", recvMsg.BlockNum).
104+
Uint64("Current Block Number", current).
105+
Msg("[Explorer] received a future block on PREPARE phase")
106+
return nil
107+
}
91108
block, blockObj := recvMsg.Block, &types.Block{}
92109
if err := rlp.DecodeBytes(block, blockObj); err != nil {
93110
utils.Logger().Error().Err(err).Msg("explorer could not rlp decode block")

0 commit comments

Comments
 (0)