From: yahtoo Date: Fri, 12 Jul 2019 07:04:56 +0000 (+0800) Subject: Fix BlockSignatureMsg unbroadcast problem (#267) X-Git-Tag: v1.0.5~154 X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=commitdiff_plain;h=68b5591b9e5fddae66ce722c1a540f52dc80c164 Fix BlockSignatureMsg unbroadcast problem (#267) * Fix BlockSignatureMsg unbroadcast problem * Fix review bug --- diff --git a/netsync/consensusmgr/handle.go b/netsync/consensusmgr/handle.go index db166885..9c8642e4 100644 --- a/netsync/consensusmgr/handle.go +++ b/netsync/consensusmgr/handle.go @@ -67,7 +67,7 @@ func (m *Manager) processMsg(peerID string, msgType byte, msg ConsensusMessage) return } - logrus.WithFields(logrus.Fields{"module": logModule, "peer": peerID, "type": reflect.TypeOf(msg), "message": msg.String()}).Info("receive message from peer") + logrus.WithFields(logrus.Fields{"module": logModule, "peer": peer.Addr(), "type": reflect.TypeOf(msg), "message": msg.String()}).Info("receive message from peer") switch msg := msg.(type) { case *BlockProposeMsg: diff --git a/protocol/bbft.go b/protocol/bbft.go index 11dc0db6..888ce999 100644 --- a/protocol/bbft.go +++ b/protocol/bbft.go @@ -7,6 +7,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/vapor/config" + "github.com/vapor/crypto/ed25519/chainkd" "github.com/vapor/errors" "github.com/vapor/event" "github.com/vapor/protocol/bc" @@ -132,6 +133,7 @@ func (c *Chain) validateSign(block *types.Block) error { cachekey := signCacheKey(blockHash.String(), pubKey) if signature, ok := c.signatureCache.Get(cachekey); ok { block.Set(node.Order, signature.([]byte)) + c.eventDispatcher.Post(event.BlockSignatureEvent{BlockHash: blockHash, Signature: signature.([]byte), XPub: []byte(pubKey)}) c.signatureCache.Remove(cachekey) } else { continue @@ -165,6 +167,12 @@ func (c *Chain) ProcessBlockSignature(signature, xPub []byte, blockHash *bc.Hash // save the signature if the block is not exist if blockHeader == nil { + var xPubKey chainkd.XPub + copy(xPub[:], xPub[:]) + if !xPubKey.Verify(blockHash.Bytes(), signature) { + return errInvalidSignature + } + cacheKey := signCacheKey(blockHash.String(), xpubStr) c.signatureCache.Add(cacheKey, signature) return nil