Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
1c45f2f4
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,发现更多精彩内容 >>
未验证
提交
1c45f2f4
编写于
8月 08, 2017
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: fix txpool journal and test races
上级
97107982
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
30 deletion
+43
-30
core/tx_pool.go
core/tx_pool.go
+16
-3
core/tx_pool_test.go
core/tx_pool_test.go
+27
-27
未找到文件。
core/tx_pool.go
浏览文件 @
1c45f2f4
...
...
@@ -207,7 +207,7 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, eventMux *e
}
pool
.
locals
=
newAccountSet
(
pool
.
signer
)
pool
.
priced
=
newTxPricedList
(
&
pool
.
all
)
pool
.
reset
State
()
pool
.
reset
()
// If local transactions and journaling is enabled, load from disk
if
!
config
.
NoLocals
&&
config
.
Journal
!=
""
{
...
...
@@ -261,7 +261,7 @@ func (pool *TxPool) loop() {
pool
.
homestead
=
true
}
}
pool
.
reset
State
()
pool
.
reset
()
pool
.
mu
.
Unlock
()
case
RemovedTransactionEvent
:
...
...
@@ -300,15 +300,28 @@ func (pool *TxPool) loop() {
// Handle local transaction journal rotation
case
<-
journal
.
C
:
if
pool
.
journal
!=
nil
{
pool
.
mu
.
Lock
()
if
err
:=
pool
.
journal
.
rotate
(
pool
.
local
());
err
!=
nil
{
log
.
Warn
(
"Failed to rotate local tx journal"
,
"err"
,
err
)
}
pool
.
mu
.
Unlock
()
}
}
}
}
func
(
pool
*
TxPool
)
resetState
()
{
// lockedReset is a wrapper around reset to allow calling it in a thread safe
// manner. This method is only ever used in the tester!
func
(
pool
*
TxPool
)
lockedReset
()
{
pool
.
mu
.
Lock
()
defer
pool
.
mu
.
Unlock
()
pool
.
reset
()
}
// reset retrieves the current state of the blockchain and ensures the content
// of the transaction pool is valid with regard to the chain state.
func
(
pool
*
TxPool
)
reset
()
{
currentState
,
err
:=
pool
.
currentState
()
if
err
!=
nil
{
log
.
Error
(
"Failed reset txpool state"
,
"err"
,
err
)
...
...
core/tx_pool_test.go
浏览文件 @
1c45f2f4
...
...
@@ -153,7 +153,7 @@ func TestStateChangeDuringPoolReset(t *testing.T) {
// trigger state change in the background
trigger
=
true
pool
.
resetState
()
pool
.
lockedReset
()
pendingTx
,
err
:=
pool
.
Pending
()
if
err
!=
nil
{
...
...
@@ -213,7 +213,7 @@ func TestTransactionQueue(t *testing.T) {
from
,
_
:=
deriveSender
(
tx
)
currentState
,
_
:=
pool
.
currentState
()
currentState
.
AddBalance
(
from
,
big
.
NewInt
(
1000
))
pool
.
resetState
()
pool
.
lockedReset
()
pool
.
enqueueTx
(
tx
.
Hash
(),
tx
)
pool
.
promoteExecutables
(
currentState
,
[]
common
.
Address
{
from
})
...
...
@@ -243,7 +243,7 @@ func TestTransactionQueue(t *testing.T) {
from
,
_
=
deriveSender
(
tx1
)
currentState
,
_
=
pool
.
currentState
()
currentState
.
AddBalance
(
from
,
big
.
NewInt
(
1000
))
pool
.
resetState
()
pool
.
lockedReset
()
pool
.
enqueueTx
(
tx1
.
Hash
(),
tx1
)
pool
.
enqueueTx
(
tx2
.
Hash
(),
tx2
)
...
...
@@ -314,7 +314,7 @@ func TestTransactionChainFork(t *testing.T) {
pool
.
currentState
=
func
()
(
*
state
.
StateDB
,
error
)
{
return
statedb
,
nil
}
currentState
,
_
:=
pool
.
currentState
()
currentState
.
AddBalance
(
addr
,
big
.
NewInt
(
100000000000000
))
pool
.
resetState
()
pool
.
lockedReset
()
}
resetState
()
...
...
@@ -342,7 +342,7 @@ func TestTransactionDoubleNonce(t *testing.T) {
pool
.
currentState
=
func
()
(
*
state
.
StateDB
,
error
)
{
return
statedb
,
nil
}
currentState
,
_
:=
pool
.
currentState
()
currentState
.
AddBalance
(
addr
,
big
.
NewInt
(
100000000000000
))
pool
.
resetState
()
pool
.
lockedReset
()
}
resetState
()
...
...
@@ -412,14 +412,14 @@ func TestNonceRecovery(t *testing.T) {
currentState
,
_
:=
pool
.
currentState
()
currentState
.
SetNonce
(
addr
,
n
)
currentState
.
AddBalance
(
addr
,
big
.
NewInt
(
100000000000000
))
pool
.
resetState
()
pool
.
lockedReset
()
tx
:=
transaction
(
n
,
big
.
NewInt
(
100000
),
key
)
if
err
:=
pool
.
AddRemote
(
tx
);
err
!=
nil
{
t
.
Error
(
err
)
}
// simulate some weird re-order of transactions and missing nonce(s)
currentState
.
SetNonce
(
addr
,
n
-
1
)
pool
.
resetState
()
pool
.
lockedReset
()
if
fn
:=
pool
.
pendingState
.
GetNonce
(
addr
);
fn
!=
n
+
1
{
t
.
Errorf
(
"expected nonce to be %d, got %d"
,
n
+
1
,
fn
)
}
...
...
@@ -433,7 +433,7 @@ func TestRemovedTxEvent(t *testing.T) {
from
,
_
:=
deriveSender
(
tx
)
currentState
,
_
:=
pool
.
currentState
()
currentState
.
AddBalance
(
from
,
big
.
NewInt
(
1000000000000
))
pool
.
resetState
()
pool
.
lockedReset
()
pool
.
eventMux
.
Post
(
RemovedTransactionEvent
{
types
.
Transactions
{
tx
}})
pool
.
eventMux
.
Post
(
ChainHeadEvent
{
nil
})
if
pool
.
pending
[
from
]
.
Len
()
!=
1
{
...
...
@@ -482,7 +482,7 @@ func TestTransactionDropping(t *testing.T) {
if
len
(
pool
.
all
)
!=
6
{
t
.
Errorf
(
"total transaction mismatch: have %d, want %d"
,
len
(
pool
.
all
),
6
)
}
pool
.
resetState
()
pool
.
lockedReset
()
if
pool
.
pending
[
account
]
.
Len
()
!=
3
{
t
.
Errorf
(
"pending transaction mismatch: have %d, want %d"
,
pool
.
pending
[
account
]
.
Len
(),
3
)
}
...
...
@@ -494,7 +494,7 @@ func TestTransactionDropping(t *testing.T) {
}
// Reduce the balance of the account, and check that invalidated transactions are dropped
state
.
AddBalance
(
account
,
big
.
NewInt
(
-
650
))
pool
.
resetState
()
pool
.
lockedReset
()
if
_
,
ok
:=
pool
.
pending
[
account
]
.
txs
.
items
[
tx0
.
Nonce
()];
!
ok
{
t
.
Errorf
(
"funded pending transaction missing: %v"
,
tx0
)
...
...
@@ -519,7 +519,7 @@ func TestTransactionDropping(t *testing.T) {
}
// Reduce the block gas limit, check that invalidated transactions are dropped
pool
.
gasLimit
=
func
()
*
big
.
Int
{
return
big
.
NewInt
(
100
)
}
pool
.
resetState
()
pool
.
lockedReset
()
if
_
,
ok
:=
pool
.
pending
[
account
]
.
txs
.
items
[
tx0
.
Nonce
()];
!
ok
{
t
.
Errorf
(
"funded pending transaction missing: %v"
,
tx0
)
...
...
@@ -573,7 +573,7 @@ func TestTransactionPostponing(t *testing.T) {
if
len
(
pool
.
all
)
!=
len
(
txns
)
{
t
.
Errorf
(
"total transaction mismatch: have %d, want %d"
,
len
(
pool
.
all
),
len
(
txns
))
}
pool
.
resetState
()
pool
.
lockedReset
()
if
pool
.
pending
[
account
]
.
Len
()
!=
len
(
txns
)
{
t
.
Errorf
(
"pending transaction mismatch: have %d, want %d"
,
pool
.
pending
[
account
]
.
Len
(),
len
(
txns
))
}
...
...
@@ -585,7 +585,7 @@ func TestTransactionPostponing(t *testing.T) {
}
// Reduce the balance of the account, and check that transactions are reorganised
state
.
AddBalance
(
account
,
big
.
NewInt
(
-
750
))
pool
.
resetState
()
pool
.
lockedReset
()
if
_
,
ok
:=
pool
.
pending
[
account
]
.
txs
.
items
[
txns
[
0
]
.
Nonce
()];
!
ok
{
t
.
Errorf
(
"tx %d: valid and funded transaction missing from pending pool: %v"
,
0
,
txns
[
0
])
...
...
@@ -626,7 +626,7 @@ func TestTransactionQueueAccountLimiting(t *testing.T) {
state
,
_
:=
pool
.
currentState
()
state
.
AddBalance
(
account
,
big
.
NewInt
(
1000000
))
pool
.
resetState
()
pool
.
lockedReset
()
// Keep queuing up transactions and make sure all above a limit are dropped
for
i
:=
uint64
(
1
);
i
<=
testTxPoolConfig
.
AccountQueue
+
5
;
i
++
{
...
...
@@ -780,7 +780,7 @@ func testTransactionQueueTimeLimiting(t *testing.T, nolocals bool) {
if
err
:=
pool
.
AddRemote
(
pricedTransaction
(
1
,
big
.
NewInt
(
100000
),
big
.
NewInt
(
1
),
remote
));
err
!=
nil
{
t
.
Fatalf
(
"failed to add remote transaction: %v"
,
err
)
}
pending
,
queued
:=
pool
.
s
tats
()
pending
,
queued
:=
pool
.
S
tats
()
if
pending
!=
0
{
t
.
Fatalf
(
"pending transactions mismatched: have %d, want %d"
,
pending
,
0
)
}
...
...
@@ -793,7 +793,7 @@ func testTransactionQueueTimeLimiting(t *testing.T, nolocals bool) {
// Wait a bit for eviction to run and clean up any leftovers, and ensure only the local remains
time
.
Sleep
(
2
*
config
.
Lifetime
)
pending
,
queued
=
pool
.
s
tats
()
pending
,
queued
=
pool
.
S
tats
()
if
pending
!=
0
{
t
.
Fatalf
(
"pending transactions mismatched: have %d, want %d"
,
pending
,
0
)
}
...
...
@@ -823,7 +823,7 @@ func TestTransactionPendingLimiting(t *testing.T) {
state
,
_
:=
pool
.
currentState
()
state
.
AddBalance
(
account
,
big
.
NewInt
(
1000000
))
pool
.
resetState
()
pool
.
lockedReset
()
// Keep queuing up transactions and make sure all above a limit are dropped
for
i
:=
uint64
(
0
);
i
<
testTxPoolConfig
.
AccountQueue
+
5
;
i
++
{
...
...
@@ -1057,7 +1057,7 @@ func TestTransactionPoolRepricing(t *testing.T) {
pool
.
AddRemotes
(
txs
)
pool
.
AddLocal
(
ltx
)
pending
,
queued
:=
pool
.
s
tats
()
pending
,
queued
:=
pool
.
S
tats
()
if
pending
!=
4
{
t
.
Fatalf
(
"pending transactions mismatched: have %d, want %d"
,
pending
,
4
)
}
...
...
@@ -1070,7 +1070,7 @@ func TestTransactionPoolRepricing(t *testing.T) {
// Reprice the pool and check that underpriced transactions get dropped
pool
.
SetGasPrice
(
big
.
NewInt
(
2
))
pending
,
queued
=
pool
.
s
tats
()
pending
,
queued
=
pool
.
S
tats
()
if
pending
!=
2
{
t
.
Fatalf
(
"pending transactions mismatched: have %d, want %d"
,
pending
,
2
)
}
...
...
@@ -1095,7 +1095,7 @@ func TestTransactionPoolRepricing(t *testing.T) {
if
err
:=
pool
.
AddLocal
(
tx
);
err
!=
nil
{
t
.
Fatalf
(
"failed to add underpriced local transaction: %v"
,
err
)
}
if
pending
,
_
=
pool
.
s
tats
();
pending
!=
3
{
if
pending
,
_
=
pool
.
S
tats
();
pending
!=
3
{
t
.
Fatalf
(
"pending transactions mismatched: have %d, want %d"
,
pending
,
3
)
}
if
err
:=
validateTxPoolInternals
(
pool
);
err
!=
nil
{
...
...
@@ -1142,7 +1142,7 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
pool
.
AddRemotes
(
txs
)
pool
.
AddLocal
(
ltx
)
pending
,
queued
:=
pool
.
s
tats
()
pending
,
queued
:=
pool
.
S
tats
()
if
pending
!=
3
{
t
.
Fatalf
(
"pending transactions mismatched: have %d, want %d"
,
pending
,
3
)
}
...
...
@@ -1166,7 +1166,7 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
if
err
:=
pool
.
AddRemote
(
pricedTransaction
(
3
,
big
.
NewInt
(
100000
),
big
.
NewInt
(
5
),
keys
[
1
]));
err
!=
nil
{
t
.
Fatalf
(
"failed to add well priced transaction: %v"
,
err
)
}
pending
,
queued
=
pool
.
s
tats
()
pending
,
queued
=
pool
.
S
tats
()
if
pending
!=
2
{
t
.
Fatalf
(
"pending transactions mismatched: have %d, want %d"
,
pending
,
2
)
}
...
...
@@ -1181,7 +1181,7 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
if
err
:=
pool
.
AddLocal
(
tx
);
err
!=
nil
{
t
.
Fatalf
(
"failed to add underpriced local transaction: %v"
,
err
)
}
pending
,
queued
=
pool
.
s
tats
()
pending
,
queued
=
pool
.
S
tats
()
if
pending
!=
2
{
t
.
Fatalf
(
"pending transactions mismatched: have %d, want %d"
,
pending
,
2
)
}
...
...
@@ -1307,7 +1307,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
if
err
:=
pool
.
AddRemote
(
pricedTransaction
(
0
,
big
.
NewInt
(
100000
),
big
.
NewInt
(
1
),
remote
));
err
!=
nil
{
t
.
Fatalf
(
"failed to add remote transaction: %v"
,
err
)
}
pending
,
queued
:=
pool
.
s
tats
()
pending
,
queued
:=
pool
.
S
tats
()
if
pending
!=
4
{
t
.
Fatalf
(
"pending transactions mismatched: have %d, want %d"
,
pending
,
4
)
}
...
...
@@ -1322,7 +1322,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
statedb
.
SetNonce
(
crypto
.
PubkeyToAddress
(
local
.
PublicKey
),
1
)
pool
=
NewTxPool
(
config
,
params
.
TestChainConfig
,
new
(
event
.
TypeMux
),
func
()
(
*
state
.
StateDB
,
error
)
{
return
statedb
,
nil
},
func
()
*
big
.
Int
{
return
big
.
NewInt
(
1000000
)
})
pending
,
queued
=
pool
.
s
tats
()
pending
,
queued
=
pool
.
S
tats
()
if
queued
!=
0
{
t
.
Fatalf
(
"queued transactions mismatched: have %d, want %d"
,
queued
,
0
)
}
...
...
@@ -1340,13 +1340,13 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
}
// Bump the nonce temporarily and ensure the newly invalidated transaction is removed
statedb
.
SetNonce
(
crypto
.
PubkeyToAddress
(
local
.
PublicKey
),
2
)
pool
.
resetState
()
pool
.
lockedReset
()
time
.
Sleep
(
2
*
config
.
Rejournal
)
pool
.
Stop
()
statedb
.
SetNonce
(
crypto
.
PubkeyToAddress
(
local
.
PublicKey
),
1
)
pool
=
NewTxPool
(
config
,
params
.
TestChainConfig
,
new
(
event
.
TypeMux
),
func
()
(
*
state
.
StateDB
,
error
)
{
return
statedb
,
nil
},
func
()
*
big
.
Int
{
return
big
.
NewInt
(
1000000
)
})
pending
,
queued
=
pool
.
s
tats
()
pending
,
queued
=
pool
.
S
tats
()
if
pending
!=
0
{
t
.
Fatalf
(
"pending transactions mismatched: have %d, want %d"
,
pending
,
0
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录