remove statusData from fetch

This commit is contained in:
alex.sharov 2021-08-14 15:47:49 +07:00
parent bb87df0afa
commit 07aad2f286
2 changed files with 12 additions and 17 deletions

View File

@ -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}))

View File

@ -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)
}
}
}