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
8e35dc9d
Commit
8e35dc9d
authored
Jun 06, 2019
by
陈德海
Committed by
vipwzw
Jun 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix price getproperfee to feerate
parent
4c49bccd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
10 deletions
+17
-10
cache.go
plugin/mempool/price/cache.go
+13
-9
cache_test.go
plugin/mempool/price/cache_test.go
+4
-1
No files found.
plugin/mempool/price/cache.go
View file @
8e35dc9d
...
...
@@ -4,6 +4,7 @@ import (
"github.com/33cn/chain33/common/skiplist"
"github.com/33cn/chain33/system/mempool"
"github.com/33cn/chain33/types"
"github.com/golang/protobuf/proto"
)
var
mempoolDupResendInterval
int64
=
600
// mempool内交易过期时间,10分钟
...
...
@@ -25,9 +26,8 @@ func NewQueue(subcfg subConfig) *Queue {
}
func
(
cache
*
Queue
)
newSkipValue
(
item
*
mempool
.
Item
)
(
*
skiplist
.
SkipValue
,
error
)
{
buf
:=
types
.
Encode
(
item
.
Value
)
size
:=
len
(
buf
)
return
&
skiplist
.
SkipValue
{
Score
:
item
.
Value
.
Fee
/
int64
(
size
),
Value
:
item
},
nil
txSize
:=
proto
.
Size
(
item
.
Value
)
return
&
skiplist
.
SkipValue
{
Score
:
item
.
Value
.
Fee
/
int64
(
txSize
),
Value
:
item
},
nil
}
//Exist 是否存在
...
...
@@ -122,22 +122,26 @@ func (cache *Queue) Walk(count int, cb func(value *mempool.Item) bool) {
})
}
// GetProperFee 获取合适的手续费
,取前100的平均价格
// GetProperFee 获取合适的手续费
率,取前100的平均手续费率
func
(
cache
*
Queue
)
GetProperFee
()
int64
{
var
sumFee
int64
var
properFee
int64
var
sumFee
Rate
int64
var
properFee
Rate
int64
if
cache
.
Size
()
==
0
{
return
cache
.
subConfig
.
ProperFee
}
i
:=
0
var
txSize
int
var
feeRate
int64
cache
.
txList
.
Walk
(
func
(
tx
interface
{})
bool
{
if
i
==
100
{
return
false
}
sumFee
+=
tx
.
(
*
mempool
.
Item
)
.
Value
.
Fee
txSize
=
proto
.
Size
(
tx
.
(
*
mempool
.
Item
)
.
Value
)
feeRate
=
tx
.
(
*
mempool
.
Item
)
.
Value
.
Fee
/
int64
(
txSize
/
1000
+
1
)
sumFeeRate
+=
feeRate
i
++
return
true
})
properFee
=
sumFe
e
/
int64
(
i
)
return
properFee
properFee
Rate
=
sumFeeRat
e
/
int64
(
i
)
return
properFee
Rate
}
plugin/mempool/price/cache_test.go
View file @
8e35dc9d
...
...
@@ -10,6 +10,7 @@ import (
drivers
"github.com/33cn/chain33/system/mempool"
"github.com/33cn/chain33/types"
"github.com/stretchr/testify/assert"
"github.com/golang/protobuf/proto"
)
var
(
...
...
@@ -157,5 +158,7 @@ func TestGetProperFee(t *testing.T) {
cache
.
Push
(
item1
)
cache
.
Push
(
item4
)
cache
.
GetProperFee
()
assert
.
Equal
(
t
,
(
item1
.
Value
.
Fee
+
item4
.
Value
.
Fee
)
/
2
,
cache
.
GetProperFee
())
txSize1
:=
proto
.
Size
(
item1
.
Value
)
txSize2
:=
proto
.
Size
(
item4
.
Value
)
assert
.
Equal
(
t
,
(
item1
.
Value
.
Fee
/
int64
(
txSize1
/
1000
+
1
)
+
item4
.
Value
.
Fee
/
int64
(
txSize2
/
1000
+
1
))
/
2
,
cache
.
GetProperFee
())
}
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