Skip to content

Commit

Permalink
Merge pull request #235 from bitcoin-sv/fix/response-map-expiry
Browse files Browse the repository at this point in the history
Do not check for expiry when getting hash from memory
  • Loading branch information
boecklim authored Jan 5, 2024
2 parents d02c960 + 18c8ae7 commit 0ec9a61
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
4 changes: 0 additions & 4 deletions metamorph/processor_response_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ func (m *ProcessorResponseMap) Get(hash *chainhash.Hash) (*processor_response.Pr
return nil, false
}

if m.now().Sub(processorResponse.Start) > m.Expiry {
return nil, false
}

return processorResponse, true
}

Expand Down
49 changes: 35 additions & 14 deletions metamorph/processor_response_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,42 @@ func TestNewProcessorResponseMap(t *testing.T) {
assert.Equalf(t, expiry, prm.Expiry, "NewProcessorResponseMap(%v)", expiry)
assert.Len(t, prm.ResponseItems, 0)
})
}

t.Run("go routine", func(t *testing.T) {
proc := NewProcessorResponseMap(50 * time.Millisecond)
proc.Set(testdata.TX1Hash, processor_response.NewProcessorResponseWithStatus(testdata.TX1Hash, metamorph_api.Status_SENT_TO_NETWORK))
item, ok := proc.Get(testdata.TX1Hash)
assert.True(t, ok)
assert.Equal(t, metamorph_api.Status_SENT_TO_NETWORK, item.GetStatus())

time.Sleep(100 * time.Millisecond)

// should be cleaned up
item, ok = proc.Get(testdata.TX1Hash)
assert.False(t, ok)
assert.Nil(t, item)
})
func TestProcessorResponseMapGet(t *testing.T) {
tt := []struct {
name string
hash *chainhash.Hash

expectedFound bool
}{
{
name: "found",
hash: testdata.TX1Hash,

expectedFound: true,
},
{
name: "not found",
hash: testdata.TX2Hash,

expectedFound: false,
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
proc := NewProcessorResponseMap(50 * time.Millisecond)
proc.Set(testdata.TX1Hash, processor_response.NewProcessorResponseWithStatus(testdata.TX1Hash, metamorph_api.Status_SENT_TO_NETWORK))

item, ok := proc.Get(tc.hash)
require.Equal(t, tc.expectedFound, ok)

if tc.expectedFound {
require.Equal(t, metamorph_api.Status_SENT_TO_NETWORK, item.GetStatus())
}
})
}
}

func TestProcessorResponseMap_Clear(t *testing.T) {
Expand Down
14 changes: 0 additions & 14 deletions metamorph/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,6 @@ func TestLoadUnmined(t *testing.T) {
},
getTransactionBlockErr: errors.New("failed to get transaction block"),

expectedItemTxHashesFinal: []*chainhash.Hash{testdata.TX2Hash},
},
{
name: "delete expired - deletion fails",
storedData: []*store.StoreData{
{
StoredAt: storedAt.Add(-400 * time.Hour),
AnnouncedAt: storedAt.Add(1 * time.Second),
Hash: testdata.TX2Hash,
Status: metamorph_api.Status_SEEN_ON_NETWORK,
},
},
delErr: errors.New("failed to delete hash"),

expectedItemTxHashesFinal: []*chainhash.Hash{testdata.TX2Hash},
},
}
Expand Down

0 comments on commit 0ec9a61

Please sign in to comment.