Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

les: remove transaction propagation limits #22125

Merged
merged 1 commit into from
Jan 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 8 additions & 22 deletions les/txrelay.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)

type ltrInfo struct {
tx *types.Transaction
sentTo map[*serverPeer]struct{}
}

type lesTxRelay struct {
txSent map[common.Hash]*ltrInfo
txSent map[common.Hash]*types.Transaction
txPending map[common.Hash]struct{}
peerList []*serverPeer
peerStartPos int
Expand All @@ -43,7 +38,7 @@ type lesTxRelay struct {

func newLesTxRelay(ps *serverPeerSet, retriever *retrieveManager) *lesTxRelay {
r := &lesTxRelay{
txSent: make(map[common.Hash]*ltrInfo),
txSent: make(map[common.Hash]*types.Transaction),
txPending: make(map[common.Hash]struct{}),
retriever: retriever,
stop: make(chan struct{}),
Expand Down Expand Up @@ -80,8 +75,7 @@ func (ltrx *lesTxRelay) unregisterPeer(p *serverPeer) {
}
}

// send sends a list of transactions to at most a given number of peers at
// once, never resending any particular transaction to the same peer twice
// send sends a list of transactions to at most a given number of peers.
func (ltrx *lesTxRelay) send(txs types.Transactions, count int) {
sendTo := make(map[*serverPeer]types.Transactions)

Expand All @@ -92,26 +86,18 @@ func (ltrx *lesTxRelay) send(txs types.Transactions, count int) {

for _, tx := range txs {
hash := tx.Hash()
ltr, ok := ltrx.txSent[hash]
_, ok := ltrx.txSent[hash]
if !ok {
ltr = &ltrInfo{
tx: tx,
sentTo: make(map[*serverPeer]struct{}),
}
ltrx.txSent[hash] = ltr
ltrx.txSent[hash] = tx
ltrx.txPending[hash] = struct{}{}
}

if len(ltrx.peerList) > 0 {
cnt := count
pos := ltrx.peerStartPos
for {
peer := ltrx.peerList[pos]
if _, ok := ltr.sentTo[peer]; !ok {
sendTo[peer] = append(sendTo[peer], tx)
ltr.sentTo[peer] = struct{}{}
cnt--
}
sendTo[peer] = append(sendTo[peer], tx)
cnt--
if cnt == 0 {
break // sent it to the desired number of peers
}
Expand Down Expand Up @@ -174,7 +160,7 @@ func (ltrx *lesTxRelay) NewHead(head common.Hash, mined []common.Hash, rollback
txs := make(types.Transactions, len(ltrx.txPending))
i := 0
for hash := range ltrx.txPending {
txs[i] = ltrx.txSent[hash].tx
txs[i] = ltrx.txSent[hash]
i++
}
ltrx.send(txs, 1)
Expand Down