diff --git a/internal/metamorph/processor.go b/internal/metamorph/processor.go index ec6fff029..844661e86 100644 --- a/internal/metamorph/processor.go +++ b/internal/metamorph/processor.go @@ -450,7 +450,7 @@ func (p *Processor) StartProcessExpiredTransactions() { // every second time request tx, every other time announce tx if tx.Retries%2 == 0 { - // Sending GETDATA to peers to see if they have it + // Send GETDATA to peers to see if they have it p.logger.Debug("Re-getting expired tx", slog.String("hash", tx.Hash.String())) p.pm.RequestTransaction(tx.Hash) requested++ @@ -604,7 +604,10 @@ func (p *Processor) ProcessTransaction(req *ProcessorRequest) { }() } - // Announce transaction to network and save peers + // Send GETDATA to peers to see if they have it + p.pm.RequestTransaction(req.Data.Hash) + + // Announce transaction to network peers p.logger.Debug("announcing transaction", slog.String("hash", req.Data.Hash.String())) peers := p.pm.AnnounceTransaction(req.Data.Hash, nil) if len(peers) == 0 { diff --git a/internal/metamorph/processor_test.go b/internal/metamorph/processor_test.go index 2ca6d3f8a..124ae9bf7 100644 --- a/internal/metamorph/processor_test.go +++ b/internal/metamorph/processor_test.go @@ -139,6 +139,8 @@ func TestProcessTransaction(t *testing.T) { expectedResponseMapItems int expectedResponses []metamorph_api.Status expectedSetCalls int + expectedAnnounceCalls int + expectedRequestCalls int }{ { name: "record not found", @@ -150,6 +152,8 @@ func TestProcessTransaction(t *testing.T) { }, expectedResponseMapItems: 0, expectedSetCalls: 1, + expectedAnnounceCalls: 1, + expectedRequestCalls: 1, }, { name: "record found", @@ -163,7 +167,9 @@ func TestProcessTransaction(t *testing.T) { expectedResponses: []metamorph_api.Status{ metamorph_api.Status_REJECTED, }, - expectedSetCalls: 1, + expectedSetCalls: 1, + expectedAnnounceCalls: 0, + expectedRequestCalls: 0, }, { name: "store unavailable", @@ -173,7 +179,9 @@ func TestProcessTransaction(t *testing.T) { expectedResponses: []metamorph_api.Status{ metamorph_api.Status_RECEIVED, }, - expectedSetCalls: 0, + expectedSetCalls: 0, + expectedAnnounceCalls: 0, + expectedRequestCalls: 0, }, } @@ -207,10 +215,13 @@ func TestProcessTransaction(t *testing.T) { return nil }, } - pm := &mocks.PeerManagerMock{AnnounceTransactionFunc: func(txHash *chainhash.Hash, peers []p2p.PeerI) []p2p.PeerI { - require.True(t, testdata.TX1Hash.IsEqual(txHash)) - return nil - }} + pm := &mocks.PeerManagerMock{ + AnnounceTransactionFunc: func(txHash *chainhash.Hash, peers []p2p.PeerI) []p2p.PeerI { + require.True(t, testdata.TX1Hash.IsEqual(txHash)) + return nil + }, + RequestTransactionFunc: func(txHash *chainhash.Hash) p2p.PeerI { return nil }, + } publisher := &mocks.MessageQueueClientMock{ PublishRegisterTxsFunc: func(hash []byte) error { @@ -256,6 +267,8 @@ func TestProcessTransaction(t *testing.T) { } require.Equal(t, tc.expectedSetCalls, len(s.SetCalls())) + require.Equal(t, tc.expectedAnnounceCalls, len(pm.AnnounceTransactionCalls())) + require.Equal(t, tc.expectedRequestCalls, len(pm.RequestTransactionCalls())) }) } }