mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
only broadcast vote, timeout and syncinfo if the peer do not have it (#53)
This commit is contained in:
parent
da336f53b1
commit
76724b06d7
1 changed files with 25 additions and 9 deletions
|
|
@ -906,34 +906,50 @@ func (pm *ProtocolManager) BroadcastTx(hash common.Hash, tx *types.Transaction)
|
||||||
func (pm *ProtocolManager) BroadcastVote(vote *utils.Vote) {
|
func (pm *ProtocolManager) BroadcastVote(vote *utils.Vote) {
|
||||||
hash := vote.Hash()
|
hash := vote.Hash()
|
||||||
peers := pm.peers.PeersWithoutVote(hash)
|
peers := pm.peers.PeersWithoutVote(hash)
|
||||||
|
if len(peers) > 0 {
|
||||||
for _, peer := range peers {
|
for _, peer := range peers {
|
||||||
peer.SendVote(vote)
|
err := peer.SendVote(vote)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("[BroadcastVote] Fail to broadcast vote message", "NumberOfPeers", len(peers), "peerId", peer.id, "vote", vote, "Error", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.Info("Propagated Vote", "vote hash", vote.Hash(), "voted block hash", vote.ProposedBlockInfo.Hash.Hex(), "number", vote.ProposedBlockInfo.Number, "round", vote.ProposedBlockInfo.Round, "recipients", len(peers))
|
log.Info("Propagated Vote", "vote hash", vote.Hash(), "voted block hash", vote.ProposedBlockInfo.Hash.Hex(), "number", vote.ProposedBlockInfo.Number, "round", vote.ProposedBlockInfo.Round, "recipients", len(peers))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// BroadcastTimeout will propagate a Timeout to all peers which are not known to
|
// BroadcastTimeout will propagate a Timeout to all peers which are not known to
|
||||||
// already have the given timeout.
|
// already have the given timeout.
|
||||||
func (pm *ProtocolManager) BroadcastTimeout(timeout *utils.Timeout) {
|
func (pm *ProtocolManager) BroadcastTimeout(timeout *utils.Timeout) {
|
||||||
hash := timeout.Hash()
|
hash := timeout.Hash()
|
||||||
peers := pm.peers.PeersWithoutTimeout(hash)
|
peers := pm.peers.PeersWithoutTimeout(hash)
|
||||||
|
if len(peers) > 0 {
|
||||||
for _, peer := range peers {
|
for _, peer := range peers {
|
||||||
peer.SendTimeout(timeout)
|
err := peer.SendTimeout(timeout)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("[BroadcastTimeout] Fail to broadcast timeout message", "NumberOfPeers", len(peers), "peerId", peer.id, "timeout", timeout, "Error", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.Trace("Propagated Timeout", "hash", hash, "recipients", len(peers))
|
log.Trace("Propagated Timeout", "hash", hash, "recipients", len(peers))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// BroadcastSyncInfo will propagate a SyncInfo to all peers which are not known to
|
// BroadcastSyncInfo will propagate a SyncInfo to all peers which are not known to
|
||||||
// already have the given SyncInfo.
|
// already have the given SyncInfo.
|
||||||
func (pm *ProtocolManager) BroadcastSyncInfo(syncInfo *utils.SyncInfo) {
|
func (pm *ProtocolManager) BroadcastSyncInfo(syncInfo *utils.SyncInfo) {
|
||||||
hash := syncInfo.Hash()
|
hash := syncInfo.Hash()
|
||||||
peers := pm.peers.PeersWithoutSyncInfo(hash)
|
peers := pm.peers.PeersWithoutSyncInfo(hash)
|
||||||
|
if len(peers) > 0 {
|
||||||
for _, peer := range peers {
|
for _, peer := range peers {
|
||||||
peer.SendSyncInfo(syncInfo)
|
err := peer.SendSyncInfo(syncInfo)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("[BroadcastSyncInfo] Fail to broadcast syncInfo message", "NumberOfPeers", len(peers), "peerId", peer.id, "syncInfo", syncInfo, "Error", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.Trace("Propagated SyncInfo", "hash", hash, "recipients", len(peers))
|
log.Trace("Propagated SyncInfo", "hash", hash, "recipients", len(peers))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// OrderBroadcastTx will propagate a transaction to all peers which are not known to
|
// OrderBroadcastTx will propagate a transaction to all peers which are not known to
|
||||||
// already have the given transaction.
|
// already have the given transaction.
|
||||||
func (pm *ProtocolManager) OrderBroadcastTx(hash common.Hash, tx *types.OrderTransaction) {
|
func (pm *ProtocolManager) OrderBroadcastTx(hash common.Hash, tx *types.OrderTransaction) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue