encode txs

This commit is contained in:
alex.sharov 2021-07-26 09:52:20 +07:00
parent 334058cf5d
commit 634953b4c0
2 changed files with 13 additions and 14 deletions

View File

@ -76,7 +76,7 @@ func TestSendTxPropagate(t *testing.T) {
defer cancelFn()
t.Run("few remote txs", func(t *testing.T) {
m := NewMockSentry(ctx)
send := NewSend(ctx, []sentry.SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil, logger)
send := NewSend(ctx, []SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil, logger)
send.BroadcastRemotePooledTxs(toHashes([32]byte{1}, [32]byte{42}))
calls := m.SendMessageToRandomPeersCalls()
@ -87,7 +87,7 @@ func TestSendTxPropagate(t *testing.T) {
})
t.Run("much remote txs", func(t *testing.T) {
m := NewMockSentry(ctx)
send := NewSend(ctx, []sentry.SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil, logger)
send := NewSend(ctx, []SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil, logger)
list := make(Hashes, p2pTxPacketLimit*3)
for i := 0; i < len(list); i += 32 {
b := []byte(fmt.Sprintf("%x", i))
@ -107,7 +107,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, []sentry.SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil, logger)
send := NewSend(ctx, []SentryClient{direct.NewSentryClientDirect(direct.ETH66, m)}, nil, logger)
send.BroadcastLocalPooledTxs(toHashes([32]byte{1}, [32]byte{42}))
calls := m.SendMessageToAllCalls()

View File

@ -27,18 +27,23 @@ import (
"google.golang.org/grpc"
)
type SentryClient interface {
sentry.SentryClient
Protocol() uint
}
// Send - does send concrete P2P messages to Sentry. Same as Fetch but for outbound traffic
// does not initiate any messages by self
type Send struct {
ctx context.Context
sentryClients []sentry.SentryClient // sentry clients that will be used for accessing the network
sentryClients []SentryClient // sentry clients that will be used for accessing the network
pool Pool
logger *zap.SugaredLogger
wg *sync.WaitGroup
}
func NewSend(ctx context.Context, sentryClients []sentry.SentryClient, pool Pool, logger *zap.SugaredLogger) *Send {
func NewSend(ctx context.Context, sentryClients []SentryClient, pool Pool, logger *zap.SugaredLogger) *Send {
return &Send{
ctx: ctx,
pool: pool,
@ -91,9 +96,7 @@ func (f *Send) BroadcastLocalPooledTxs(txs Hashes) (sentToPeers int) {
//if !sentryClient.Ready() {
// continue
//}
//protocol:=sentryClient.Protocol()
protocol := direct.ETH66
switch protocol {
switch sentryClient.Protocol() {
case direct.ETH65:
if req65 == nil {
req65 = &sentry.OutboundMessageData{
@ -155,9 +158,7 @@ func (f *Send) BroadcastRemotePooledTxs(txs Hashes) {
// continue
//}
//protocol:=sentryClient.Protocol()
protocol := direct.ETH66
switch protocol {
switch sentryClient.Protocol() {
case direct.ETH65:
if req65 == nil {
req65 = &sentry.SendMessageToRandomPeersRequest{
@ -220,9 +221,7 @@ func (f *Send) PropagatePooledTxsToPeersList(peers []*types.H512, txs []byte) {
//}
for _, peer := range peers {
//protocol:=sentryClient.Protocol()
protocol := direct.ETH66
switch protocol {
switch sentryClient.Protocol() {
case direct.ETH65:
req65 := &sentry.SendMessageByIdRequest{
PeerId: peer,