diff --git a/p2p/switch_test.go b/p2p/switch_test.go index 80ab3f663..5df2c4798 100644 --- a/p2p/switch_test.go +++ b/p2p/switch_test.go @@ -467,11 +467,10 @@ func TestSwitchStopPeerForError(t *testing.T) { // send messages to the peer from sw1 p := sw1.Peers().List()[0] - e := Envelope{ + p.Send(Envelope{ ChannelID: 0x1, Message: &p2p.Message{}, - } - p.Send(e) + }) // stop sw2. this should cause the p to fail, // which results in calling StopPeerForError internally diff --git a/statesync/reactor.go b/statesync/reactor.go index 5b764d2ad..11e8fa4c5 100644 --- a/statesync/reactor.go +++ b/statesync/reactor.go @@ -132,7 +132,7 @@ func (r *Reactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) { for _, snapshot := range snapshots { r.Logger.Debug("Advertising snapshot", "height", snapshot.Height, "format", snapshot.Format, "peer", src.ID()) - e := p2p.Envelope{ + src.Send(p2p.Envelope{ ChannelID: chID, Message: mustWrapToProto(&ssproto.SnapshotsResponse{ Height: snapshot.Height, @@ -141,8 +141,7 @@ func (r *Reactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) { Hash: snapshot.Hash, Metadata: snapshot.Metadata, }), - } - src.Send(e) + }) } case *ssproto.SnapshotsResponse: @@ -188,7 +187,7 @@ func (r *Reactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) { } r.Logger.Debug("Sending chunk", "height", msg.Height, "format", msg.Format, "chunk", msg.Index, "peer", src.ID()) - e := p2p.Envelope{ + src.Send(p2p.Envelope{ ChannelID: ChunkChannel, Message: mustWrapToProto(&ssproto.ChunkResponse{ Height: msg.Height, @@ -197,8 +196,7 @@ func (r *Reactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) { Chunk: resp.Chunk, Missing: resp.Chunk == nil, }), - } - src.Send(e) + }) case *ssproto.ChunkResponse: r.mtx.RLock() @@ -279,11 +277,11 @@ func (r *Reactor) Sync(stateProvider StateProvider, discoveryTime time.Duration) hook := func() { r.Logger.Debug("Requesting snapshots from known peers") // Request snapshots from all currently connected peers - e := p2p.Envelope{ + + r.Switch.NewBroadcast(p2p.Envelope{ ChannelID: SnapshotChannel, Message: mustWrapToProto(&ssproto.SnapshotsRequest{}), - } - r.Switch.NewBroadcast(e) + }) } hook() diff --git a/statesync/syncer.go b/statesync/syncer.go index 13d9fd57d..d1d2aef39 100644 --- a/statesync/syncer.go +++ b/statesync/syncer.go @@ -471,15 +471,14 @@ func (s *syncer) requestChunk(snapshot *snapshot, chunk uint32) { } s.logger.Debug("Requesting snapshot chunk", "height", snapshot.Height, "format", snapshot.Format, "chunk", chunk, "peer", peer.ID()) - e := p2p.Envelope{ + peer.Send(p2p.Envelope{ ChannelID: ChunkChannel, Message: mustWrapToProto(&ssproto.ChunkRequest{ Height: snapshot.Height, Format: snapshot.Format, Index: chunk, }), - } - peer.Send(e) + }) } // verifyApp verifies the sync, checking the app hash, last block height and app version