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
b94b9b01
Commit
b94b9b01
authored
Sep 18, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1817 from obscuren/nonce-fix
core: transaction nonce recovery
parents
216c486a
b60a2762
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
transaction_pool.go
core/transaction_pool.go
+2
-2
transaction_pool_test.go
core/transaction_pool_test.go
+19
-0
No files found.
core/transaction_pool.go
View file @
b94b9b01
...
...
@@ -121,8 +121,8 @@ func (pool *TxPool) resetState() {
if
addr
,
err
:=
tx
.
From
();
err
==
nil
{
// Set the nonce. Transaction nonce can never be lower
// than the state nonce; validatePool took care of that.
if
pool
.
pendingState
.
GetNonce
(
addr
)
<
tx
.
Nonce
()
{
pool
.
pendingState
.
SetNonce
(
addr
,
tx
.
Nonce
())
if
pool
.
pendingState
.
GetNonce
(
addr
)
<
=
tx
.
Nonce
()
{
pool
.
pendingState
.
SetNonce
(
addr
,
tx
.
Nonce
()
+
1
)
}
}
}
...
...
core/transaction_pool_test.go
View file @
b94b9b01
...
...
@@ -219,3 +219,22 @@ func TestMissingNonce(t *testing.T) {
t
.
Error
(
"expected 1 queued transaction, got"
,
len
(
pool
.
queue
[
addr
]))
}
}
func
TestNonceRecovery
(
t
*
testing
.
T
)
{
const
n
=
10
pool
,
key
:=
setupTxPool
()
addr
:=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
pool
.
currentState
()
.
SetNonce
(
addr
,
n
)
pool
.
currentState
()
.
AddBalance
(
addr
,
big
.
NewInt
(
100000000000000
))
pool
.
resetState
()
tx
:=
transaction
(
n
,
big
.
NewInt
(
100000
),
key
)
if
err
:=
pool
.
Add
(
tx
);
err
!=
nil
{
t
.
Error
(
err
)
}
// simulate some weird re-order of transactions and missing nonce(s)
pool
.
currentState
()
.
SetNonce
(
addr
,
n
-
1
)
pool
.
resetState
()
if
fn
:=
pool
.
pendingState
.
GetNonce
(
addr
);
fn
!=
n
+
1
{
t
.
Errorf
(
"expected nonce to be %d, got %d"
,
n
+
1
,
fn
)
}
}
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