Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
7f2890a9
Unverified
Commit
7f2890a9
authored
Sep 02, 2022
by
Martin Holst Swende
Committed by
GitHub
Sep 02, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/fetcher: throttle peers which deliver many invalid transactions (#25573)
Co-authored-by:
Felix Lange
<
fjl@twurst.com
>
parent
d6a12bc7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
42 deletions
+68
-42
helpers.go
cmd/devp2p/internal/ethtest/helpers.go
+5
-1
suite.go
cmd/devp2p/internal/ethtest/suite.go
+4
-0
transaction.go
cmd/devp2p/internal/ethtest/transaction.go
+3
-3
tx_fetcher.go
eth/fetcher/tx_fetcher.go
+56
-38
No files found.
cmd/devp2p/internal/ethtest/helpers.go
View file @
7f2890a9
...
...
@@ -357,9 +357,13 @@ 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
nil
case
*
NewPooledTransactionHashes
:
// ignore tx announcements from previous tests
case
*
NewPooledTransactionHashes
:
continue
case
*
Transactions
:
continue
default
:
return
fmt
.
Errorf
(
"unexpected: %s"
,
pretty
.
Sdump
(
msg
))
}
...
...
cmd/devp2p/internal/ethtest/suite.go
View file @
7f2890a9
...
...
@@ -544,9 +544,13 @@ func (s *Suite) TestNewPooledTxs(t *utesting.T) {
t
.
Fatalf
(
"unexpected number of txs requested: wanted %d, got %d"
,
len
(
hashes
),
len
(
msg
.
GetPooledTransactionsPacket
))
}
return
// ignore propagated txs from previous tests
case
*
NewPooledTransactionHashes
:
continue
case
*
Transactions
:
continue
// ignore block announcements from previous tests
case
*
NewBlockHashes
:
continue
...
...
cmd/devp2p/internal/ethtest/transaction.go
View file @
7f2890a9
...
...
@@ -29,7 +29,7 @@ import (
"github.com/ethereum/go-ethereum/params"
)
//var faucetAddr = common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7")
//
var faucetAddr = common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7")
var
faucetKey
,
_
=
crypto
.
HexToECDSA
(
"b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291"
)
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
()
// Wait for the transaction announcement(s) and make sure all sent txs are being propagated.
// all txs should be announced within
3
announcements.
// all txs should be announced within
a couple
announcements.
recvHashes
:=
make
([]
common
.
Hash
,
0
)
for
i
:=
0
;
i
<
3
;
i
++
{
for
i
:=
0
;
i
<
20
;
i
++
{
switch
msg
:=
recvConn
.
readAndServe
(
s
.
chain
,
timeout
)
.
(
type
)
{
case
*
Transactions
:
for
_
,
tx
:=
range
*
msg
{
...
...
eth/fetcher/tx_fetcher.go
View file @
7f2890a9
...
...
@@ -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
// re-schedule missing transactions as soon as possible.
func
(
f
*
TxFetcher
)
Enqueue
(
peer
string
,
txs
[]
*
types
.
Transaction
,
direct
bool
)
error
{
// Keep track of all the propagated transactions
if
direct
{
txReplyInMeter
.
Mark
(
int64
(
len
(
txs
)))
}
else
{
txBroadcastInMeter
.
Mark
(
int64
(
len
(
txs
)))
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
inMeter
.
Mark
(
int64
(
len
(
txs
)))
// Push all the transactions into the pool, tracking underpriced ones to avoid
// re-requesting them and dropping the peer in case of malicious transfers.
var
(
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
underpriced
int64
otherreject
int64
)
errs
:=
f
.
addTxs
(
txs
)
for
i
,
err
:=
range
errs
{
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.
...
...
@@ -285,7 +302,7 @@ func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool)
for
f
.
underpriced
.
Cardinality
()
>=
maxTxUnderpricedSetSize
{
f
.
underpriced
.
Pop
()
}
f
.
underpriced
.
Add
(
txs
[
i
]
.
Hash
())
f
.
underpriced
.
Add
(
batch
[
j
]
.
Hash
())
}
// Track a few interesting failure types
switch
{
...
...
@@ -300,16 +317,17 @@ func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool)
default
:
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
{
case
f
.
cleanup
<-
&
txDelivery
{
origin
:
peer
,
hashes
:
added
,
direct
:
direct
}
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment