Skip to content

Commit

Permalink
polygon: tidy up proto import aliases (#12685)
Browse files Browse the repository at this point in the history
  • Loading branch information
taratorio authored Nov 9, 2024
1 parent 045ada3 commit c6824f4
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 108 deletions.
4 changes: 2 additions & 2 deletions polygon/bor/bor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/erigontech/erigon-lib/chain"
libcommon "github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/crypto"
sentry "github.com/erigontech/erigon-lib/gointerfaces/sentryproto"
"github.com/erigontech/erigon-lib/gointerfaces/sentryproto"
"github.com/erigontech/erigon-lib/kv/memdb"
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon/consensus"
Expand Down Expand Up @@ -498,7 +498,7 @@ func TestSendBlock(t *testing.T) {
}

r.ReceiveWg.Add(1)
for _, err = range r.Send(&sentry.InboundMessage{Id: sentry.MessageId_NEW_BLOCK_66, Data: b, PeerId: s.PeerId}) {
for _, err = range r.Send(&sentryproto.InboundMessage{Id: sentryproto.MessageId_NEW_BLOCK_66, Data: b, PeerId: s.PeerId}) {
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions polygon/p2p/fetcher_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/direct"
"github.com/erigontech/erigon-lib/gointerfaces/sentryproto"
erigonlibtypes "github.com/erigontech/erigon-lib/gointerfaces/typesproto"
"github.com/erigontech/erigon-lib/gointerfaces/typesproto"
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon-lib/p2p/sentry"
"github.com/erigontech/erigon/core/types"
Expand Down Expand Up @@ -891,7 +891,7 @@ func (ft *fetcherTest) mockSentryInboundMessagesStream(mocks ...requestResponseM
}

return &sentryproto.SentPeers{
Peers: []*erigonlibtypes.H512{req.PeerId},
Peers: []*typesproto.H512{req.PeerId},
}, nil
}).
AnyTimes()
Expand Down
58 changes: 29 additions & 29 deletions polygon/p2p/fetcher_penalizing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/erigontech/erigon-lib/common"
sentry "github.com/erigontech/erigon-lib/gointerfaces/sentryproto"
"github.com/erigontech/erigon-lib/gointerfaces/sentryproto"
"github.com/erigontech/erigon/core/types"
)

