Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
acb59f32
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
acb59f32
编写于
6月 10, 2015
作者:
J
Jeffrey Wilcke
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1223 from obscuren/tx-pool-vroooooom
core: fixed race condition in the transaction pool
上级
858a6f0b
4407524d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
41 deletion
+32
-41
core/helper_test.go
core/helper_test.go
+1
-4
core/transaction_pool.go
core/transaction_pool.go
+31
-32
eth/backend.go
eth/backend.go
+0
-5
未找到文件。
core/helper_test.go
浏览文件 @
acb59f32
...
...
@@ -6,8 +6,8 @@ import (
"github.com/ethereum/go-ethereum/core/types"
// "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
)
...
...
@@ -76,8 +76,5 @@ func NewTestManager() *TestManager {
// testManager.blockChain = NewChainManager(testManager)
// testManager.stateManager = NewStateManager(testManager)
// Start the tx pool
testManager
.
txPool
.
Start
()
return
testManager
}
core/transaction_pool.go
浏览文件 @
acb59f32
...
...
@@ -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
),
...
...
@@ -58,14 +58,17 @@ func NewTxPool(eventMux *event.TypeMux, currentStateFn stateFn, gasLimitFn func(
currentState
:
currentStateFn
,
gasLimit
:
gasLimitFn
,
pendingState
:
state
.
ManageState
(
currentStateFn
()),
events
:
eventMux
.
Subscribe
(
ChainEvent
{}),
}
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
pool
.
events
=
pool
.
eventMux
.
Subscribe
(
ChainEvent
{})
for
_
=
range
pool
.
events
.
Chan
()
{
pool
.
mu
.
Lock
()
...
...
@@ -100,7 +103,6 @@ func (pool *TxPool) resetState() {
}
func
(
pool
*
TxPool
)
Stop
()
{
pool
.
pending
=
make
(
map
[
common
.
Hash
]
*
types
.
Transaction
)
close
(
pool
.
quit
)
pool
.
events
.
Unsubscribe
()
glog
.
V
(
logger
.
Info
)
.
Infoln
(
"TX Pool stopped"
)
...
...
@@ -169,15 +171,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 +204,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 +311,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
浏览文件 @
acb59f32
...
...
@@ -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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录