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
055528ae
Unverified
Commit
055528ae
authored
Nov 07, 2022
by
Marius van der Wijden
Committed by
GitHub
Nov 07, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/devp2p/internal/ethtest: add support for eth/68 (#26078)
Co-authored-by:
Felix Lange
<
fjl@twurst.com
>
parent
9027ee0b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
15 deletions
+73
-15
helpers.go
cmd/devp2p/internal/ethtest/helpers.go
+4
-1
suite.go
cmd/devp2p/internal/ethtest/suite.go
+17
-8
transaction.go
cmd/devp2p/internal/ethtest/transaction.go
+38
-3
types.go
cmd/devp2p/internal/ethtest/types.go
+14
-3
No files found.
cmd/devp2p/internal/ethtest/helpers.go
View file @
055528ae
...
...
@@ -63,8 +63,9 @@ func (s *Suite) dial() (*Conn, error) {
conn
.
caps
=
[]
p2p
.
Cap
{
{
Name
:
"eth"
,
Version
:
66
},
{
Name
:
"eth"
,
Version
:
67
},
{
Name
:
"eth"
,
Version
:
68
},
}
conn
.
ourHighestProtoVersion
=
6
7
conn
.
ourHighestProtoVersion
=
6
8
return
&
conn
,
nil
}
...
...
@@ -359,6 +360,8 @@ func (s *Suite) waitAnnounce(conn *Conn, blockAnnouncement *NewBlock) error {
return
nil
// ignore tx announcements from previous tests
case
*
NewPooledTransactionHashes66
:
continue
case
*
NewPooledTransactionHashes
:
continue
case
*
Transactions
:
...
...
cmd/devp2p/internal/ethtest/suite.go
View file @
055528ae
...
...
@@ -510,17 +510,18 @@ func (s *Suite) TestNewPooledTxs(t *utesting.T) {
}
// generate 50 txs
hashMap
,
_
,
err
:=
generateTxs
(
s
,
50
)
_
,
txs
,
err
:=
generateTxs
(
s
,
50
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to generate transactions: %v"
,
err
)
}
// create new pooled tx hashes announcement
hashes
:=
make
([]
common
.
Hash
,
0
)
for
_
,
hash
:=
range
hashMap
{
hashes
=
append
(
hashes
,
hash
)
hashes
:=
make
([]
common
.
Hash
,
len
(
txs
))
types
:=
make
([]
byte
,
len
(
txs
))
sizes
:=
make
([]
uint32
,
len
(
txs
))
for
i
,
tx
:=
range
txs
{
hashes
[
i
]
=
tx
.
Hash
()
types
[
i
]
=
tx
.
Type
()
sizes
[
i
]
=
uint32
(
tx
.
Size
())
}
announce
:=
NewPooledTransactionHashes
(
hashes
)
// send announcement
conn
,
err
:=
s
.
dial
()
...
...
@@ -531,7 +532,13 @@ func (s *Suite) TestNewPooledTxs(t *utesting.T) {
if
err
=
conn
.
peer
(
s
.
chain
,
nil
);
err
!=
nil
{
t
.
Fatalf
(
"peering failed: %v"
,
err
)
}
if
err
=
conn
.
Write
(
announce
);
err
!=
nil
{
var
ann
Message
=
NewPooledTransactionHashes
{
Types
:
types
,
Sizes
:
sizes
,
Hashes
:
hashes
}
if
conn
.
negotiatedProtoVersion
<
eth
.
ETH68
{
ann
=
NewPooledTransactionHashes66
(
hashes
)
}
err
=
conn
.
Write
(
ann
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to write to connection: %v"
,
err
)
}
...
...
@@ -546,6 +553,8 @@ func (s *Suite) TestNewPooledTxs(t *utesting.T) {
return
// ignore propagated txs from previous tests
case
*
NewPooledTransactionHashes66
:
continue
case
*
NewPooledTransactionHashes
:
continue
case
*
Transactions
:
...
...
cmd/devp2p/internal/ethtest/transaction.go
View file @
055528ae
...
...
@@ -95,7 +95,7 @@ func sendSuccessfulTx(s *Suite, tx *types.Transaction, prevTx *types.Transaction
}
}
return
fmt
.
Errorf
(
"missing transaction: got %v missing %v"
,
recTxs
,
tx
.
Hash
())
case
*
NewPooledTransactionHashes
:
case
*
NewPooledTransactionHashes
66
:
txHashes
:=
*
msg
// if you receive an old tx propagation, read from connection again
if
len
(
txHashes
)
==
1
&&
prevTx
!=
nil
{
...
...
@@ -110,6 +110,34 @@ func sendSuccessfulTx(s *Suite, tx *types.Transaction, prevTx *types.Transaction
}
}
return
fmt
.
Errorf
(
"missing transaction announcement: got %v missing %v"
,
txHashes
,
tx
.
Hash
())
case
*
NewPooledTransactionHashes
:
txHashes
:=
msg
.
Hashes
if
len
(
txHashes
)
!=
len
(
msg
.
Sizes
)
{
return
fmt
.
Errorf
(
"invalid msg size lengths: hashes: %v sizes: %v"
,
len
(
txHashes
),
len
(
msg
.
Sizes
))
}
if
len
(
txHashes
)
!=
len
(
msg
.
Types
)
{
return
fmt
.
Errorf
(
"invalid msg type lengths: hashes: %v types: %v"
,
len
(
txHashes
),
len
(
msg
.
Types
))
}
// if you receive an old tx propagation, read from connection again
if
len
(
txHashes
)
==
1
&&
prevTx
!=
nil
{
if
txHashes
[
0
]
==
prevTx
.
Hash
()
{
continue
}
}
for
index
,
gotHash
:=
range
txHashes
{
if
gotHash
==
tx
.
Hash
()
{
if
msg
.
Sizes
[
index
]
!=
uint32
(
tx
.
Size
())
{
return
fmt
.
Errorf
(
"invalid tx size: got %v want %v"
,
msg
.
Sizes
[
index
],
tx
.
Size
())
}
if
msg
.
Types
[
index
]
!=
tx
.
Type
()
{
return
fmt
.
Errorf
(
"invalid tx type: got %v want %v"
,
msg
.
Types
[
index
],
tx
.
Type
())
}
// Ok
return
nil
}
}
return
fmt
.
Errorf
(
"missing transaction announcement: got %v missing %v"
,
txHashes
,
tx
.
Hash
())
default
:
return
fmt
.
Errorf
(
"unexpected message in sendSuccessfulTx: %s"
,
pretty
.
Sdump
(
msg
))
}
...
...
@@ -201,8 +229,10 @@ func sendMultipleSuccessfulTxs(t *utesting.T, s *Suite, txs []*types.Transaction
for
_
,
tx
:=
range
*
msg
{
recvHashes
=
append
(
recvHashes
,
tx
.
Hash
())
}
case
*
NewPooledTransactionHashes
:
case
*
NewPooledTransactionHashes
66
:
recvHashes
=
append
(
recvHashes
,
*
msg
...
)
case
*
NewPooledTransactionHashes
:
recvHashes
=
append
(
recvHashes
,
msg
.
Hashes
...
)
default
:
if
!
strings
.
Contains
(
pretty
.
Sdump
(
msg
),
"i/o timeout"
)
{
return
fmt
.
Errorf
(
"unexpected message while waiting to receive txs: %s"
,
pretty
.
Sdump
(
msg
))
...
...
@@ -246,11 +276,16 @@ func checkMaliciousTxPropagation(s *Suite, txs []*types.Transaction, conn *Conn)
if
len
(
badTxs
)
>
0
{
return
fmt
.
Errorf
(
"received %d bad txs:
\n
%v"
,
len
(
badTxs
),
badTxs
)
}
case
*
NewPooledTransactionHashes
:
case
*
NewPooledTransactionHashes
66
:
badTxs
,
_
:=
compareReceivedTxs
(
*
msg
,
txs
)
if
len
(
badTxs
)
>
0
{
return
fmt
.
Errorf
(
"received %d bad txs:
\n
%v"
,
len
(
badTxs
),
badTxs
)
}
case
*
NewPooledTransactionHashes
:
badTxs
,
_
:=
compareReceivedTxs
(
msg
.
Hashes
,
txs
)
if
len
(
badTxs
)
>
0
{
return
fmt
.
Errorf
(
"received %d bad txs:
\n
%v"
,
len
(
badTxs
),
badTxs
)
}
case
*
Error
:
// Transaction should not be announced -> wait for timeout
return
nil
...
...
cmd/devp2p/internal/ethtest/types.go
View file @
055528ae
...
...
@@ -126,8 +126,14 @@ type NewBlock eth.NewBlockPacket
func
(
msg
NewBlock
)
Code
()
int
{
return
23
}
func
(
msg
NewBlock
)
ReqID
()
uint64
{
return
0
}
// NewPooledTransactionHashes66 is the network packet for the tx hash propagation message.
type
NewPooledTransactionHashes66
eth
.
NewPooledTransactionHashesPacket66
func
(
msg
NewPooledTransactionHashes66
)
Code
()
int
{
return
24
}
func
(
msg
NewPooledTransactionHashes66
)
ReqID
()
uint64
{
return
0
}
// NewPooledTransactionHashes is the network packet for the tx hash propagation message.
type
NewPooledTransactionHashes
eth
.
NewPooledTransactionHashesPacket6
6
type
NewPooledTransactionHashes
eth
.
NewPooledTransactionHashesPacket6
8
func
(
msg
NewPooledTransactionHashes
)
Code
()
int
{
return
24
}
func
(
msg
NewPooledTransactionHashes
)
ReqID
()
uint64
{
return
0
}
...
...
@@ -202,8 +208,13 @@ func (c *Conn) Read() Message {
msg
=
new
(
NewBlockHashes
)
case
(
Transactions
{})
.
Code
()
:
msg
=
new
(
Transactions
)
case
(
NewPooledTransactionHashes
{})
.
Code
()
:
msg
=
new
(
NewPooledTransactionHashes
)
case
(
NewPooledTransactionHashes66
{})
.
Code
()
:
// Try decoding to eth68
ethMsg
:=
new
(
NewPooledTransactionHashes
)
if
err
:=
rlp
.
DecodeBytes
(
rawData
,
ethMsg
);
err
==
nil
{
return
ethMsg
}
msg
=
new
(
NewPooledTransactionHashes66
)
case
(
GetPooledTransactions
{}
.
Code
())
:
ethMsg
:=
new
(
eth
.
GetPooledTransactionsPacket66
)
if
err
:=
rlp
.
DecodeBytes
(
rawData
,
ethMsg
);
err
!=
nil
{
...
...
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