Commit 8951f19a authored by jiangpeng's avatar jiangpeng Committed by 33cn

mempool-price:update get proper fee

parent f0a83b79
......@@ -74,11 +74,21 @@ func (cache *Queue) GetProperFee() int64 {
return cache.subConfig.ProperFee
}
i := 0
var txSize int
var feeRate int64
cache.Walk(100, func(item *mempool.Item) bool {
txSize = proto.Size(item.Value)
feeRate = item.Value.Fee / int64(txSize/1000+1)
//总单元费率的个数, 单个交易根据txsize/1000 + 1计算
unitFeeNum := proto.Size(item.Value)/1000 + 1
//交易组计算
if count := item.Value.GetGroupCount(); count > 0 {
unitFeeNum = int(count)
txs, err := item.Value.GetTxGroup()
if err != nil {
for _, tx := range txs.GetTxs() {
unitFeeNum += proto.Size(tx) / 1000
}
}
}
feeRate = item.Value.Fee / int64(unitFeeNum)
sumFeeRate += feeRate
i++
return true
......
......@@ -158,13 +158,17 @@ func TestQueueDirection(t *testing.T) {
func TestGetProperFee(t *testing.T) {
cache := initEnv(0)
assert.Equal(t, cache.subConfig.ProperFee, cache.GetProperFee())
txs, err := types.CreateTxGroup([]*types.Transaction{tx2, tx3, tx5}, 1200000)
assert.NoError(t, err)
tx := txs.Tx()
groupItem := &drivers.Item{Value: txs.Tx(), Priority: tx.Fee, EnterTime: types.Now().Unix() - 1000}
cache.Push(item1)
cache.Push(item4)
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())
cache.Push(groupItem)
properFee := cache.GetProperFee()
feeRate1 := item1.Value.Fee / int64(proto.Size(item1.Value)/1000+1)
feeRate2 := item4.Value.Fee / int64(proto.Size(item4.Value)/1000+1)
assert.Equal(t, (feeRate1+feeRate2+1200000)/3, properFee)
}
func TestRealNodeMempool(t *testing.T) {
......
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