Skip to content

Commit

Permalink
Merge pull request #508 from bitcoin-sv/feature/request-announce
Browse files Browse the repository at this point in the history
request-announce
  • Loading branch information
boecklim authored Jul 19, 2024
2 parents 45b2791 + 31515a7 commit 642169b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
7 changes: 5 additions & 2 deletions internal/metamorph/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 19 additions & 6 deletions internal/metamorph/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -150,6 +152,8 @@ func TestProcessTransaction(t *testing.T) {
},
expectedResponseMapItems: 0,
expectedSetCalls: 1,
expectedAnnounceCalls: 1,
expectedRequestCalls: 1,
},
{
name: "record found",
Expand All @@ -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",
Expand All @@ -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,
},
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()))
})
}
}
Expand Down

0 comments on commit 642169b

Please sign in to comment.