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
65a48f9c
Commit
65a48f9c
authored
Jun 09, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fixed race condition in the transaction pool
Removed `Stop/Start` mechanism from the transaction pool.
parent
858a6f0b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
35 deletions
+30
-35
transaction_pool.go
core/transaction_pool.go
+30
-30
backend.go
eth/backend.go
+0
-5
No files found.
core/transaction_pool.go
View file @
65a48f9c
...
...
@@ -50,7 +50,7 @@ type TxPool struct {
}
func
NewTxPool
(
eventMux
*
event
.
TypeMux
,
currentStateFn
stateFn
,
gasLimitFn
func
()
*
big
.
Int
)
*
TxPool
{
return
&
TxPool
{
pool
:=
&
TxPool
{
pending
:
make
(
map
[
common
.
Hash
]
*
types
.
Transaction
),
queue
:
make
(
map
[
common
.
Address
]
map
[
common
.
Hash
]
*
types
.
Transaction
),
quit
:
make
(
chan
bool
),
...
...
@@ -59,9 +59,12 @@ func NewTxPool(eventMux *event.TypeMux, currentStateFn stateFn, gasLimitFn func(
gasLimit
:
gasLimitFn
,
pendingState
:
state
.
ManageState
(
currentStateFn
()),
}
go
pool
.
eventLoop
()
return
pool
}
func
(
pool
*
TxPool
)
Start
()
{
func
(
pool
*
TxPool
)
eventLoop
()
{
// Track chain events. When a chain events occurs (new chain canon block)
// we need to know the new state. The new state will help us determine
// the nonces in the managed state
...
...
@@ -169,15 +172,10 @@ func (pool *TxPool) validateTx(tx *types.Transaction) error {
return
nil
}
// validate and queue transactions.
func
(
self
*
TxPool
)
add
(
tx
*
types
.
Transaction
)
error
{
hash
:=
tx
.
Hash
()
/* XXX I'm unsure about this. This is extremely dangerous and may result
in total black listing of certain transactions
if self.invalidHashes.Has(hash) {
return fmt.Errorf("Invalid transaction (%x)", hash[:4])
}
*/
if
self
.
pending
[
hash
]
!=
nil
{
return
fmt
.
Errorf
(
"Known transaction (%x)"
,
hash
[
:
4
])
}
...
...
@@ -207,6 +205,30 @@ func (self *TxPool) add(tx *types.Transaction) error {
return
nil
}
// queueTx will queue an unknown transaction
func
(
self
*
TxPool
)
queueTx
(
hash
common
.
Hash
,
tx
*
types
.
Transaction
)
{
from
,
_
:=
tx
.
From
()
// already validated
if
self
.
queue
[
from
]
==
nil
{
self
.
queue
[
from
]
=
make
(
map
[
common
.
Hash
]
*
types
.
Transaction
)
}
self
.
queue
[
from
][
hash
]
=
tx
}
// addTx will add a transaction to the pending (processable queue) list of transactions
func
(
pool
*
TxPool
)
addTx
(
hash
common
.
Hash
,
addr
common
.
Address
,
tx
*
types
.
Transaction
)
{
if
_
,
ok
:=
pool
.
pending
[
hash
];
!
ok
{
pool
.
pending
[
hash
]
=
tx
// Increment the nonce on the pending state. This can only happen if
// the nonce is +1 to the previous one.
pool
.
pendingState
.
SetNonce
(
addr
,
tx
.
AccountNonce
+
1
)
// Notify the subscribers. This event is posted in a goroutine
// because it's possible that somewhere during the post "Remove transaction"
// gets called which will then wait for the global tx pool lock and deadlock.
go
pool
.
eventMux
.
Post
(
TxPreEvent
{
tx
})
}
}
// Add queues a single transaction in the pool if it is valid.
func
(
self
*
TxPool
)
Add
(
tx
*
types
.
Transaction
)
error
{
self
.
mu
.
Lock
()
...
...
@@ -290,28 +312,6 @@ func (self *TxPool) RemoveTransactions(txs types.Transactions) {
}
}
func
(
self
*
TxPool
)
queueTx
(
hash
common
.
Hash
,
tx
*
types
.
Transaction
)
{
from
,
_
:=
tx
.
From
()
// already validated
if
self
.
queue
[
from
]
==
nil
{
self
.
queue
[
from
]
=
make
(
map
[
common
.
Hash
]
*
types
.
Transaction
)
}
self
.
queue
[
from
][
hash
]
=
tx
}
func
(
pool
*
TxPool
)
addTx
(
hash
common
.
Hash
,
addr
common
.
Address
,
tx
*
types
.
Transaction
)
{
if
_
,
ok
:=
pool
.
pending
[
hash
];
!
ok
{
pool
.
pending
[
hash
]
=
tx
// Increment the nonce on the pending state. This can only happen if
// the nonce is +1 to the previous one.
pool
.
pendingState
.
SetNonce
(
addr
,
tx
.
AccountNonce
+
1
)
// Notify the subscribers. This event is posted in a goroutine
// because it's possible that somewhere during the post "Remove transaction"
// gets called which will then wait for the global tx pool lock and deadlock.
go
pool
.
eventMux
.
Post
(
TxPreEvent
{
tx
})
}
}
// checkQueue moves transactions that have become processable to main pool.
func
(
pool
*
TxPool
)
checkQueue
()
{
state
:=
pool
.
pendingState
...
...
eth/backend.go
View file @
65a48f9c
...
...
@@ -466,8 +466,6 @@ func (s *Ethereum) Start() error {
s
.
StartAutoDAG
()
}
// Start services
go
s
.
txPool
.
Start
()
s
.
protocolManager
.
Start
()
if
s
.
whisper
!=
nil
{
...
...
@@ -513,9 +511,6 @@ func (s *Ethereum) StartForTest() {
ClientString
:
s
.
net
.
Name
,
ProtocolVersion
:
ProtocolVersion
,
})
// Start services
s
.
txPool
.
Start
()
}
// AddPeer connects to the given node and maintains the connection until the
...
...
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