From b0bd4302eb21ae017c2299f012f0922ca255162b Mon Sep 17 00:00:00 2001 From: Trung Nguyen Date: Thu, 11 Oct 2018 15:55:56 -0400 Subject: [PATCH] cloned p2p Message to be used for checking --- consensus/istanbul/backend/handler.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/consensus/istanbul/backend/handler.go b/consensus/istanbul/backend/handler.go index 496e08d1a..d2443f5b3 100644 --- a/consensus/istanbul/backend/handler.go +++ b/consensus/istanbul/backend/handler.go @@ -95,10 +95,19 @@ 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 + // as p2p.Msg can only be decoded once, we need to clone it for our own check - if data, hash, err := sb.decode(msg); err == nil && core.IsIstanbulPayload(data) { - if _, ok := sb.knownMessages.Get(hash); ok { - return true, nil + rPipe, wPipe := p2p.MsgPipe() + if err := wPipe.WriteMsg(msg); err != nil { + return false, err + } + if clonedMsg, err := rPipe.ReadMsg(); err != nil { + return false, err + } else { + if data, hash, err := sb.decode(clonedMsg); err == nil && core.IsIstanbulPayload(data) { + if _, ok := sb.knownMessages.Get(hash); ok { + return true, nil + } } } }