mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
fix: fix drop logic to remove alternates map
This commit is contained in:
parent
5c535074ac
commit
242f3f9334
2 changed files with 57 additions and 0 deletions
|
|
@ -816,6 +816,10 @@ func (f *TxFetcher) loop() {
|
||||||
if len(f.announced[hash]) == 0 {
|
if len(f.announced[hash]) == 0 {
|
||||||
delete(f.announced, hash)
|
delete(f.announced, hash)
|
||||||
}
|
}
|
||||||
|
delete(f.alternates[hash], drop.peer)
|
||||||
|
if len(f.alternates[hash]) == 0 {
|
||||||
|
delete(f.alternates, hash)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
delete(f.announces, drop.peer)
|
delete(f.announces, drop.peer)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1858,6 +1858,59 @@ func TestBlobTransactionAnnounce(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTransactionFetcherDropAlternates(t *testing.T) {
|
||||||
|
testTransactionFetcherParallel(t, txFetcherTest{
|
||||||
|
init: func() *TxFetcher {
|
||||||
|
return NewTxFetcher(
|
||||||
|
func(common.Hash) bool { return false },
|
||||||
|
func(txs []*types.Transaction) []error {
|
||||||
|
return make([]error, len(txs))
|
||||||
|
},
|
||||||
|
func(string, []common.Hash) error { return nil },
|
||||||
|
nil,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
steps: []interface{}{
|
||||||
|
doTxNotify{peer: "A", hashes: []common.Hash{testTxsHashes[0]}, types: []byte{testTxs[0].Type()}, sizes: []uint32{uint32(testTxs[0].Size())}},
|
||||||
|
doWait{time: txArriveTimeout, step: true},
|
||||||
|
doTxNotify{peer: "B", hashes: []common.Hash{testTxsHashes[0]}, types: []byte{testTxs[0].Type()}, sizes: []uint32{uint32(testTxs[0].Size())}},
|
||||||
|
|
||||||
|
// Step 3
|
||||||
|
isScheduled{
|
||||||
|
tracking: map[string][]announce{
|
||||||
|
"A": {
|
||||||
|
{testTxsHashes[0], testTxs[0].Type(), uint32(testTxs[0].Size())},
|
||||||
|
},
|
||||||
|
"B": {
|
||||||
|
{testTxsHashes[0], testTxs[0].Type(), uint32(testTxs[0].Size())},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fetching: map[string][]common.Hash{
|
||||||
|
"A": {testTxsHashes[0]},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
doDrop("B"),
|
||||||
|
|
||||||
|
// Step 5
|
||||||
|
isScheduled{
|
||||||
|
tracking: map[string][]announce{
|
||||||
|
"A": {
|
||||||
|
{testTxsHashes[0], testTxs[0].Type(), uint32(testTxs[0].Size())},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fetching: map[string][]common.Hash{
|
||||||
|
"A": {testTxsHashes[0]},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
doDrop("A"),
|
||||||
|
// Step 7
|
||||||
|
isScheduled{
|
||||||
|
tracking: nil, fetching: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testTransactionFetcherParallel(t *testing.T, tt txFetcherTest) {
|
func testTransactionFetcherParallel(t *testing.T, tt txFetcherTest) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
testTransactionFetcher(t, tt)
|
testTransactionFetcher(t, tt)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue