|
|
@ -262,22 +262,39 @@ func (f *TxFetcher) Notify(peer string, hashes []common.Hash) error { |
|
|
|
// direct request replies. The differentiation is important so the fetcher can
|
|
|
|
// direct request replies. The differentiation is important so the fetcher can
|
|
|
|
// re-schedule missing transactions as soon as possible.
|
|
|
|
// re-schedule missing transactions as soon as possible.
|
|
|
|
func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool) error { |
|
|
|
func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool) error { |
|
|
|
// Keep track of all the propagated transactions
|
|
|
|
var ( |
|
|
|
if direct { |
|
|
|
inMeter = txReplyInMeter |
|
|
|
txReplyInMeter.Mark(int64(len(txs))) |
|
|
|
knownMeter = txReplyKnownMeter |
|
|
|
} else { |
|
|
|
underpricedMeter = txReplyUnderpricedMeter |
|
|
|
txBroadcastInMeter.Mark(int64(len(txs))) |
|
|
|
otherRejectMeter = txReplyOtherRejectMeter |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
if !direct { |
|
|
|
|
|
|
|
inMeter = txBroadcastInMeter |
|
|
|
|
|
|
|
knownMeter = txBroadcastKnownMeter |
|
|
|
|
|
|
|
underpricedMeter = txBroadcastUnderpricedMeter |
|
|
|
|
|
|
|
otherRejectMeter = txBroadcastOtherRejectMeter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Keep track of all the propagated transactions
|
|
|
|
|
|
|
|
inMeter.Mark(int64(len(txs))) |
|
|
|
|
|
|
|
|
|
|
|
// Push all the transactions into the pool, tracking underpriced ones to avoid
|
|
|
|
// Push all the transactions into the pool, tracking underpriced ones to avoid
|
|
|
|
// re-requesting them and dropping the peer in case of malicious transfers.
|
|
|
|
// re-requesting them and dropping the peer in case of malicious transfers.
|
|
|
|
var ( |
|
|
|
var ( |
|
|
|
added = make([]common.Hash, 0, len(txs)) |
|
|
|
added = make([]common.Hash, 0, len(txs)) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
// proceed in batches
|
|
|
|
|
|
|
|
for i := 0; i < len(txs); i += 128 { |
|
|
|
|
|
|
|
end := i + 128 |
|
|
|
|
|
|
|
if end > len(txs) { |
|
|
|
|
|
|
|
end = len(txs) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var ( |
|
|
|
duplicate int64 |
|
|
|
duplicate int64 |
|
|
|
underpriced int64 |
|
|
|
underpriced int64 |
|
|
|
otherreject int64 |
|
|
|
otherreject int64 |
|
|
|
) |
|
|
|
) |
|
|
|
errs := f.addTxs(txs) |
|
|
|
batch := txs[i:end] |
|
|
|
for i, err := range errs { |
|
|
|
for j, err := range f.addTxs(batch) { |
|
|
|
// Track the transaction hash if the price is too low for us.
|
|
|
|
// Track the transaction hash if the price is too low for us.
|
|
|
|
// Avoid re-request this transaction when we receive another
|
|
|
|
// Avoid re-request this transaction when we receive another
|
|
|
|
// announcement.
|
|
|
|
// announcement.
|
|
|
@ -285,7 +302,7 @@ func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool) |
|
|
|
for f.underpriced.Cardinality() >= maxTxUnderpricedSetSize { |
|
|
|
for f.underpriced.Cardinality() >= maxTxUnderpricedSetSize { |
|
|
|
f.underpriced.Pop() |
|
|
|
f.underpriced.Pop() |
|
|
|
} |
|
|
|
} |
|
|
|
f.underpriced.Add(txs[i].Hash()) |
|
|
|
f.underpriced.Add(batch[j].Hash()) |
|
|
|
} |
|
|
|
} |
|
|
|
// Track a few interesting failure types
|
|
|
|
// Track a few interesting failure types
|
|
|
|
switch { |
|
|
|
switch { |
|
|
@ -300,16 +317,17 @@ func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool) |
|
|
|
default: |
|
|
|
default: |
|
|
|
otherreject++ |
|
|
|
otherreject++ |
|
|
|
} |
|
|
|
} |
|
|
|
added = append(added, txs[i].Hash()) |
|
|
|
added = append(added, batch[j].Hash()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
knownMeter.Mark(duplicate) |
|
|
|
|
|
|
|
underpricedMeter.Mark(underpriced) |
|
|
|
|
|
|
|
otherRejectMeter.Mark(otherreject) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If 'other reject' is >25% of the deliveries in any batch, sleep a bit.
|
|
|
|
|
|
|
|
if otherreject > 128/4 { |
|
|
|
|
|
|
|
time.Sleep(200 * time.Millisecond) |
|
|
|
|
|
|
|
log.Warn("Peer delivering stale transactions", "peer", peer, "rejected", otherreject) |
|
|
|
} |
|
|
|
} |
|
|
|
if direct { |
|
|
|
|
|
|
|
txReplyKnownMeter.Mark(duplicate) |
|
|
|
|
|
|
|
txReplyUnderpricedMeter.Mark(underpriced) |
|
|
|
|
|
|
|
txReplyOtherRejectMeter.Mark(otherreject) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
txBroadcastKnownMeter.Mark(duplicate) |
|
|
|
|
|
|
|
txBroadcastUnderpricedMeter.Mark(underpriced) |
|
|
|
|
|
|
|
txBroadcastOtherRejectMeter.Mark(otherreject) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
select { |
|
|
|
select { |
|
|
|
case f.cleanup <- &txDelivery{origin: peer, hashes: added, direct: direct}: |
|
|
|
case f.cleanup <- &txDelivery{origin: peer, hashes: added, direct: direct}: |
|
|
|