Skip to content

Commit eddcecc

Browse files
authored
Merge pull request #20234 from rjl493456442/newtxhashes_2
core, eth: announce based transaction propagation
2 parents 90caa2c + 9938d95 commit eddcecc

File tree

133 files changed

+3522
-393
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+3522
-393
lines changed

core/tx_pool.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package core
1818

1919
import (
2020
"errors"
21-
"fmt"
2221
"math"
2322
"math/big"
2423
"sort"
@@ -53,6 +52,10 @@ const (
5352
)
5453

5554
var (
55+
// ErrAlreadyKnown is returned if the transactions is already contained
56+
// within the pool.
57+
ErrAlreadyKnown = errors.New("already known")
58+
5659
// ErrInvalidSender is returned if the transaction contains an invalid signature.
5760
ErrInvalidSender = errors.New("invalid sender")
5861

@@ -579,7 +582,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
579582
if pool.all.Get(hash) != nil {
580583
log.Trace("Discarding already known transaction", "hash", hash)
581584
knownTxMeter.Mark(1)
582-
return false, fmt.Errorf("known transaction: %x", hash)
585+
return false, ErrAlreadyKnown
583586
}
584587
// If the transaction fails basic validation, discard it
585588
if err := pool.validateTx(tx, local); err != nil {
@@ -786,7 +789,7 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error {
786789
for i, tx := range txs {
787790
// If the transaction is known, pre-set the error slot
788791
if pool.all.Get(tx.Hash()) != nil {
789-
errs[i] = fmt.Errorf("known transaction: %x", tx.Hash())
792+
errs[i] = ErrAlreadyKnown
790793
knownTxMeter.Mark(1)
791794
continue
792795
}
@@ -864,6 +867,12 @@ func (pool *TxPool) Get(hash common.Hash) *types.Transaction {
864867
return pool.all.Get(hash)
865868
}
866869

870+
// Has returns an indicator whether txpool has a transaction cached with the
871+
// given hash.
872+
func (pool *TxPool) Has(hash common.Hash) bool {
873+
return pool.all.Get(hash) != nil
874+
}
875+
867876
// removeTx removes a single transaction from the queue, moving all subsequent
868877
// transactions back to the future queue.
869878
func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {

eth/downloader/peer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ func (ps *peerSet) HeaderIdlePeers() ([]*peerConnection, int) {
470470
defer p.lock.RUnlock()
471471
return p.headerThroughput
472472
}
473-
return ps.idlePeers(62, 64, idle, throughput)
473+
return ps.idlePeers(62, 65, idle, throughput)
474474
}
475475

476476
// BodyIdlePeers retrieves a flat list of all the currently body-idle peers within
@@ -484,7 +484,7 @@ func (ps *peerSet) BodyIdlePeers() ([]*peerConnection, int) {
484484
defer p.lock.RUnlock()
485485
return p.blockThroughput
486486
}
487-
return ps.idlePeers(62, 64, idle, throughput)
487+
return ps.idlePeers(62, 65, idle, throughput)
488488
}
489489

490490
// ReceiptIdlePeers retrieves a flat list of all the currently receipt-idle peers
@@ -498,7 +498,7 @@ func (ps *peerSet) ReceiptIdlePeers() ([]*peerConnection, int) {
498498
defer p.lock.RUnlock()
499499
return p.receiptThroughput
500500
}
501-
return ps.idlePeers(63, 64, idle, throughput)
501+
return ps.idlePeers(63, 65, idle, throughput)
502502
}
503503

504504
// NodeDataIdlePeers retrieves a flat list of all the currently node-data-idle
@@ -512,7 +512,7 @@ func (ps *peerSet) NodeDataIdlePeers() ([]*peerConnection, int) {
512512
defer p.lock.RUnlock()
513513
return p.stateThroughput
514514
}
515-
return ps.idlePeers(63, 64, idle, throughput)
515+
return ps.idlePeers(63, 65, idle, throughput)
516516
}
517517

518518
// idlePeers retrieves a flat list of all currently idle peers satisfying the

0 commit comments

Comments
 (0)