Expand All @@ -33,9 +33,9 @@ func TestPenalizingFetcherFetchHeadersShouldPenalizePeerWhenErrTooManyHeaders(t

peerId := PeerIdFromUint64(1)
requestId := uint64(1234)
mockInboundMessages := []*sentry.InboundMessage{
mockInboundMessages := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_HEADERS_66,
Id: sentryproto.MessageId_BLOCK_HEADERS_66,
PeerId: peerId.H512(),
// response should contain 2 headers instead we return 5
Data: newMockBlockHeadersPacket66Bytes(t, requestId, 5),
Expand Down Expand Up @@ -73,9 +73,9 @@ func TestPenalizingFetcherFetchHeadersShouldPenalizePeerWhenErrNonSequentialHead
disconnectedHeaders[0] = mockBlockHeaders[0]
disconnectedHeaders[1] = mockBlockHeaders[2]
disconnectedHeaders[2] = mockBlockHeaders[4]
mockInboundMessages := []*sentry.InboundMessage{
mockInboundMessages := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_HEADERS_66,
Id: sentryproto.MessageId_BLOCK_HEADERS_66,
PeerId: peerId.H512(),
Data: blockHeadersPacket66Bytes(t, requestId, disconnectedHeaders),
},
Expand Down Expand Up @@ -112,9 +112,9 @@ func TestPenalizingFetcherFetchHeadersShouldPenalizePeerWhenErrNonSequentialHead
Number: big.NewInt(1),
GasLimit: 1234, // change a random value in order to change the header Hash
}
mockInboundMessages := []*sentry.InboundMessage{
mockInboundMessages := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_HEADERS_66,
Id: sentryproto.MessageId_BLOCK_HEADERS_66,
PeerId: peerId.H512(),
Data: blockHeadersPacket66Bytes(t, requestId, disconnectedHeaders),
},
Expand Down Expand Up @@ -149,9 +149,9 @@ func TestPenalizingFetcherFetchHeadersShouldPenalizePeerWhenHeaderGtRequestedSta
requestId := uint64(1234)
mockBlockHeaders := newMockBlockHeaders(3)
incorrectOriginHeaders := mockBlockHeaders[1:]
mockInboundMessages := []*sentry.InboundMessage{
mockInboundMessages := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_HEADERS_66,
Id: sentryproto.MessageId_BLOCK_HEADERS_66,
PeerId: peerId.H512(),
// response headers should be 2 and start at 1 - instead we start at 2
Data: blockHeadersPacket66Bytes(t, requestId, incorrectOriginHeaders),
Expand Down Expand Up @@ -186,9 +186,9 @@ func TestPenalizingFetcherFetchBodiesShouldPenalizePeerWhenErrTooManyBodies(t *t
requestId := uint64(1234)
headers := []*types.Header{{Number: big.NewInt(1)}}
hashes := []common.Hash{headers[0].Hash()}
mockInboundMessages := []*sentry.InboundMessage{
mockInboundMessages := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_BODIES_66,
Id: sentryproto.MessageId_BLOCK_BODIES_66,
PeerId: peerId.H512(),
Data: newMockBlockBodiesPacketBytes(t, requestId, &types.Body{}, &types.Body{}),
},
Expand Down Expand Up @@ -221,9 +221,9 @@ func TestPenalizingFetcherFetchBodiesShouldPenalizePeerWhenErrMissingBodies(t *t
requestId := uint64(1234)
headers := []*types.Header{{Number: big.NewInt(1)}}
hashes := []common.Hash{headers[0].Hash()}
mockInboundMessages := []*sentry.InboundMessage{
mockInboundMessages := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_BODIES_66,
Id: sentryproto.MessageId_BLOCK_BODIES_66,
PeerId: peerId.H512(),
Data: newMockBlockBodiesPacketBytes(t, requestId),
},
Expand Down Expand Up @@ -257,9 +257,9 @@ func TestPenalizingFetcherFetchBlocksBackwardsByHashShouldPenalizePeerWhenErrToo
requestId1 := uint64(1233)
headers := newMockBlockHeaders(1)
hash := headers[0].Hash()
mockInboundMessages1 := []*sentry.InboundMessage{
mockInboundMessages1 := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_HEADERS_66,
Id: sentryproto.MessageId_BLOCK_HEADERS_66,
PeerId: peerId.H512(),
Data: blockHeadersPacket66Bytes(t, requestId1, headers),
},
Expand All @@ -273,9 +273,9 @@ func TestPenalizingFetcherFetchBlocksBackwardsByHashShouldPenalizePeerWhenErrToo
wantReverse: true,
}
requestId2 := uint64(1234)
mockInboundMessages2 := []*sentry.InboundMessage{
mockInboundMessages2 := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_BODIES_66,
Id: sentryproto.MessageId_BLOCK_BODIES_66,
PeerId: peerId.H512(),
Data: newMockBlockBodiesPacketBytes(t, requestId2, &types.Body{}, &types.Body{}),
},
Expand Down Expand Up @@ -308,9 +308,9 @@ func TestPenalizingFetcherFetchBlocksBackwardsByHashShouldPenalizePeerWhenErrMis
requestId1 := uint64(1233)
headers := newMockBlockHeaders(1)
hash := headers[0].Hash()
mockInboundMessages1 := []*sentry.InboundMessage{
mockInboundMessages1 := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_HEADERS_66,
Id: sentryproto.MessageId_BLOCK_HEADERS_66,
PeerId: peerId.H512(),
Data: blockHeadersPacket66Bytes(t, requestId1, headers),
},
Expand All @@ -324,9 +324,9 @@ func TestPenalizingFetcherFetchBlocksBackwardsByHashShouldPenalizePeerWhenErrMis
wantReverse: true,
}
requestId2 := uint64(1234)
mockInboundMessages2 := []*sentry.InboundMessage{
mockInboundMessages2 := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_BODIES_66,
Id: sentryproto.MessageId_BLOCK_BODIES_66,
PeerId: peerId.H512(),
Data: newMockBlockBodiesPacketBytes(t, requestId2),
},
Expand Down Expand Up @@ -360,9 +360,9 @@ func TestPenalizingFetcherFetchBlocksBackwardsByHashShouldPenalizePeerWhenErrUne
requestId1 := uint64(1233)
headers := newMockBlockHeaders(2)
hash := headers[0].Hash()
mockInboundMessages1 := []*sentry.InboundMessage{
mockInboundMessages1 := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_HEADERS_66,
Id: sentryproto.MessageId_BLOCK_HEADERS_66,
PeerId: peerId.H512(),
Data: blockHeadersPacket66Bytes(t, requestId1, headers[1:]),
},
Expand Down Expand Up @@ -397,9 +397,9 @@ func TestPenalizingFetcherFetchBlocksBackwardsByHashShouldPenalizePeerWhenErrToo
requestId1 := uint64(1233)
headers := newMockBlockHeaders(2)
hash := headers[0].Hash()
mockInboundMessages1 := []*sentry.InboundMessage{
mockInboundMessages1 := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_HEADERS_66,
Id: sentryproto.MessageId_BLOCK_HEADERS_66,
PeerId: peerId.H512(),
Data: blockHeadersPacket66Bytes(t, requestId1, headers),
},
Expand Down Expand Up @@ -434,9 +434,9 @@ func TestPenalizingFetcherFetchBlocksBackwardsByHashShouldPenalizePeerWhenErrNon
requestId1 := uint64(1233)
headers := newMockBlockHeaders(3)
hash := headers[2].Hash()
mockInboundMessages1 := []*sentry.InboundMessage{
mockInboundMessages1 := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_HEADERS_66,
Id: sentryproto.MessageId_BLOCK_HEADERS_66,
PeerId: peerId.H512(),
Data: blockHeadersPacket66Bytes(t, requestId1, []*types.Header{headers[2], headers[0]}),
},
Expand Down Expand Up @@ -476,9 +476,9 @@ func TestPenalizingFetcherFetchBlocksBackwardsByHashShouldPenalizePeerWhenErrNon
GasLimit: 1234,
}
incorrectHeader.Hash()
mockInboundMessages1 := []*sentry.InboundMessage{
mockInboundMessages1 := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_HEADERS_66,
Id: sentryproto.MessageId_BLOCK_HEADERS_66,
PeerId: peerId.H512(),
Data: blockHeadersPacket66Bytes(t, requestId1, []*types.Header{headers[1], incorrectHeader}),
},
Expand Down
36 changes: 18 additions & 18 deletions polygon/p2p/fetcher_tracking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"google.golang.org/protobuf/types/known/emptypb"

"github.com/erigontech/erigon-lib/common"
sentry "github.com/erigontech/erigon-lib/gointerfaces/sentryproto"
"github.com/erigontech/erigon-lib/gointerfaces/sentryproto"
"github.com/erigontech/erigon/core/types"
)

