refined NewBlockMsg handling in Istanbul

This commit is contained in:
Trung Nguyen 2018-10-11 14:57:58 -04:00
parent 784491e502
commit b9ee7c9719
No known key found for this signature in database
GPG Key ID: 4636434ED9505EB7
2 changed files with 12 additions and 1 deletions

View File

@ -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
}

View File

@ -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)
}