forked from cerc-io/plugeth
les: remove transaction propagation limits (#22125)
This commit is contained in:
parent
d3952898c3
commit
165f53fc6e
@ -25,13 +25,8 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ltrInfo struct {
|
|
||||||
tx *types.Transaction
|
|
||||||
sentTo map[*serverPeer]struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type lesTxRelay struct {
|
type lesTxRelay struct {
|
||||||
txSent map[common.Hash]*ltrInfo
|
txSent map[common.Hash]*types.Transaction
|
||||||
txPending map[common.Hash]struct{}
|
txPending map[common.Hash]struct{}
|
||||||
peerList []*serverPeer
|
peerList []*serverPeer
|
||||||
peerStartPos int
|
peerStartPos int
|
||||||
@ -43,7 +38,7 @@ type lesTxRelay struct {
|
|||||||
|
|
||||||
func newLesTxRelay(ps *serverPeerSet, retriever *retrieveManager) *lesTxRelay {
|
func newLesTxRelay(ps *serverPeerSet, retriever *retrieveManager) *lesTxRelay {
|
||||||
r := &lesTxRelay{
|
r := &lesTxRelay{
|
||||||
txSent: make(map[common.Hash]*ltrInfo),
|
txSent: make(map[common.Hash]*types.Transaction),
|
||||||
txPending: make(map[common.Hash]struct{}),
|
txPending: make(map[common.Hash]struct{}),
|
||||||
retriever: retriever,
|
retriever: retriever,
|
||||||
stop: make(chan struct{}),
|
stop: make(chan struct{}),
|
||||||
@ -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
|
// send sends a list of transactions to at most a given number of peers.
|
||||||
// once, never resending any particular transaction to the same peer twice
|
|
||||||
func (ltrx *lesTxRelay) send(txs types.Transactions, count int) {
|
func (ltrx *lesTxRelay) send(txs types.Transactions, count int) {
|
||||||
sendTo := make(map[*serverPeer]types.Transactions)
|
sendTo := make(map[*serverPeer]types.Transactions)
|
||||||
|
|
||||||
@ -92,26 +86,18 @@ func (ltrx *lesTxRelay) send(txs types.Transactions, count int) {
|
|||||||
|
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
hash := tx.Hash()
|
hash := tx.Hash()
|
||||||
ltr, ok := ltrx.txSent[hash]
|
_, ok := ltrx.txSent[hash]
|
||||||
if !ok {
|
if !ok {
|
||||||
ltr = <rInfo{
|
ltrx.txSent[hash] = tx
|
||||||
tx: tx,
|
|
||||||
sentTo: make(map[*serverPeer]struct{}),
|
|
||||||
}
|
|
||||||
ltrx.txSent[hash] = ltr
|
|
||||||
ltrx.txPending[hash] = struct{}{}
|
ltrx.txPending[hash] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ltrx.peerList) > 0 {
|
if len(ltrx.peerList) > 0 {
|
||||||
cnt := count
|
cnt := count
|
||||||
pos := ltrx.peerStartPos
|
pos := ltrx.peerStartPos
|
||||||
for {
|
for {
|
||||||
peer := ltrx.peerList[pos]
|
peer := ltrx.peerList[pos]
|
||||||
if _, ok := ltr.sentTo[peer]; !ok {
|
|
||||||
sendTo[peer] = append(sendTo[peer], tx)
|
sendTo[peer] = append(sendTo[peer], tx)
|
||||||
ltr.sentTo[peer] = struct{}{}
|
|
||||||
cnt--
|
cnt--
|
||||||
}
|
|
||||||
if cnt == 0 {
|
if cnt == 0 {
|
||||||
break // sent it to the desired number of peers
|
break // sent it to the desired number of peers
|
||||||
}
|
}
|
||||||
@ -174,7 +160,7 @@ func (ltrx *lesTxRelay) NewHead(head common.Hash, mined []common.Hash, rollback
|
|||||||
txs := make(types.Transactions, len(ltrx.txPending))
|
txs := make(types.Transactions, len(ltrx.txPending))
|
||||||
i := 0
|
i := 0
|
||||||
for hash := range ltrx.txPending {
|
for hash := range ltrx.txPending {
|
||||||
txs[i] = ltrx.txSent[hash].tx
|
txs[i] = ltrx.txSent[hash]
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
ltrx.send(txs, 1)
|
ltrx.send(txs, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user