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
912cf7ba
Commit
912cf7ba
authored
Jun 04, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: added fork test & double nonce test
parent
0f51ee6c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
20 deletions
+75
-20
transaction_pool.go
core/transaction_pool.go
+26
-20
transaction_pool_test.go
core/transaction_pool_test.go
+49
-0
No files found.
core/transaction_pool.go
View file @
912cf7ba
...
...
@@ -68,31 +68,37 @@ func (pool *TxPool) Start() {
pool
.
events
=
pool
.
eventMux
.
Subscribe
(
ChainEvent
{})
for
_
=
range
pool
.
events
.
Chan
()
{
pool
.
mu
.
Lock
()
pool
.
state
=
state
.
ManageState
(
pool
.
currentState
())
// validate the pool of pending transactions, this will remove
// any transactions that have been included in the block or
// have been invalidated because of another transaction (e.g.
// higher gas price)
pool
.
validatePool
()
// Loop over the pending transactions and base the nonce of the new
// pending transaction set.
for
_
,
tx
:=
range
pool
.
pending
{
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.
pool
.
state
.
SetNonce
(
addr
,
tx
.
Nonce
())
}
}
// Check the queue and move transactions over to the pending if possible
// or remove those that have become invalid
pool
.
checkQueue
()
pool
.
resetState
()
pool
.
mu
.
Unlock
()
}
}
func
(
pool
*
TxPool
)
resetState
()
{
pool
.
state
=
state
.
ManageState
(
pool
.
currentState
())
// validate the pool of pending transactions, this will remove
// any transactions that have been included in the block or
// have been invalidated because of another transaction (e.g.
// higher gas price)
pool
.
validatePool
()
// Loop over the pending transactions and base the nonce of the new
// pending transaction set.
for
_
,
tx
:=
range
pool
.
pending
{
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.
pool
.
state
.
SetNonce
(
addr
,
tx
.
Nonce
())
}
}
// Check the queue and move transactions over to the pending if possible
// or remove those that have become invalid
pool
.
checkQueue
()
}
func
(
pool
*
TxPool
)
Stop
()
{
pool
.
pending
=
make
(
map
[
common
.
Hash
]
*
types
.
Transaction
)
close
(
pool
.
quit
)
...
...
core/transaction_pool_test.go
View file @
912cf7ba
...
...
@@ -152,3 +152,52 @@ func TestNegativeValue(t *testing.T) {
t
.
Error
(
"expected"
,
ErrNegativeValue
,
"got"
,
err
)
}
}
func
TestTransactionChainFork
(
t
*
testing
.
T
)
{
pool
,
key
:=
setupTxPool
()
addr
:=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
pool
.
currentState
()
.
AddBalance
(
addr
,
big
.
NewInt
(
100000000000000
))
tx
:=
transaction
()
tx
.
GasLimit
=
big
.
NewInt
(
100000
)
tx
.
SignECDSA
(
key
)
err
:=
pool
.
add
(
tx
)
if
err
!=
nil
{
t
.
Error
(
"didn't expect error"
,
err
)
}
pool
.
RemoveTransactions
([]
*
types
.
Transaction
{
tx
})
// reset the pool's internal state
pool
.
resetState
()
err
=
pool
.
add
(
tx
)
if
err
!=
nil
{
t
.
Error
(
"didn't expect error"
,
err
)
}
}
func
TestTransactionDoubleNonce
(
t
*
testing
.
T
)
{
pool
,
key
:=
setupTxPool
()
addr
:=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
pool
.
currentState
()
.
AddBalance
(
addr
,
big
.
NewInt
(
100000000000000
))
tx
:=
transaction
()
tx
.
GasLimit
=
big
.
NewInt
(
100000
)
tx
.
SignECDSA
(
key
)
err
:=
pool
.
add
(
tx
)
if
err
!=
nil
{
t
.
Error
(
"didn't expect error"
,
err
)
}
tx2
:=
transaction
()
tx2
.
GasLimit
=
big
.
NewInt
(
1000000
)
tx2
.
SignECDSA
(
key
)
err
=
pool
.
add
(
tx2
)
if
err
!=
nil
{
t
.
Error
(
"didn't expect error"
,
err
)
}
if
len
(
pool
.
pending
)
!=
2
{
t
.
Error
(
"expected 2 pending txs. Got"
,
len
(
pool
.
pending
))
}
}
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