diff --git a/consensus/istanbul/backend/handler.go b/consensus/istanbul/backend/handler.go index 3b750a7b4..496e08d1a 100644 --- a/consensus/istanbul/backend/handler.go +++ b/consensus/istanbul/backend/handler.go @@ -18,6 +18,7 @@ package backend import ( "errors" + "github.com/ethereum/go-ethereum/consensus/istanbul/core" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus" @@ -93,8 +94,9 @@ func (sb *backend) HandleMsg(addr common.Address, msg p2p.Msg) (bool, error) { } if msg.Code == 0x07 && sb.core.IsProposer() { // eth.NewBlockMsg: import cycle // this case is to safeguard the race of similar block which gets propagated from other node while this node is proposing + // need to make sure this is the Gossip message from Istanbul peers - if data, hash, err := sb.decode(msg); err == nil && len(data) > 0 { + if data, hash, err := sb.decode(msg); err == nil && core.IsIstanbulPayload(data) { if _, ok := sb.knownMessages.Get(hash); ok { return true, nil } diff --git a/consensus/istanbul/core/types.go b/consensus/istanbul/core/types.go index 71e388521..ee363c7ef 100644 --- a/consensus/istanbul/core/types.go +++ b/consensus/istanbul/core/types.go @@ -160,6 +160,15 @@ func (m *message) String() string { // // helper functions +// Check if a payload is encoded from Istanbul `message` struct +func IsIstanbulPayload(payload []byte) bool { + msg := new(message) + if err := msg.FromPayload(payload, nil); err != nil { + return false + } + return true +} + func Encode(val interface{}) ([]byte, error) { return rlp.EncodeToBytes(val) }