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
5e1581c2
Unverified
Commit
5e1581c2
authored
Dec 20, 2017
by
Péter Szilágyi
Committed by
GitHub
Dec 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix panic when stat-ing a tx from a queue-only account (#15714)
parent
50df2b78
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
1 deletion
+58
-1
tx_pool.go
core/tx_pool.go
+1
-1
tx_pool_test.go
core/tx_pool_test.go
+57
-0
No files found.
core/tx_pool.go
View file @
5e1581c2
...
...
@@ -838,7 +838,7 @@ func (pool *TxPool) Status(hashes []common.Hash) []TxStatus {
for
i
,
hash
:=
range
hashes
{
if
tx
:=
pool
.
all
[
hash
];
tx
!=
nil
{
from
,
_
:=
types
.
Sender
(
pool
.
signer
,
tx
)
// already validated
if
pool
.
pending
[
from
]
.
txs
.
items
[
tx
.
Nonce
()]
!=
nil
{
if
pool
.
pending
[
from
]
!=
nil
&&
pool
.
pending
[
from
]
.
txs
.
items
[
tx
.
Nonce
()]
!=
nil
{
status
[
i
]
=
TxStatusPending
}
else
{
status
[
i
]
=
TxStatusQueued
...
...
core/tx_pool_test.go
View file @
5e1581c2
...
...
@@ -1563,6 +1563,63 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
pool
.
Stop
()
}
// TestTransactionStatusCheck tests that the pool can correctly retrieve the
// pending status of individual transactions.
func
TestTransactionStatusCheck
(
t
*
testing
.
T
)
{
t
.
Parallel
()
// Create the pool to test the status retrievals with
db
,
_
:=
ethdb
.
NewMemDatabase
()
statedb
,
_
:=
state
.
New
(
common
.
Hash
{},
state
.
NewDatabase
(
db
))
blockchain
:=
&
testBlockChain
{
statedb
,
big
.
NewInt
(
1000000
),
new
(
event
.
Feed
)}
pool
:=
NewTxPool
(
testTxPoolConfig
,
params
.
TestChainConfig
,
blockchain
)
defer
pool
.
Stop
()
// Create the test accounts to check various transaction statuses with
keys
:=
make
([]
*
ecdsa
.
PrivateKey
,
3
)
for
i
:=
0
;
i
<
len
(
keys
);
i
++
{
keys
[
i
],
_
=
crypto
.
GenerateKey
()
pool
.
currentState
.
AddBalance
(
crypto
.
PubkeyToAddress
(
keys
[
i
]
.
PublicKey
),
big
.
NewInt
(
1000000
))
}
// Generate and queue a batch of transactions, both pending and queued
txs
:=
types
.
Transactions
{}
txs
=
append
(
txs
,
pricedTransaction
(
0
,
big
.
NewInt
(
100000
),
big
.
NewInt
(
1
),
keys
[
0
]))
// Pending only
txs
=
append
(
txs
,
pricedTransaction
(
0
,
big
.
NewInt
(
100000
),
big
.
NewInt
(
1
),
keys
[
1
]))
// Pending and queued
txs
=
append
(
txs
,
pricedTransaction
(
2
,
big
.
NewInt
(
100000
),
big
.
NewInt
(
1
),
keys
[
1
]))
txs
=
append
(
txs
,
pricedTransaction
(
2
,
big
.
NewInt
(
100000
),
big
.
NewInt
(
1
),
keys
[
2
]))
// Queued only
// Import the transaction and ensure they are correctly added
pool
.
AddRemotes
(
txs
)
pending
,
queued
:=
pool
.
Stats
()
if
pending
!=
2
{
t
.
Fatalf
(
"pending transactions mismatched: have %d, want %d"
,
pending
,
2
)
}
if
queued
!=
2
{
t
.
Fatalf
(
"queued transactions mismatched: have %d, want %d"
,
queued
,
2
)
}
if
err
:=
validateTxPoolInternals
(
pool
);
err
!=
nil
{
t
.
Fatalf
(
"pool internal state corrupted: %v"
,
err
)
}
// Retrieve the status of each transaction and validate them
hashes
:=
make
([]
common
.
Hash
,
len
(
txs
))
for
i
,
tx
:=
range
txs
{
hashes
[
i
]
=
tx
.
Hash
()
}
hashes
=
append
(
hashes
,
common
.
Hash
{})
statuses
:=
pool
.
Status
(
hashes
)
expect
:=
[]
TxStatus
{
TxStatusPending
,
TxStatusPending
,
TxStatusQueued
,
TxStatusQueued
,
TxStatusUnknown
}
for
i
:=
0
;
i
<
len
(
statuses
);
i
++
{
if
statuses
[
i
]
!=
expect
[
i
]
{
t
.
Errorf
(
"transaction %d: status mismatch: have %v, want %v"
,
i
,
statuses
[
i
],
expect
[
i
])
}
}
}
// Benchmarks the speed of validating the contents of the pending queue of the
// transaction pool.
func
BenchmarkPendingDemotion100
(
b
*
testing
.
B
)
{
benchmarkPendingDemotion
(
b
,
100
)
}
...
...
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