Commit 8e35dc9d authored by 陈德海's avatar 陈德海 Committed by vipwzw

fix price getproperfee to feerate

parent 4c49bccd
......@@ -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 sumFeeRate int64
var properFeeRate 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 = sumFee / int64(i)
return properFee
properFeeRate = sumFeeRate / int64(i)
return properFeeRate
}
......@@ -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())
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment