From 07aad2f286558c5b0bef414b1d2f36d5124595d0 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Sat, 14 Aug 2021 15:47:49 +0700 Subject: [PATCH] remove statusData from fetch --- txpool/fetch_test.go | 11 ++++------- txpool/send.go | 18 ++++++++---------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/txpool/fetch_test.go b/txpool/fetch_test.go index ce96e2f20..957327bd9 100644 --- a/txpool/fetch_test.go +++ b/txpool/fetch_test.go @@ -28,7 +28,6 @@ import ( "github.com/ledgerwatch/erigon-lib/gointerfaces/sentry" "github.com/ledgerwatch/erigon-lib/gointerfaces/types" "github.com/ledgerwatch/erigon-lib/kv/memdb" - "github.com/ledgerwatch/log/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc" @@ -65,13 +64,11 @@ func TestFetch(t *testing.T) { } func TestSendTxPropagate(t *testing.T) { - logger := log.New() - ctx, cancelFn := context.WithCancel(context.Background()) defer cancelFn() t.Run("few remote byHash", func(t *testing.T) { m := NewMockSentry(ctx) - send := NewSend(ctx, []SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil, logger) + send := NewSend(ctx, []SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil) send.BroadcastRemotePooledTxs(toHashes([32]byte{1}, [32]byte{42})) calls := m.SendMessageToRandomPeersCalls() @@ -82,7 +79,7 @@ func TestSendTxPropagate(t *testing.T) { }) t.Run("much remote byHash", func(t *testing.T) { m := NewMockSentry(ctx) - send := NewSend(ctx, []SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil, logger) + send := NewSend(ctx, []SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil) list := make(Hashes, p2pTxPacketLimit*3) for i := 0; i < len(list); i += 32 { b := []byte(fmt.Sprintf("%x", i)) @@ -102,7 +99,7 @@ func TestSendTxPropagate(t *testing.T) { m.SendMessageToAllFunc = func(contextMoqParam context.Context, outboundMessageData *sentry.OutboundMessageData) (*sentry.SentPeers, error) { return &sentry.SentPeers{Peers: make([]*types.H512, 5)}, nil } - send := NewSend(ctx, []SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil, logger) + send := NewSend(ctx, []SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil) send.BroadcastLocalPooledTxs(toHashes([32]byte{1}, [32]byte{42})) calls := m.SendMessageToAllCalls() @@ -117,7 +114,7 @@ func TestSendTxPropagate(t *testing.T) { m.SendMessageToAllFunc = func(contextMoqParam context.Context, outboundMessageData *sentry.OutboundMessageData) (*sentry.SentPeers, error) { return &sentry.SentPeers{Peers: make([]*types.H512, 5)}, nil } - send := NewSend(ctx, []SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil, logger) + send := NewSend(ctx, []SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil) expectPeers := toPeerIDs(1, 2, 42) send.PropagatePooledTxsToPeersList(expectPeers, toHashes([32]byte{1}, [32]byte{42})) diff --git a/txpool/send.go b/txpool/send.go index a1e91cc72..a8591feda 100644 --- a/txpool/send.go +++ b/txpool/send.go @@ -38,16 +38,14 @@ type Send struct { sentryClients []SentryClient // sentry clients that will be used for accessing the network pool Pool - logger log.Logger - wg *sync.WaitGroup + wg *sync.WaitGroup } -func NewSend(ctx context.Context, sentryClients []SentryClient, pool Pool, logger log.Logger) *Send { +func NewSend(ctx context.Context, sentryClients []SentryClient, pool Pool) *Send { return &Send{ ctx: ctx, pool: pool, sentryClients: sentryClients, - logger: logger.New("at", "TxPool.Send"), } } @@ -102,7 +100,7 @@ func (f *Send) BroadcastLocalPooledTxs(txs Hashes) (sentToPeers int) { peers, err := sentryClient.SendMessageToAll(f.ctx, req65, &grpc.EmptyCallOption{}) if err != nil { - f.logger.Warn("sentry response", "err", err) + log.Warn("[txpool.send] BroadcastLocalPooledTxs", "err", err) } avgPeersPerSent65 += len(peers.Peers) @@ -115,7 +113,7 @@ func (f *Send) BroadcastLocalPooledTxs(txs Hashes) (sentToPeers int) { } peers, err := sentryClient.SendMessageToAll(f.ctx, req66, &grpc.EmptyCallOption{}) if err != nil { - f.logger.Warn("sentry response", "err", err) + log.Warn("[txpool.send] BroadcastLocalPooledTxs", "err", err) } avgPeersPerSent66 += len(peers.Peers) } @@ -161,7 +159,7 @@ func (f *Send) BroadcastRemotePooledTxs(txs Hashes) { } if _, err := sentryClient.SendMessageToRandomPeers(f.ctx, req65, &grpc.EmptyCallOption{}); err != nil { - f.logger.Warn("sentry response", "err", err) + log.Warn("[txpool.send] BroadcastRemotePooledTxs", "err", err) } case direct.ETH66: @@ -175,7 +173,7 @@ func (f *Send) BroadcastRemotePooledTxs(txs Hashes) { } } if _, err := sentryClient.SendMessageToRandomPeers(f.ctx, req66, &grpc.EmptyCallOption{}); err != nil { - f.logger.Warn("sentry response", "err", err) + log.Warn("[txpool.send] BroadcastRemotePooledTxs", "err", err) } } } @@ -217,7 +215,7 @@ func (f *Send) PropagatePooledTxsToPeersList(peers []PeerID, txs []byte) { } if _, err := sentryClient.SendMessageById(f.ctx, req65, &grpc.EmptyCallOption{}); err != nil { - f.logger.Warn("sentry response", "err", err) + log.Warn("[txpool.send] PropagatePooledTxsToPeersList", "err", err) } case direct.ETH66: @@ -229,7 +227,7 @@ func (f *Send) PropagatePooledTxsToPeersList(peers []PeerID, txs []byte) { }, } if _, err := sentryClient.SendMessageById(f.ctx, req66, &grpc.EmptyCallOption{}); err != nil { - f.logger.Warn("sentry response", "err", err) + log.Warn("[txpool.send] PropagatePooledTxsToPeersList", "err", err) } } }