Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
b0b3cf2e
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,发现更多精彩内容 >>
未验证
提交
b0b3cf2e
编写于
6月 22, 2017
作者:
M
Martin Holst Swende
提交者:
Péter Szilágyi
6月 22, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: add testcase for txpool
上级
58a1e13e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
79 addition
and
0 deletion
+79
-0
core/tx_pool.go
core/tx_pool.go
+13
-0
core/tx_pool_test.go
core/tx_pool_test.go
+66
-0
未找到文件。
core/tx_pool.go
浏览文件 @
b0b3cf2e
...
...
@@ -301,6 +301,19 @@ func (pool *TxPool) Stats() (int, int) {
return
pool
.
stats
()
}
// validateInternals checks if the content in pool.all
// is consistent with the numbers reported in pending and queued
func
(
pool
*
TxPool
)
validateInternals
()
error
{
pool
.
mu
.
RLock
()
defer
pool
.
mu
.
RUnlock
()
p
,
q
:=
pool
.
stats
()
a
:=
len
(
pool
.
all
)
if
a
!=
p
+
q
{
return
fmt
.
Errorf
(
"Pool.all size %d != %d pending + %d queued"
,
a
,
p
,
q
)
}
return
nil
}
// stats retrieves the current pool stats, namely the number of pending and the
// number of queued (non-executable) transactions.
func
(
pool
*
TxPool
)
stats
()
(
int
,
int
)
{
...
...
core/tx_pool_test.go
浏览文件 @
b0b3cf2e
...
...
@@ -719,6 +719,12 @@ func testTransactionLimitingEquivalency(t *testing.T, origin uint64) {
txns
=
append
(
txns
,
transaction
(
origin
+
i
,
big
.
NewInt
(
100000
),
key2
))
}
pool2
.
AddBatch
(
txns
)
if
err
:=
pool2
.
validateInternals
();
err
!=
nil
{
t
.
Error
(
err
)
}
if
err
:=
pool1
.
validateInternals
();
err
!=
nil
{
t
.
Error
(
err
)
}
// Ensure the batch optimization honors the same pool mechanics
if
len
(
pool1
.
pending
)
!=
len
(
pool2
.
pending
)
{
...
...
@@ -769,6 +775,9 @@ func TestTransactionPendingGlobalLimiting(t *testing.T) {
// Import the batch and verify that limits have been enforced
pool
.
AddBatch
(
txs
)
if
err
:=
pool
.
validateInternals
();
err
!=
nil
{
t
.
Error
(
err
)
}
pending
:=
0
for
_
,
list
:=
range
pool
.
pending
{
pending
+=
list
.
Len
()
...
...
@@ -778,6 +787,42 @@ func TestTransactionPendingGlobalLimiting(t *testing.T) {
}
}
// Tests that if transactions start being capped, transasctions are also removed from 'all'
func
TestTransactionCapClearsFromAll
(
t
*
testing
.
T
)
{
// Reduce the queue limits to shorten test time
defer
func
(
old
uint64
)
{
DefaultTxPoolConfig
.
GlobalSlots
=
old
}(
DefaultTxPoolConfig
.
GlobalSlots
)
DefaultTxPoolConfig
.
AccountSlots
=
2
DefaultTxPoolConfig
.
AccountQueue
=
2
DefaultTxPoolConfig
.
GlobalSlots
=
8
// Create the pool to test the limit enforcement with
db
,
_
:=
ethdb
.
NewMemDatabase
()
statedb
,
_
:=
state
.
New
(
common
.
Hash
{},
db
)
pool
:=
NewTxPool
(
DefaultTxPoolConfig
,
params
.
TestChainConfig
,
new
(
event
.
TypeMux
),
func
()
(
*
state
.
StateDB
,
error
)
{
return
statedb
,
nil
},
func
()
*
big
.
Int
{
return
big
.
NewInt
(
1000000
)
})
pool
.
resetState
()
// Create a number of test accounts and fund them
state
,
_
:=
pool
.
currentState
()
key
,
_
:=
crypto
.
GenerateKey
()
addr
:=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
state
.
AddBalance
(
addr
,
big
.
NewInt
(
1000000
))
txs
:=
types
.
Transactions
{}
nonce
:=
uint64
(
0
)
for
j
:=
0
;
j
<
int
(
DefaultTxPoolConfig
.
GlobalSlots
)
*
2
;
j
++
{
tx
:=
transaction
(
nonce
,
big
.
NewInt
(
100000
),
key
)
txs
=
append
(
txs
,
tx
)
nonce
++
}
// Import the batch and verify that limits have been enforced
pool
.
AddBatch
(
txs
)
if
err
:=
pool
.
validateInternals
();
err
!=
nil
{
t
.
Error
(
err
)
}
}
// Tests that if the transaction count belonging to multiple accounts go above
// some hard threshold, if they are under the minimum guaranteed slot count then
// the transactions are still kept.
...
...
@@ -815,6 +860,10 @@ func TestTransactionPendingMinimumAllowance(t *testing.T) {
// Import the batch and verify that limits have been enforced
pool
.
AddBatch
(
txs
)
if
err
:=
pool
.
validateInternals
();
err
!=
nil
{
t
.
Error
(
err
)
}
for
addr
,
list
:=
range
pool
.
pending
{
if
list
.
Len
()
!=
int
(
DefaultTxPoolConfig
.
AccountSlots
)
{
t
.
Errorf
(
"addr %x: total pending transactions mismatch: have %d, want %d"
,
addr
,
list
.
Len
(),
DefaultTxPoolConfig
.
AccountSlots
)
...
...
@@ -860,6 +909,10 @@ func TestTransactionPoolRepricing(t *testing.T) {
// Import the batch and that both pending and queued transactions match up
pool
.
AddBatch
(
txs
)
if
err
:=
pool
.
validateInternals
();
err
!=
nil
{
t
.
Error
(
err
)
}
pending
,
queued
:=
pool
.
stats
()
if
pending
!=
4
{
t
.
Fatalf
(
"pending transactions mismatched: have %d, want %d"
,
pending
,
4
)
...
...
@@ -894,6 +947,10 @@ func TestTransactionPoolRepricing(t *testing.T) {
if
pending
,
_
=
pool
.
stats
();
pending
!=
3
{
t
.
Fatalf
(
"pending transactions mismatched: have %d, want %d"
,
pending
,
3
)
}
if
err
:=
pool
.
validateInternals
();
err
!=
nil
{
t
.
Error
(
err
)
}
}
// Tests that when the pool reaches its global transaction limit, underpriced
...
...
@@ -937,6 +994,9 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
// Import the batch and that both pending and queued transactions match up
pool
.
AddBatch
(
txs
)
if
err
:=
pool
.
validateInternals
();
err
!=
nil
{
t
.
Error
(
err
)
}
pending
,
queued
:=
pool
.
stats
()
if
pending
!=
3
{
...
...
@@ -980,6 +1040,9 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
if
queued
!=
2
{
t
.
Fatalf
(
"queued transactions mismatched: have %d, want %d"
,
queued
,
2
)
}
if
err
:=
pool
.
validateInternals
();
err
!=
nil
{
t
.
Error
(
err
)
}
}
// Tests that the pool rejects replacement transactions that don't meet the minimum
...
...
@@ -1041,6 +1104,9 @@ func TestTransactionReplacement(t *testing.T) {
if
err
:=
pool
.
Add
(
pricedTransaction
(
2
,
big
.
NewInt
(
100000
),
big
.
NewInt
(
threshold
+
1
),
key
));
err
!=
nil
{
t
.
Fatalf
(
"failed to replace original queued transaction: %v"
,
err
)
}
if
err
:=
pool
.
validateInternals
();
err
!=
nil
{
t
.
Error
(
err
)
}
}
// Benchmarks the speed of validating the contents of the pending queue of the
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录