Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
link33
plugin
Commits
01e20edd
Commit
01e20edd
authored
Dec 12, 2018
by
陈德海
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix test
parent
63a555bf
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
279 additions
and
34 deletions
+279
-34
cache.go
plugin/mempool/trade/cache.go
+4
-4
cache_test.go
plugin/mempool/trade/cache_test.go
+78
-0
chain33.test.toml
plugin/mempool/trade/chain33.test.toml
+193
-0
mempool_test.go
plugin/mempool/trade/mempool_test.go
+0
-27
chain33.test.toml
vendor/github.com/33cn/chain33/cmd/chain33/chain33.test.toml
+2
-2
base.go
vendor/github.com/33cn/chain33/system/mempool/base.go
+2
-1
No files found.
plugin/mempool/trade/cache.go
View file @
01e20edd
...
...
@@ -86,11 +86,11 @@ func (cache *TradeQueue) Push(item *mempool.Item) error {
if
err
!=
nil
{
return
err
}
if
cache
.
txList
.
Len
()
>=
cache
.
Size
()
{
tail
:=
cache
.
txList
.
tail
if
int64
(
cache
.
txList
.
Len
())
>=
cache
.
subConfig
.
PoolCacheSize
{
tail
:=
cache
.
txList
.
GetIterator
()
.
Last
()
//价格高
if
sv
.
Compare
(
tail
.
Value
)
==
1
{
cache
.
Remove
(
string
(
tail
.
Value
.
Value
.
(
*
mempool
.
Item
)
.
Value
.
Hash
()))
if
sv
.
Compare
(
tail
)
==
1
{
cache
.
Remove
(
string
(
tail
.
Value
.
(
*
mempool
.
Item
)
.
Value
.
Hash
()))
}
else
{
return
types
.
ErrMemFull
}
...
...
plugin/mempool/trade/cache_test.go
0 → 100644
View file @
01e20edd
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
trade
import
(
"testing"
drivers
"github.com/33cn/chain33/system/mempool"
"github.com/33cn/chain33/types"
"github.com/stretchr/testify/assert"
)
func
TestCache
(
t
*
testing
.
T
)
{
_
,
sub
:=
types
.
InitCfg
(
"chain33.test.toml"
)
var
subcfg
subConfig
types
.
MustDecode
(
sub
.
Mempool
[
"trade"
],
&
subcfg
)
subcfg
.
PoolCacheSize
=
1
cache
:=
NewTradeQueue
(
subcfg
)
tx
:=
&
types
.
Transaction
{
Payload
:
[]
byte
(
"123"
)}
hash
:=
string
(
tx
.
Hash
())
assert
.
Equal
(
t
,
false
,
cache
.
Exist
(
hash
))
item1
:=
&
drivers
.
Item
{
Value
:
tx
,
Priority
:
tx
.
Fee
,
EnterTime
:
types
.
Now
()
.
Unix
()}
err
:=
cache
.
Push
(
item1
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
true
,
cache
.
Exist
(
hash
))
it
,
err
:=
cache
.
GetItem
(
hash
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
item1
,
it
)
_
,
err
=
cache
.
GetItem
(
hash
+
":"
)
assert
.
Equal
(
t
,
types
.
ErrNotFound
,
err
)
err
=
cache
.
Push
(
item1
)
assert
.
Equal
(
t
,
types
.
ErrTxExist
,
err
)
tx2
:=
&
types
.
Transaction
{
Payload
:
[]
byte
(
"1234"
)}
item2
:=
&
drivers
.
Item
{
Value
:
tx2
,
Priority
:
tx
.
Fee
,
EnterTime
:
types
.
Now
()
.
Unix
()}
err
=
cache
.
Push
(
item2
)
assert
.
Equal
(
t
,
types
.
ErrMemFull
,
err
)
cache
.
Remove
(
hash
)
assert
.
Equal
(
t
,
0
,
cache
.
Size
())
//push to item
subcfg
.
PoolCacheSize
=
2
cache
=
NewTradeQueue
(
subcfg
)
cache
.
Push
(
item1
)
cache
.
Push
(
item2
)
assert
.
Equal
(
t
,
2
,
cache
.
Size
())
var
data
[
2
]
*
drivers
.
Item
i
:=
0
cache
.
Walk
(
1
,
func
(
value
*
drivers
.
Item
)
bool
{
data
[
i
]
=
value
i
++
return
true
})
assert
.
Equal
(
t
,
1
,
i
)
assert
.
Equal
(
t
,
data
[
0
],
item1
)
i
=
0
cache
.
Walk
(
2
,
func
(
value
*
drivers
.
Item
)
bool
{
data
[
i
]
=
value
i
++
return
true
})
assert
.
Equal
(
t
,
2
,
i
)
assert
.
Equal
(
t
,
data
[
0
],
item1
)
assert
.
Equal
(
t
,
data
[
1
],
item2
)
i
=
0
cache
.
Walk
(
2
,
func
(
value
*
drivers
.
Item
)
bool
{
data
[
i
]
=
value
i
++
return
false
})
assert
.
Equal
(
t
,
1
,
i
)
}
plugin/mempool/trade/chain33.test.toml
0 → 100644
View file @
01e20edd
Title
=
"chain33"
TestNet
=
true
[log]
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
loglevel
=
"debug"
logConsoleLevel
=
"info"
# 日志文件名,可带目录,所有生成的日志文件都放到此目录下
logFile
=
"logs/chain33.log"
# 单个日志文件的最大值(单位:兆)
maxFileSize
=
20
# 最多保存的历史日志文件个数
maxBackups
=
20
# 最多保存的历史日志消息(单位:天)
maxAge
=
28
# 日志文件名是否使用本地事件(否则使用UTC时间)
localTime
=
true
# 历史日志文件是否压缩(压缩格式为gz)
compress
=
false
# 是否打印调用源文件和行号
callerFile
=
true
# 是否打印调用方法
callerFunction
=
true
[blockchain]
defCacheSize
=
128
maxFetchBlockNum
=
128
timeoutSeconds
=
5
batchBlockNum
=
128
driver
=
"memdb"
dbPath
=
"datadir"
dbCache
=
64
isStrongConsistency
=
true
singleMode
=
true
batchsync
=
false
isRecordBlockSequence
=
true
isParaChain
=
false
enableTxQuickIndex
=
false
[p2p]
port
=
13802
seeds
=
["47.104.125.151:13802","47.104.125.97:13802","47.104.125.177:13802"]
enable
=
true
isSeed
=
true
serverStart
=
true
msgCacheSize
=
10240
driver
=
"memdb"
dbPath
=
"datadir/addrbook"
dbCache
=
4
grpcLogFile
=
"grpc33.log"
version
=
216
verMix
=
216
verMax
=
217
[rpc]
jrpcBindAddr
=
"localhost:8801"
grpcBindAddr
=
"localhost:8802"
whitelist
=
["127.0.0.1"]
jrpcFuncWhitelist
=
["*"]
grpcFuncWhitelist
=
["*"]
enableTLS
=
false
certFile
=
"cert.pem"
keyFile
=
"key.pem"
[mempool]
name
=
"trade"
poolCacheSize
=
10240
minTxFee
=
100000
maxTxNumPerAccount
=
10000
[mempool.sub.timeline]
poolCacheSize
=
10240
minTxFee
=
100000
maxTxNumPerAccount
=
10000
[mempool.sub.trade]
poolCacheSize
=
10240
minTxFee
=
100000
maxTxNumPerAccount
=
10000
timeParam
=
1
#时间占价格比例
priceConstant
=
1
#一个合适的常量
pricePower
=
0
#手续费占常量比例
[consensus]
name
=
"solo"
minerstart
=
true
genesisBlockTime
=
1514533394
genesis
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
[mver.consensus]
fundKeyAddr
=
"1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5"
coinReward
=
18
coinDevFund
=
12
ticketPrice
=
10000
powLimitBits
=
"0x1f00ffff"
retargetAdjustmentFactor
=
4
futureBlockTime
=
16
ticketFrozenTime
=
5
#5s only for test
ticketWithdrawTime
=
10
#10s only for test
ticketMinerWaitTime
=
2
#2s only for test
maxTxNumber
=
1600
#160
targetTimespan
=
2304
targetTimePerBlock
=
16
[mver.consensus.ForkChainParamV1]
maxTxNumber
=
10000
targetTimespan
=
288
#only for test
targetTimePerBlock
=
2
[mver.consensus.ForkChainParamV2]
powLimitBits
=
"0x1f2fffff"
[consensus.sub.solo]
genesis
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
genesisBlockTime
=
1514533394
hotkeyAddr
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
waitTxMs
=
10
[consensus.sub.ticket]
genesisBlockTime
=
1514533394
[[consensus.sub.ticket.genesis]]
minerAddr
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
returnAddr
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
count
=
10000
[[consensus.sub.ticket.genesis]]
minerAddr
=
"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
returnAddr
=
"1EbDHAXpoiewjPLX9uqoz38HsKqMXayZrF"
count
=
10000
[[consensus.sub.ticket.genesis]]
minerAddr
=
"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
returnAddr
=
"1KcCVZLSQYRUwE5EXTsAoQs9LuJW6xwfQa"
count
=
10000
[store]
name
=
"mavl"
driver
=
"memdb"
dbPath
=
"datadir/mavltree"
dbCache
=
128
[store.sub.mavl]
enableMavlPrefix
=
false
enableMVCC
=
false
enableMavlPrune
=
false
pruneHeight
=
10000
[wallet]
minFee
=
1000000
driver
=
"memdb"
dbPath
=
"datadir/wallet"
dbCache
=
16
signType
=
"secp256k1"
[wallet.sub.ticket]
minerwhitelist
=
["*"]
[exec]
isFree
=
false
minExecFee
=
100000
enableStat
=
false
enableMVCC
=
false
[exec.sub.token]
saveTokenTxList
=
true
tokenApprs
=
[
"1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S"
,
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"
,
"1LY8GFia5EiyoTodMLfkB5PHNNpXRqxhyB"
,
"1GCzJDS6HbgTQ2emade7mEJGGWFfA15pS9"
,
"1JYB8sxi4He5pZWHCd3Zi2nypQ4JMB6AxN"
,
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
,
]
[exec.sub.relay]
genesis
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
[exec.sub.cert]
# 是否启用证书验证和签名
enable
=
false
# 加密文件路径
cryptoPath
=
"authdir/crypto"
# 带证书签名类型,支持"auth_ecdsa", "auth_sm2"
signType
=
"auth_ecdsa"
[exec.sub.manage]
superManager
=[
"1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S"
,
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
,
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"
]
\ No newline at end of file
plugin/mempool/trade/mempool_test.go
deleted
100644 → 0
View file @
63a555bf
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
trade
import
(
"encoding/json"
"testing"
"github.com/33cn/chain33/system/mempool"
"github.com/33cn/chain33/types"
)
func
TestNewMempool
(
t
*
testing
.
T
)
{
sub
,
_
:=
json
.
Marshal
(
&
subConfig
{
PoolCacheSize
:
2
,
MinTxFee
:
100000
,
MaxTxNumPerAccount
:
10000
,
TimeParam
:
1
,
PriceConstant
:
1
,
PricePower
:
1
,
})
module
:=
New
(
&
types
.
Mempool
{},
sub
)
mem
:=
module
.
(
*
mempool
.
Mempool
)
mem
.
Close
()
}
vendor/github.com/33cn/chain33/cmd/chain33/chain33.test.toml
View file @
01e20edd
...
...
@@ -64,7 +64,7 @@ certFile="cert.pem"
keyFile
=
"key.pem"
[mempool]
name
=
"t
rad
e"
name
=
"t
imelin
e"
poolCacheSize
=
10240
minTxFee
=
100000
maxTxNumPerAccount
=
10000
...
...
@@ -80,7 +80,7 @@ minTxFee=100000
maxTxNumPerAccount
=
10000
timeParam
=
1
#时间占价格比例
priceConstant
=
1
#一个合适的常量
pricePower
=
1
#手续费占常量比例
pricePower
=
0
#手续费占常量比例
[consensus]
name
=
"solo"
...
...
vendor/github.com/33cn/chain33/system/mempool/base.go
View file @
01e20edd
...
...
@@ -89,7 +89,8 @@ func (mem *Mempool) SetQueueClient(client queue.Client) {
go
mem
.
checkSync
()
mem
.
wg
.
Add
(
1
)
go
mem
.
removeBlockedTxs
()
mem
.
wg
.
Add
(
1
)
go
mem
.
reply
()
mem
.
wg
.
Add
(
1
)
go
mem
.
eventProcess
()
}
...
...
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