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
e136c0de
Commit
e136c0de
authored
Mar 16, 2019
by
vipwzw
Browse files
Options
Browse Files
Download
Plain Diff
merge from master
parents
a9213c23
187ee1d3
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
103 additions
and
36 deletions
+103
-36
chain33.toml
chain33.toml
+1
-1
doc.go
plugin/dapp/token/doc.go
+1
-0
exec_local.go
plugin/dapp/token/executor/exec_local.go
+1
-1
cache.go
plugin/mempool/price/cache.go
+22
-11
cache_test.go
plugin/mempool/price/cache_test.go
+12
-2
chain33.test.toml
plugin/mempool/price/chain33.test.toml
+1
-1
mempool.go
plugin/mempool/price/mempool.go
+4
-0
cache.go
plugin/mempool/score/cache.go
+28
-12
cache_test.go
plugin/mempool/score/cache_test.go
+28
-7
chain33.test.toml
plugin/mempool/score/chain33.test.toml
+1
-1
mempool.go
plugin/mempool/score/mempool.go
+4
-0
No files found.
chain33.toml
View file @
e136c0de
...
...
@@ -73,7 +73,7 @@ poolCacheSize=10240
[mempool.sub.score]
poolCacheSize
=
10240
timeParam
=
1
#时间占价格比例
priceConstant
=
1
544
#手续费相对于时间的一个合适的常量,取当前unxi时间戳前四位数,排序时手续费高1e-5~=快1s
priceConstant
=
1
0
#手续费相对于时间的一个的常量,排队时手续费高1e3的分数~=快1h的分数
pricePower
=
1
#常量比例
[mempool.sub.price]
...
...
plugin/dapp/token/doc.go
View file @
e136c0de
...
...
@@ -6,6 +6,7 @@
//主要包含两方面功能
// 1. token 的创建
// 1. token 的转账
// 1. token 燃烧和增发
//
//token的创建
// 1. prepare create
...
...
plugin/dapp/token/executor/exec_local.go
View file @
e136c0de
...
...
@@ -113,7 +113,7 @@ func (t *token) ExecLocal_TokenFinishCreate(payload *tokenty.TokenFinishCreate,
table
:=
NewLogsTable
(
t
.
GetLocalDB
())
txIndex
:=
dapp
.
HeightIndexStr
(
t
.
GetHeight
(),
int64
(
index
))
err
=
table
.
Add
(
&
tokenty
.
LocalLogs
{
Symbol
:
payload
.
Symbol
,
TxIndex
:
txIndex
,
ActionType
:
tokenty
.
TokenActionFinishCreate
,
TxHash
:
hex
.
EncodeToString
(
tx
.
Hash
())})
err
=
table
.
Add
(
&
tokenty
.
LocalLogs
{
Symbol
:
payload
.
Symbol
,
TxIndex
:
txIndex
,
ActionType
:
tokenty
.
TokenActionFinishCreate
,
TxHash
:
"0x"
+
hex
.
EncodeToString
(
tx
.
Hash
())})
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/mempool/price/cache.go
View file @
e136c0de
package
price
import
(
"bytes"
"encoding/gob"
"github.com/33cn/chain33/common/skiplist"
"github.com/33cn/chain33/system/mempool"
"github.com/33cn/chain33/types"
...
...
@@ -28,14 +25,8 @@ func NewQueue(subcfg subConfig) *Queue {
}
func
(
cache
*
Queue
)
newSkipValue
(
item
*
mempool
.
Item
)
(
*
skiplist
.
SkipValue
,
error
)
{
//tx := item.value
buf
:=
bytes
.
NewBuffer
(
nil
)
enc
:=
gob
.
NewEncoder
(
buf
)
err
:=
enc
.
Encode
(
item
.
Value
)
if
err
!=
nil
{
return
nil
,
err
}
size
:=
len
(
buf
.
Bytes
())
buf
:=
types
.
Encode
(
item
.
Value
)
size
:=
len
(
buf
)
return
&
skiplist
.
SkipValue
{
Score
:
item
.
Value
.
Fee
/
int64
(
size
),
Value
:
item
},
nil
}
...
...
@@ -130,3 +121,23 @@ func (cache *Queue) Walk(count int, cb func(value *mempool.Item) bool) {
return
i
!=
count
})
}
// GetProperFee 获取合适的手续费,取前100的平均价格
func
(
cache
*
Queue
)
GetProperFee
()
int64
{
var
sumFee
int64
var
properFee
int64
if
cache
.
Size
()
==
0
{
return
cache
.
subConfig
.
ProperFee
}
i
:=
0
cache
.
txList
.
Walk
(
func
(
tx
interface
{})
bool
{
if
i
==
100
{
return
false
}
sumFee
+=
tx
.
(
*
mempool
.
Item
)
.
Value
.
Fee
i
++
return
true
})
properFee
=
sumFee
/
int64
(
i
)
return
properFee
}
plugin/mempool/price/cache_test.go
View file @
e136c0de
...
...
@@ -113,9 +113,9 @@ func TestTimeCompetition(t *testing.T) {
func
TestPriceCompetition
(
t
*
testing
.
T
)
{
cache
:=
initEnv
(
1
)
cache
.
Push
(
item
1
)
cache
.
Push
(
item
3
)
cache
.
Push
(
item4
)
assert
.
Equal
(
t
,
false
,
cache
.
Exist
(
string
(
item
1
.
Value
.
Hash
())))
assert
.
Equal
(
t
,
false
,
cache
.
Exist
(
string
(
item
3
.
Value
.
Hash
())))
assert
.
Equal
(
t
,
true
,
cache
.
Exist
(
string
(
item4
.
Value
.
Hash
())))
}
...
...
@@ -149,3 +149,13 @@ func TestQueueDirection(t *testing.T) {
assert
.
Equal
(
t
,
5
,
i
)
assert
.
Equal
(
t
,
true
,
lastScore
==
cache
.
txList
.
GetIterator
()
.
Last
()
.
Score
)
}
func
TestGetProperFee
(
t
*
testing
.
T
)
{
cache
:=
initEnv
(
0
)
assert
.
Equal
(
t
,
cache
.
subConfig
.
ProperFee
,
cache
.
GetProperFee
())
cache
.
Push
(
item1
)
cache
.
Push
(
item4
)
cache
.
GetProperFee
()
assert
.
Equal
(
t
,
(
item1
.
Value
.
Fee
+
item4
.
Value
.
Fee
)
/
2
,
cache
.
GetProperFee
())
}
plugin/mempool/price/chain33.test.toml
View file @
e136c0de
...
...
@@ -75,7 +75,7 @@ poolCacheSize=10240
[mempool.sub.score]
poolCacheSize
=
10240
timeParam
=
1
#时间占价格比例
priceConstant
=
1544
#手续费相对于时间的一个合适的常量,取当前unxi时间戳前四位数,排序时手续费高1e-5~=快1s
priceConstant
=
3
#手续费相对于时间的一个的常量,排队时手续费高1e3的分数~=快1h的分数
pricePower
=
1
#常量比例
[mempool.sub.price]
...
...
plugin/mempool/price/mempool.go
View file @
e136c0de
...
...
@@ -11,6 +11,7 @@ import (
type
subConfig
struct
{
PoolCacheSize
int64
`json:"poolCacheSize"`
ProperFee
int64
`json:"properFee"`
}
func
init
()
{
...
...
@@ -25,6 +26,9 @@ func New(cfg *types.Mempool, sub []byte) queue.Module {
if
subcfg
.
PoolCacheSize
==
0
{
subcfg
.
PoolCacheSize
=
cfg
.
PoolCacheSize
}
if
subcfg
.
ProperFee
==
0
{
subcfg
.
ProperFee
=
cfg
.
MinTxFee
}
c
.
SetQueueCache
(
NewQueue
(
subcfg
))
return
c
}
plugin/mempool/score/cache.go
View file @
e136c0de
package
score
import
(
"bytes"
"encoding/gob"
"time"
"github.com/33cn/chain33/common/skiplist"
"github.com/33cn/chain33/system/mempool"
...
...
@@ -11,7 +10,7 @@ import (
var
mempoolDupResendInterval
int64
=
600
// mempool内交易过期时间,10分钟
// Queue 分数队列模式(分数=
常量a*手续费/交易字节数-常量b*时间*定量c,按分数排队,高的优先,常量a,b和定量
c可配置)
// Queue 分数队列模式(分数=
定量a*常量b*手续费/交易字节数-常量c*时间,按分数排队,高的优先,定量a和常量b,
c可配置)
type
Queue
struct
{
txMap
map
[
string
]
*
skiplist
.
SkipValue
txList
*
skiplist
.
SkipList
...
...
@@ -28,15 +27,10 @@ func NewQueue(subcfg subConfig) *Queue {
}
func
(
cache
*
Queue
)
newSkipValue
(
item
*
mempool
.
Item
)
(
*
skiplist
.
SkipValue
,
error
)
{
//tx := item.value
buf
:=
bytes
.
NewBuffer
(
nil
)
enc
:=
gob
.
NewEncoder
(
buf
)
err
:=
enc
.
Encode
(
item
.
Value
)
if
err
!=
nil
{
return
nil
,
err
}
size
:=
len
(
buf
.
Bytes
())
return
&
skiplist
.
SkipValue
{
Score
:
cache
.
subConfig
.
PriceConstant
*
(
item
.
Value
.
Fee
/
int64
(
size
))
*
cache
.
subConfig
.
PricePower
-
cache
.
subConfig
.
TimeParam
*
item
.
EnterTime
,
Value
:
item
},
nil
buf
:=
types
.
Encode
(
item
.
Value
)
size
:=
len
(
buf
)
return
&
skiplist
.
SkipValue
{
Score
:
cache
.
subConfig
.
PriceConstant
*
(
item
.
Value
.
Fee
/
int64
(
size
))
*
cache
.
subConfig
.
PricePower
-
cache
.
subConfig
.
TimeParam
*
item
.
EnterTime
,
Value
:
item
},
nil
}
// Exist 是否存在
...
...
@@ -122,3 +116,25 @@ func (cache *Queue) Walk(count int, cb func(value *mempool.Item) bool) {
return
i
!=
count
})
}
// GetProperFee 获取合适的手续费
func
(
cache
*
Queue
)
GetProperFee
()
int64
{
var
sumScore
int64
var
properFee
int64
if
cache
.
Size
()
==
0
{
return
cache
.
subConfig
.
ProperFee
}
i
:=
0
cache
.
txList
.
WalkS
(
func
(
node
interface
{})
bool
{
if
i
==
100
{
return
false
}
sumScore
+=
node
.
(
*
skiplist
.
SkipValue
)
.
Score
i
++
return
true
})
//这里的int64(250)是一般交易的大小
properFee
=
(
sumScore
/
int64
(
i
)
+
cache
.
subConfig
.
TimeParam
*
time
.
Now
()
.
Unix
())
*
int64
(
250
)
/
(
cache
.
subConfig
.
PriceConstant
*
cache
.
subConfig
.
PricePower
)
return
properFee
}
plugin/mempool/score/cache_test.go
View file @
e136c0de
...
...
@@ -2,6 +2,7 @@ package score
import
(
"testing"
"time"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/address"
...
...
@@ -21,11 +22,11 @@ var (
amount
=
int64
(
1e8
)
v
=
&
cty
.
CoinsAction_Transfer
{
Transfer
:
&
types
.
AssetsTransfer
{
Amount
:
amount
}}
transfer
=
&
cty
.
CoinsAction
{
Value
:
v
,
Ty
:
cty
.
CoinsActionTransfer
}
tx1
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"coins"
),
Payload
:
types
.
Encode
(
transfer
),
Fee
:
100000
0
,
Expire
:
1
,
To
:
toAddr
}
tx2
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"coins"
),
Payload
:
types
.
Encode
(
transfer
),
Fee
:
100000
0
,
Expire
:
2
,
To
:
toAddr
}
tx3
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"coins"
),
Payload
:
types
.
Encode
(
transfer
),
Fee
:
100000
0
,
Expire
:
3
,
To
:
toAddr
}
tx4
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"coins"
),
Payload
:
types
.
Encode
(
transfer
),
Fee
:
200000
0
,
Expire
:
4
,
To
:
toAddr
}
tx5
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"coins"
),
Payload
:
types
.
Encode
(
transfer
),
Fee
:
100000
0
,
Expire
:
5
,
To
:
toAddr
}
tx1
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"coins"
),
Payload
:
types
.
Encode
(
transfer
),
Fee
:
100000
,
Expire
:
1
,
To
:
toAddr
}
tx2
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"coins"
),
Payload
:
types
.
Encode
(
transfer
),
Fee
:
100000
,
Expire
:
2
,
To
:
toAddr
}
tx3
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"coins"
),
Payload
:
types
.
Encode
(
transfer
),
Fee
:
100000
,
Expire
:
3
,
To
:
toAddr
}
tx4
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"coins"
),
Payload
:
types
.
Encode
(
transfer
),
Fee
:
200000
,
Expire
:
4
,
To
:
toAddr
}
tx5
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"coins"
),
Payload
:
types
.
Encode
(
transfer
),
Fee
:
100000
,
Expire
:
5
,
To
:
toAddr
}
item1
=
&
drivers
.
Item
{
Value
:
tx1
,
Priority
:
tx1
.
Fee
,
EnterTime
:
types
.
Now
()
.
Unix
()}
item2
=
&
drivers
.
Item
{
Value
:
tx2
,
Priority
:
tx2
.
Fee
,
EnterTime
:
types
.
Now
()
.
Unix
()}
item3
=
&
drivers
.
Item
{
Value
:
tx3
,
Priority
:
tx3
.
Fee
,
EnterTime
:
types
.
Now
()
.
Unix
()
-
1000
}
...
...
@@ -113,9 +114,9 @@ func TestTimeCompetition(t *testing.T) {
func
TestPriceCompetition
(
t
*
testing
.
T
)
{
cache
:=
initEnv
(
1
)
cache
.
Push
(
item
1
)
cache
.
Push
(
item
3
)
cache
.
Push
(
item4
)
assert
.
Equal
(
t
,
false
,
cache
.
Exist
(
string
(
item
1
.
Value
.
Hash
())))
assert
.
Equal
(
t
,
false
,
cache
.
Exist
(
string
(
item
3
.
Value
.
Hash
())))
assert
.
Equal
(
t
,
true
,
cache
.
Exist
(
string
(
item4
.
Value
.
Hash
())))
}
...
...
@@ -149,3 +150,23 @@ func TestQueueDirection(t *testing.T) {
assert
.
Equal
(
t
,
5
,
i
)
assert
.
Equal
(
t
,
true
,
lastScore
==
cache
.
txList
.
GetIterator
()
.
Last
()
.
Score
)
}
func
TestGetProperFee
(
t
*
testing
.
T
)
{
cache
:=
initEnv
(
0
)
assert
.
Equal
(
t
,
cache
.
subConfig
.
ProperFee
,
cache
.
GetProperFee
())
cache
.
Push
(
item3
)
cache
.
Push
(
item4
)
cache
.
GetProperFee
()
buf3
:=
types
.
Encode
(
item3
.
Value
)
size3
:=
len
(
buf3
)
buf4
:=
types
.
Encode
(
item4
.
Value
)
size4
:=
len
(
buf4
)
score3
:=
item3
.
Value
.
Fee
*
cache
.
subConfig
.
PriceConstant
*
cache
.
subConfig
.
PricePower
/
int64
(
size3
)
-
item3
.
EnterTime
*
cache
.
subConfig
.
TimeParam
score4
:=
item4
.
Value
.
Fee
*
cache
.
subConfig
.
PriceConstant
*
cache
.
subConfig
.
PricePower
/
int64
(
size4
)
-
item4
.
EnterTime
*
cache
.
subConfig
.
TimeParam
properFee
:=
((
score3
+
score4
)
/
2
+
time
.
Now
()
.
Unix
()
*
cache
.
subConfig
.
TimeParam
)
*
int64
(
250
)
/
(
cache
.
subConfig
.
PriceConstant
*
cache
.
subConfig
.
PricePower
)
assert
.
Equal
(
t
,
int64
(
1
),
properFee
/
cache
.
GetProperFee
())
}
plugin/mempool/score/chain33.test.toml
View file @
e136c0de
...
...
@@ -75,7 +75,7 @@ poolCacheSize=10240
[mempool.sub.score]
poolCacheSize
=
10240
timeParam
=
1
#时间占价格比例
priceConstant
=
1
544
#手续费相对于时间的一个合适的常量,取当前unxi时间戳前四位数,排队时手续费高1e-5的分数~=快1s
的分数
priceConstant
=
1
0
#手续费相对于时间的一个的常量,排队时手续费高1e3的分数~=快1h
的分数
pricePower
=
1
#常量比例
[mempool.sub.price]
...
...
plugin/mempool/score/mempool.go
View file @
e136c0de
...
...
@@ -14,6 +14,7 @@ type subConfig struct {
TimeParam
int64
`json:"timeParam"`
PriceConstant
int64
`json:"priceConstant"`
PricePower
int64
`json:"pricePower"`
ProperFee
int64
`json:"properFee"`
}
func
init
()
{
...
...
@@ -28,6 +29,9 @@ func New(cfg *types.Mempool, sub []byte) queue.Module {
if
subcfg
.
PoolCacheSize
==
0
{
subcfg
.
PoolCacheSize
=
cfg
.
PoolCacheSize
}
if
subcfg
.
ProperFee
==
0
{
subcfg
.
ProperFee
=
cfg
.
MinTxFee
}
c
.
SetQueueCache
(
NewQueue
(
subcfg
))
return
c
}
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