mirror of https://github.com/poanetwork/quorum.git
refined NewBlockMsg handling in Istanbul
This commit is contained in:
parent
784491e502
commit
b9ee7c9719
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue