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
b80c840a
Commit
b80c840a
authored
Jul 22, 2019
by
gary rong
Committed by
Péter Szilágyi
Jul 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core, les: fix les unit tests (#19823)
parent
a32a2b93
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
12 deletions
+22
-12
tx_pool.go
core/tx_pool.go
+2
-2
tx_pool_test.go
core/tx_pool_test.go
+9
-9
handler.go
les/handler.go
+10
-1
handler_test.go
les/handler_test.go
+1
-0
transactions.rlp
les/transactions.rlp
+0
-0
No files found.
core/tx_pool.go
View file @
b80c840a
...
@@ -745,13 +745,13 @@ func (pool *TxPool) AddRemotes(txs []*types.Transaction) []error {
...
@@ -745,13 +745,13 @@ func (pool *TxPool) AddRemotes(txs []*types.Transaction) []error {
}
}
// This is like AddRemotes, but waits for pool reorganization. Tests use this method.
// This is like AddRemotes, but waits for pool reorganization. Tests use this method.
func
(
pool
*
TxPool
)
a
ddRemotesSync
(
txs
[]
*
types
.
Transaction
)
[]
error
{
func
(
pool
*
TxPool
)
A
ddRemotesSync
(
txs
[]
*
types
.
Transaction
)
[]
error
{
return
pool
.
addTxs
(
txs
,
false
,
true
)
return
pool
.
addTxs
(
txs
,
false
,
true
)
}
}
// This is like AddRemotes with a single transaction, but waits for pool reorganization. Tests use this method.
// This is like AddRemotes with a single transaction, but waits for pool reorganization. Tests use this method.
func
(
pool
*
TxPool
)
addRemoteSync
(
tx
*
types
.
Transaction
)
error
{
func
(
pool
*
TxPool
)
addRemoteSync
(
tx
*
types
.
Transaction
)
error
{
errs
:=
pool
.
a
ddRemotesSync
([]
*
types
.
Transaction
{
tx
})
errs
:=
pool
.
A
ddRemotesSync
([]
*
types
.
Transaction
{
tx
})
return
errs
[
0
]
return
errs
[
0
]
}
}
...
...
core/tx_pool_test.go
View file @
b80c840a
...
@@ -200,7 +200,7 @@ func TestStateChangeDuringTransactionPoolReset(t *testing.T) {
...
@@ -200,7 +200,7 @@ func TestStateChangeDuringTransactionPoolReset(t *testing.T) {
t
.
Fatalf
(
"Invalid nonce, want 0, got %d"
,
nonce
)
t
.
Fatalf
(
"Invalid nonce, want 0, got %d"
,
nonce
)
}
}
pool
.
a
ddRemotesSync
([]
*
types
.
Transaction
{
tx0
,
tx1
})
pool
.
A
ddRemotesSync
([]
*
types
.
Transaction
{
tx0
,
tx1
})
nonce
=
pool
.
Nonce
(
address
)
nonce
=
pool
.
Nonce
(
address
)
if
nonce
!=
2
{
if
nonce
!=
2
{
...
@@ -587,7 +587,7 @@ func TestTransactionPostponing(t *testing.T) {
...
@@ -587,7 +587,7 @@ func TestTransactionPostponing(t *testing.T) {
txs
=
append
(
txs
,
tx
)
txs
=
append
(
txs
,
tx
)
}
}
}
}
for
i
,
err
:=
range
pool
.
a
ddRemotesSync
(
txs
)
{
for
i
,
err
:=
range
pool
.
A
ddRemotesSync
(
txs
)
{
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"tx %d: failed to add transactions: %v"
,
i
,
err
)
t
.
Fatalf
(
"tx %d: failed to add transactions: %v"
,
i
,
err
)
}
}
...
@@ -683,7 +683,7 @@ func TestTransactionGapFilling(t *testing.T) {
...
@@ -683,7 +683,7 @@ func TestTransactionGapFilling(t *testing.T) {
defer
sub
.
Unsubscribe
()
defer
sub
.
Unsubscribe
()
// Create a pending and a queued transaction with a nonce-gap in between
// Create a pending and a queued transaction with a nonce-gap in between
pool
.
a
ddRemotesSync
([]
*
types
.
Transaction
{
pool
.
A
ddRemotesSync
([]
*
types
.
Transaction
{
transaction
(
0
,
100000
,
key
),
transaction
(
0
,
100000
,
key
),
transaction
(
2
,
100000
,
key
),
transaction
(
2
,
100000
,
key
),
})
})
...
@@ -800,7 +800,7 @@ func testTransactionQueueGlobalLimiting(t *testing.T, nolocals bool) {
...
@@ -800,7 +800,7 @@ func testTransactionQueueGlobalLimiting(t *testing.T, nolocals bool) {
nonces
[
addr
]
++
nonces
[
addr
]
++
}
}
// Import the batch and verify that limits have been enforced
// Import the batch and verify that limits have been enforced
pool
.
a
ddRemotesSync
(
txs
)
pool
.
A
ddRemotesSync
(
txs
)
queued
:=
0
queued
:=
0
for
addr
,
list
:=
range
pool
.
queue
{
for
addr
,
list
:=
range
pool
.
queue
{
...
@@ -988,7 +988,7 @@ func TestTransactionPendingGlobalLimiting(t *testing.T) {
...
@@ -988,7 +988,7 @@ func TestTransactionPendingGlobalLimiting(t *testing.T) {
}
}
}
}
// Import the batch and verify that limits have been enforced
// Import the batch and verify that limits have been enforced
pool
.
a
ddRemotesSync
(
txs
)
pool
.
A
ddRemotesSync
(
txs
)
pending
:=
0
pending
:=
0
for
_
,
list
:=
range
pool
.
pending
{
for
_
,
list
:=
range
pool
.
pending
{
...
@@ -1068,7 +1068,7 @@ func TestTransactionPendingMinimumAllowance(t *testing.T) {
...
@@ -1068,7 +1068,7 @@ func TestTransactionPendingMinimumAllowance(t *testing.T) {
}
}
}
}
// Import the batch and verify that limits have been enforced
// Import the batch and verify that limits have been enforced
pool
.
a
ddRemotesSync
(
txs
)
pool
.
A
ddRemotesSync
(
txs
)
for
addr
,
list
:=
range
pool
.
pending
{
for
addr
,
list
:=
range
pool
.
pending
{
if
list
.
Len
()
!=
int
(
config
.
AccountSlots
)
{
if
list
.
Len
()
!=
int
(
config
.
AccountSlots
)
{
...
@@ -1124,7 +1124,7 @@ func TestTransactionPoolRepricing(t *testing.T) {
...
@@ -1124,7 +1124,7 @@ func TestTransactionPoolRepricing(t *testing.T) {
ltx
:=
pricedTransaction
(
0
,
100000
,
big
.
NewInt
(
1
),
keys
[
3
])
ltx
:=
pricedTransaction
(
0
,
100000
,
big
.
NewInt
(
1
),
keys
[
3
])
// Import the batch and that both pending and queued transactions match up
// Import the batch and that both pending and queued transactions match up
pool
.
a
ddRemotesSync
(
txs
)
pool
.
A
ddRemotesSync
(
txs
)
pool
.
AddLocal
(
ltx
)
pool
.
AddLocal
(
ltx
)
pending
,
queued
:=
pool
.
Stats
()
pending
,
queued
:=
pool
.
Stats
()
...
@@ -1404,7 +1404,7 @@ func TestTransactionPoolStableUnderpricing(t *testing.T) {
...
@@ -1404,7 +1404,7 @@ func TestTransactionPoolStableUnderpricing(t *testing.T) {
for
i
:=
uint64
(
0
);
i
<
config
.
GlobalSlots
;
i
++
{
for
i
:=
uint64
(
0
);
i
<
config
.
GlobalSlots
;
i
++
{
txs
=
append
(
txs
,
pricedTransaction
(
i
,
100000
,
big
.
NewInt
(
1
),
keys
[
0
]))
txs
=
append
(
txs
,
pricedTransaction
(
i
,
100000
,
big
.
NewInt
(
1
),
keys
[
0
]))
}
}
pool
.
a
ddRemotesSync
(
txs
)
pool
.
A
ddRemotesSync
(
txs
)
pending
,
queued
:=
pool
.
Stats
()
pending
,
queued
:=
pool
.
Stats
()
if
pending
!=
int
(
config
.
GlobalSlots
)
{
if
pending
!=
int
(
config
.
GlobalSlots
)
{
...
@@ -1658,7 +1658,7 @@ func TestTransactionStatusCheck(t *testing.T) {
...
@@ -1658,7 +1658,7 @@ func TestTransactionStatusCheck(t *testing.T) {
txs
=
append
(
txs
,
pricedTransaction
(
2
,
100000
,
big
.
NewInt
(
1
),
keys
[
2
]))
// Queued only
txs
=
append
(
txs
,
pricedTransaction
(
2
,
100000
,
big
.
NewInt
(
1
),
keys
[
2
]))
// Queued only
// Import the transaction and ensure they are correctly added
// Import the transaction and ensure they are correctly added
pool
.
a
ddRemotesSync
(
txs
)
pool
.
A
ddRemotesSync
(
txs
)
pending
,
queued
:=
pool
.
Stats
()
pending
,
queued
:=
pool
.
Stats
()
if
pending
!=
2
{
if
pending
!=
2
{
...
...
les/handler.go
View file @
b80c840a
...
@@ -85,6 +85,7 @@ type BlockChain interface {
...
@@ -85,6 +85,7 @@ type BlockChain interface {
type
txPool
interface
{
type
txPool
interface
{
AddRemotes
(
txs
[]
*
types
.
Transaction
)
[]
error
AddRemotes
(
txs
[]
*
types
.
Transaction
)
[]
error
AddRemotesSync
(
txs
[]
*
types
.
Transaction
)
[]
error
Status
(
hashes
[]
common
.
Hash
)
[]
core
.
TxStatus
Status
(
hashes
[]
common
.
Hash
)
[]
core
.
TxStatus
}
}
...
@@ -125,6 +126,9 @@ type ProtocolManager struct {
...
@@ -125,6 +126,9 @@ type ProtocolManager struct {
// Callbacks
// Callbacks
synced
func
()
bool
synced
func
()
bool
// Testing fields
addTxsSync
bool
}
}
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
...
@@ -1044,7 +1048,12 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
...
@@ -1044,7 +1048,12 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
hash
:=
tx
.
Hash
()
hash
:=
tx
.
Hash
()
stats
[
i
]
=
pm
.
txStatus
(
hash
)
stats
[
i
]
=
pm
.
txStatus
(
hash
)
if
stats
[
i
]
.
Status
==
core
.
TxStatusUnknown
{
if
stats
[
i
]
.
Status
==
core
.
TxStatusUnknown
{
if
errs
:=
pm
.
txpool
.
AddRemotes
([]
*
types
.
Transaction
{
tx
});
errs
[
0
]
!=
nil
{
addFn
:=
pm
.
txpool
.
AddRemotes
// Add txs synchronously for testing purpose
if
pm
.
addTxsSync
{
addFn
=
pm
.
txpool
.
AddRemotesSync
}
if
errs
:=
addFn
([]
*
types
.
Transaction
{
tx
});
errs
[
0
]
!=
nil
{
stats
[
i
]
.
Error
=
errs
[
0
]
.
Error
()
stats
[
i
]
.
Error
=
errs
[
0
]
.
Error
()
continue
continue
}
}
...
...
les/handler_test.go
View file @
b80c840a
...
@@ -496,6 +496,7 @@ func TestGetBloombitsProofs(t *testing.T) {
...
@@ -496,6 +496,7 @@ func TestGetBloombitsProofs(t *testing.T) {
func
TestTransactionStatusLes2
(
t
*
testing
.
T
)
{
func
TestTransactionStatusLes2
(
t
*
testing
.
T
)
{
server
,
tearDown
:=
newServerEnv
(
t
,
0
,
2
,
nil
)
server
,
tearDown
:=
newServerEnv
(
t
,
0
,
2
,
nil
)
defer
tearDown
()
defer
tearDown
()
server
.
pm
.
addTxsSync
=
true
chain
:=
server
.
pm
.
blockchain
.
(
*
core
.
BlockChain
)
chain
:=
server
.
pm
.
blockchain
.
(
*
core
.
BlockChain
)
config
:=
core
.
DefaultTxPoolConfig
config
:=
core
.
DefaultTxPoolConfig
...
...
les/transactions.rlp
0 → 100755
View file @
b80c840a
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