Expand All @@ -39,9 +39,9 @@ func TestTrackingFetcherFetchHeadersUpdatesPeerTracker(t *testing.T) {

peerId1 := PeerIdFromUint64(1)
requestId1 := uint64(1234)
mockInboundMessages1 := []*sentry.InboundMessage{
mockInboundMessages1 := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_HEADERS_66,
Id: sentryproto.MessageId_BLOCK_HEADERS_66,
PeerId: peerId1.H512(),
Data: newMockBlockHeadersPacket66Bytes(t, requestId1, 2),
},
Expand All @@ -54,9 +54,9 @@ func TestTrackingFetcherFetchHeadersUpdatesPeerTracker(t *testing.T) {
wantRequestAmount: 2,
}
requestId2 := uint64(1235)
mockInboundMessages2 := []*sentry.InboundMessage{
mockInboundMessages2 := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_HEADERS_66,
Id: sentryproto.MessageId_BLOCK_HEADERS_66,
PeerId: peerId1.H512(),
// peer returns 0 headers for requestId2 - peer does not have this header range
Data: newMockBlockHeadersPacket66Bytes(t, requestId2, 0),
Expand Down Expand Up @@ -115,9 +115,9 @@ func TestTrackingFetcherFetchBodiesUpdatesPeerTracker(t *testing.T) {
requestId3 := uint64(1236)
mockHeaders := []*types.Header{{Number: big.NewInt(1)}}
mockHashes := []common.Hash{mockHeaders[0].Hash()}
mockInboundMessages1 := []*sentry.InboundMessage{
mockInboundMessages1 := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_BODIES_66,
Id: sentryproto.MessageId_BLOCK_BODIES_66,
PeerId: peerId1.H512(),
Data: newMockBlockBodiesPacketBytes(t, requestId1),
},
Expand All @@ -128,9 +128,9 @@ func TestTrackingFetcherFetchBodiesUpdatesPeerTracker(t *testing.T) {
wantRequestPeerId: peerId1,
wantRequestHashes: mockHashes,
}
mockInboundMessages2 := []*sentry.InboundMessage{
mockInboundMessages2 := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_BODIES_66,
Id: sentryproto.MessageId_BLOCK_BODIES_66,
PeerId: peerId2.H512(),
Data: nil, // response timeout
},
Expand All @@ -142,9 +142,9 @@ func TestTrackingFetcherFetchBodiesUpdatesPeerTracker(t *testing.T) {
wantRequestHashes: mockHashes,
responseDelay: 600 * time.Millisecond,
}
mockInboundMessages3 := []*sentry.InboundMessage{
mockInboundMessages3 := []*sentryproto.InboundMessage{
{
Id: sentry.MessageId_BLOCK_BODIES_66,
Id: sentryproto.MessageId_BLOCK_BODIES_66,
PeerId: peerId2.H512(),
Data: nil, // response timeout
},
Expand Down Expand Up @@ -244,29 +244,29 @@ func (tft *trackingFetcherTest) mockSentryStreams(mocks ...requestResponseMock)

tft.sentryClient.EXPECT().
Peers(gomock.Any(), gomock.Any()).
DoAndReturn(func(context.Context, *emptypb.Empty, ...grpc.CallOption) (*sentry.PeersReply, error) {
DoAndReturn(func(context.Context, *emptypb.Empty, ...grpc.CallOption) (*sentryproto.PeersReply, error) {
tft.peerTrackerInitialised.Store(true)
return &sentry.PeersReply{}, nil
return &sentryproto.PeersReply{}, nil
}).
Times(1)
}

func (tft *trackingFetcherTest) simulateDefaultPeerEvents() {
tft.simulatePeerEvents([]*sentry.PeerEvent{
tft.simulatePeerEvents([]*sentryproto.PeerEvent{
{
EventId: sentry.PeerEvent_Connect,
EventId: sentryproto.PeerEvent_Connect,
PeerId: PeerIdFromUint64(1).H512(),
},
{
EventId: sentry.PeerEvent_Connect,
EventId: sentryproto.PeerEvent_Connect,
PeerId: PeerIdFromUint64(2).H512(),
},
})
}

func (tft *trackingFetcherTest) simulatePeerEvents(peerEvents []*sentry.PeerEvent) {
func (tft *trackingFetcherTest) simulatePeerEvents(peerEvents []*sentryproto.PeerEvent) {
for _, peerEvent := range peerEvents {
tft.peerEvents <- &delayedMessage[*sentry.PeerEvent]{
tft.peerEvents <- &delayedMessage[*sentryproto.PeerEvent]{
message: peerEvent,
}
}
Expand Down
Loading

0 comments on commit c6824f4

Please sign in to comment.