forked from cerc-io/plugeth
Revert "eth/fetcher: don't spend too much time on transaction inclusion" (#25567)
Revert "eth/fetcher: don't spend too much time on transaction inclusion (#25524)"
This reverts commit 0ce494b60c
.
This commit is contained in:
parent
0ce494b60c
commit
02418c2fa9
@ -357,13 +357,9 @@ func (s *Suite) waitAnnounce(conn *Conn, blockAnnouncement *NewBlock) error {
|
|||||||
return fmt.Errorf("wrong block hash in announcement: expected %v, got %v", blockAnnouncement.Block.Hash(), hashes[0].Hash)
|
return fmt.Errorf("wrong block hash in announcement: expected %v, got %v", blockAnnouncement.Block.Hash(), hashes[0].Hash)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
// ignore tx announcements from previous tests
|
|
||||||
case *NewPooledTransactionHashes:
|
case *NewPooledTransactionHashes:
|
||||||
|
// ignore tx announcements from previous tests
|
||||||
continue
|
continue
|
||||||
case *Transactions:
|
|
||||||
continue
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unexpected: %s", pretty.Sdump(msg))
|
return fmt.Errorf("unexpected: %s", pretty.Sdump(msg))
|
||||||
}
|
}
|
||||||
|
@ -544,13 +544,9 @@ func (s *Suite) TestNewPooledTxs(t *utesting.T) {
|
|||||||
t.Fatalf("unexpected number of txs requested: wanted %d, got %d", len(hashes), len(msg.GetPooledTransactionsPacket))
|
t.Fatalf("unexpected number of txs requested: wanted %d, got %d", len(hashes), len(msg.GetPooledTransactionsPacket))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
||||||
// ignore propagated txs from previous tests
|
// ignore propagated txs from previous tests
|
||||||
case *NewPooledTransactionHashes:
|
case *NewPooledTransactionHashes:
|
||||||
continue
|
continue
|
||||||
case *Transactions:
|
|
||||||
continue
|
|
||||||
|
|
||||||
// ignore block announcements from previous tests
|
// ignore block announcements from previous tests
|
||||||
case *NewBlockHashes:
|
case *NewBlockHashes:
|
||||||
continue
|
continue
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
// var faucetAddr = common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7")
|
//var faucetAddr = common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7")
|
||||||
var faucetKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
var faucetKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||||
|
|
||||||
func (s *Suite) sendSuccessfulTxs(t *utesting.T) error {
|
func (s *Suite) sendSuccessfulTxs(t *utesting.T) error {
|
||||||
@ -192,10 +192,10 @@ func sendMultipleSuccessfulTxs(t *utesting.T, s *Suite, txs []*types.Transaction
|
|||||||
nonce = txs[len(txs)-1].Nonce()
|
nonce = txs[len(txs)-1].Nonce()
|
||||||
|
|
||||||
// Wait for the transaction announcement(s) and make sure all sent txs are being propagated.
|
// Wait for the transaction announcement(s) and make sure all sent txs are being propagated.
|
||||||
// all txs should be announced within a couple announcements.
|
// all txs should be announced within 3 announcements.
|
||||||
recvHashes := make([]common.Hash, 0)
|
recvHashes := make([]common.Hash, 0)
|
||||||
|
|
||||||
for i := 0; i < 20; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
switch msg := recvConn.readAndServe(s.chain, timeout).(type) {
|
switch msg := recvConn.readAndServe(s.chain, timeout).(type) {
|
||||||
case *Transactions:
|
case *Transactions:
|
||||||
for _, tx := range *msg {
|
for _, tx := range *msg {
|
||||||
|
@ -262,79 +262,57 @@ 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 {
|
||||||
var (
|
|
||||||
inMeter = txReplyInMeter
|
|
||||||
knownMeter = txReplyKnownMeter
|
|
||||||
underpricedMeter = txReplyUnderpricedMeter
|
|
||||||
otherRejectMeter = txReplyOtherRejectMeter
|
|
||||||
)
|
|
||||||
if !direct {
|
|
||||||
inMeter = txBroadcastInMeter
|
|
||||||
knownMeter = txBroadcastKnownMeter
|
|
||||||
underpricedMeter = txBroadcastUnderpricedMeter
|
|
||||||
otherRejectMeter = txBroadcastOtherRejectMeter
|
|
||||||
}
|
|
||||||
// Keep track of all the propagated transactions
|
// Keep track of all the propagated transactions
|
||||||
inMeter.Mark(int64(len(txs)))
|
if direct {
|
||||||
|
txReplyInMeter.Mark(int64(len(txs)))
|
||||||
|
} else {
|
||||||
|
txBroadcastInMeter.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))
|
||||||
delay time.Duration
|
duplicate int64
|
||||||
|
underpriced int64
|
||||||
|
otherreject int64
|
||||||
)
|
)
|
||||||
// proceed in batches
|
errs := f.addTxs(txs)
|
||||||
for i := 0; i < len(txs); i += 128 {
|
for i, err := range errs {
|
||||||
end := i + 128
|
// Track the transaction hash if the price is too low for us.
|
||||||
if end > len(txs) {
|
// Avoid re-request this transaction when we receive another
|
||||||
end = len(txs)
|
// announcement.
|
||||||
}
|
if errors.Is(err, core.ErrUnderpriced) || errors.Is(err, core.ErrReplaceUnderpriced) {
|
||||||
var (
|
for f.underpriced.Cardinality() >= maxTxUnderpricedSetSize {
|
||||||
duplicate int64
|
f.underpriced.Pop()
|
||||||
underpriced int64
|
|
||||||
otherreject int64
|
|
||||||
)
|
|
||||||
batch := txs[i:end]
|
|
||||||
for j, err := range f.addTxs(batch) {
|
|
||||||
// Track the transaction hash if the price is too low for us.
|
|
||||||
// Avoid re-request this transaction when we receive another
|
|
||||||
// announcement.
|
|
||||||
if errors.Is(err, core.ErrUnderpriced) || errors.Is(err, core.ErrReplaceUnderpriced) {
|
|
||||||
for f.underpriced.Cardinality() >= maxTxUnderpricedSetSize {
|
|
||||||
f.underpriced.Pop()
|
|
||||||
}
|
|
||||||
f.underpriced.Add(batch[j].Hash())
|
|
||||||
}
|
}
|
||||||
// Track a few interesting failure types
|
f.underpriced.Add(txs[i].Hash())
|
||||||
switch {
|
|
||||||
case err == nil: // Noop, but need to handle to not count these
|
|
||||||
|
|
||||||
case errors.Is(err, core.ErrAlreadyKnown):
|
|
||||||
duplicate++
|
|
||||||
|
|
||||||
case errors.Is(err, core.ErrUnderpriced) || errors.Is(err, core.ErrReplaceUnderpriced):
|
|
||||||
underpriced++
|
|
||||||
|
|
||||||
default:
|
|
||||||
otherreject++
|
|
||||||
}
|
|
||||||
added = append(added, batch[j].Hash())
|
|
||||||
}
|
}
|
||||||
knownMeter.Mark(duplicate)
|
// Track a few interesting failure types
|
||||||
underpricedMeter.Mark(underpriced)
|
switch {
|
||||||
otherRejectMeter.Mark(otherreject)
|
case err == nil: // Noop, but need to handle to not count these
|
||||||
|
|
||||||
// If 'other reject' is >25% of the deliveries in any batch, abort. Either we are
|
case errors.Is(err, core.ErrAlreadyKnown):
|
||||||
// out of sync with the chain or the peer is griefing us.
|
duplicate++
|
||||||
if otherreject > 128/4 {
|
|
||||||
delay = 200 * time.Millisecond
|
case errors.Is(err, core.ErrUnderpriced) || errors.Is(err, core.ErrReplaceUnderpriced):
|
||||||
log.Warn("Peer delivering useless transactions", "peer", peer, "ignored", len(txs)-end)
|
underpriced++
|
||||||
break
|
|
||||||
|
default:
|
||||||
|
otherreject++
|
||||||
}
|
}
|
||||||
|
added = append(added, txs[i].Hash())
|
||||||
|
}
|
||||||
|
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}:
|
||||||
time.Sleep(delay)
|
|
||||||
return nil
|
return nil
|
||||||
case <-f.quit:
|
case <-f.quit:
|
||||||
return errTerminated
|
return errTerminated
|
||||||
|
Loading…
Reference in New Issue
Block a user