From 7d4d57351e3bdfab26fdd7dcaecb7e598c19b392 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 15 Jan 2020 13:19:31 +0300 Subject: [PATCH] network: fix requestTx() behaviour for consensus service It wasn't actually requesting transactions but rather sending an inventory message telling everyone that we have them which is completely wrong and easily leads to ChangeView that could be avoided. --- pkg/network/server.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/network/server.go b/pkg/network/server.go index 5ab280f19..9eabb5e7e 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -664,7 +664,7 @@ func (s *Server) handleMessage(peer Peer, msg *Message) error { } func (s *Server) handleNewPayload(p *consensus.Payload) { - s.relayInventory(payload.ConsensusType, p.Hash()) + s.relayInventoryCmd(CMDInv, payload.ConsensusType, p.Hash()) } func (s *Server) requestTx(hashes ...util.Uint256) { @@ -672,24 +672,25 @@ func (s *Server) requestTx(hashes ...util.Uint256) { return } - s.relayInventory(payload.TXType, hashes...) + s.relayInventoryCmd(CMDGetData, payload.TXType, hashes...) } -func (s *Server) relayInventory(t payload.InventoryType, hashes ...util.Uint256) { +func (s *Server) relayInventoryCmd(cmd CommandType, t payload.InventoryType, hashes ...util.Uint256) { payload := payload.NewInventory(t, hashes) - msg := NewMessage(s.Net, CMDInv, payload) + msg := NewMessage(s.Net, cmd, payload) for peer := range s.Peers() { if !peer.Handshaked() || !peer.Version().Relay { continue } - peer.WriteMsg(msg) + // Who cares about these messages anyway? + _ = peer.WriteMsg(msg) } } // relayBlock tells all the other connected nodes about the given block. func (s *Server) relayBlock(b *core.Block) { - s.relayInventory(payload.BlockType, b.Hash()) + s.relayInventoryCmd(CMDInv, payload.BlockType, b.Hash()) } // RelayTxn a new transaction to the local node and the connected peers. @@ -711,7 +712,7 @@ func (s *Server) RelayTxn(t *transaction.Transaction) RelayReason { return RelayOutOfMemory } - s.relayInventory(payload.TXType, t.Hash()) + s.relayInventoryCmd(CMDInv, payload.TXType, t.Hash()) return RelaySucceed }