Commit 86ea79a1 authored by 陈德海's avatar 陈德海

fix linter

parent 1c0c6d72
// 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 init package init
import ( import (
_ "github.com/33cn/plugin/plugin/mempool/price" _ "github.com/33cn/plugin/plugin/mempool/price" //auto gen
_ "github.com/33cn/plugin/plugin/mempool/score" _ "github.com/33cn/plugin/plugin/mempool/score" //auto gen
) )
...@@ -10,23 +10,23 @@ import ( ...@@ -10,23 +10,23 @@ import (
var mempoolDupResendInterval int64 = 600 // mempool内交易过期时间,10分钟 var mempoolDupResendInterval int64 = 600 // mempool内交易过期时间,10分钟
// PriceQueue 价格队列模式(价格=手续费/交易字节数,价格高者优先,同价则时间早优先) // Queue 价格队列模式(价格=手续费/交易字节数,价格高者优先,同价则时间早优先)
type PriceQueue struct { type Queue struct {
txMap map[string]*SkipValue txMap map[string]*SkipValue
txList *SkipList txList *SkipList
subConfig subConfig subConfig subConfig
} }
// NewPriceQueue 创建队列 // NewQueue 创建队列
func NewPriceQueue(subcfg subConfig) *PriceQueue { func NewQueue(subcfg subConfig) *Queue {
return &PriceQueue{ return &Queue{
txMap: make(map[string]*SkipValue, subcfg.PoolCacheSize), txMap: make(map[string]*SkipValue, subcfg.PoolCacheSize),
txList: NewSkipList(&SkipValue{-1, nil}), txList: NewSkipList(&SkipValue{-1, nil}),
subConfig: subcfg, subConfig: subcfg,
} }
} }
func (cache *PriceQueue) newSkipValue(item *mempool.Item) (*SkipValue, error) { func (cache *Queue) newSkipValue(item *mempool.Item) (*SkipValue, error) {
//tx := item.value //tx := item.value
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
enc := gob.NewEncoder(buf) enc := gob.NewEncoder(buf)
...@@ -39,21 +39,21 @@ func (cache *PriceQueue) newSkipValue(item *mempool.Item) (*SkipValue, error) { ...@@ -39,21 +39,21 @@ func (cache *PriceQueue) newSkipValue(item *mempool.Item) (*SkipValue, error) {
} }
//Exist 是否存在 //Exist 是否存在
func (cache *PriceQueue) Exist(hash string) bool { func (cache *Queue) Exist(hash string) bool {
_, exists := cache.txMap[hash] _, exists := cache.txMap[hash]
return exists return exists
} }
//GetItem 获取数据通过 key //GetItem 获取数据通过 key
func (cache *PriceQueue) GetItem(hash string) (*mempool.Item, error) { func (cache *Queue) GetItem(hash string) (*mempool.Item, error) {
if k, exist := cache.txMap[hash]; exist { if k, exist := cache.txMap[hash]; exist {
return k.Value.(*mempool.Item), nil return k.Value.(*mempool.Item), nil
} }
return nil, types.ErrNotFound return nil, types.ErrNotFound
} }
// Push 把给定tx添加到PriceQueue;如果tx已经存在PriceQueue中或Mempool已满则返回对应error // Push 把给定tx添加到Queue;如果tx已经存在Queue中或Mempool已满则返回对应error
func (cache *PriceQueue) Push(item *mempool.Item) error { func (cache *Queue) Push(item *mempool.Item) error {
hash := item.Value.Hash() hash := item.Value.Hash()
if cache.Exist(string(hash)) { if cache.Exist(string(hash)) {
s := cache.txMap[string(hash)] s := cache.txMap[string(hash)]
...@@ -98,19 +98,19 @@ func (cache *PriceQueue) Push(item *mempool.Item) error { ...@@ -98,19 +98,19 @@ func (cache *PriceQueue) Push(item *mempool.Item) error {
} }
// Remove 删除数据 // Remove 删除数据
func (cache *PriceQueue) Remove(hash string) error { func (cache *Queue) Remove(hash string) error {
cache.txList.Delete(cache.txMap[hash]) cache.txList.Delete(cache.txMap[hash])
delete(cache.txMap, hash) delete(cache.txMap, hash)
return nil return nil
} }
// Size 数据总数 // Size 数据总数
func (cache *PriceQueue) Size() int { func (cache *Queue) Size() int {
return cache.txList.Len() return cache.txList.Len()
} }
// Walk 遍历整个队列 // Walk 遍历整个队列
func (cache *PriceQueue) Walk(count int, cb func(value *mempool.Item) bool) { func (cache *Queue) Walk(count int, cb func(value *mempool.Item) bool) {
i := 0 i := 0
cache.txList.Walk(func(item interface{}) bool { cache.txList.Walk(func(item interface{}) bool {
if !cb(item.(*mempool.Item)) { if !cb(item.(*mempool.Item)) {
......
...@@ -33,7 +33,7 @@ var ( ...@@ -33,7 +33,7 @@ var (
item5 = &drivers.Item{Value: tx5, Priority: tx5.Fee, EnterTime: types.Now().Unix() - 1000} item5 = &drivers.Item{Value: tx5, Priority: tx5.Fee, EnterTime: types.Now().Unix() - 1000}
) )
func initEnv(size int64) *PriceQueue { func initEnv(size int64) *Queue {
if size == 0 { if size == 0 {
size = 100 size = 100
} }
...@@ -41,7 +41,7 @@ func initEnv(size int64) *PriceQueue { ...@@ -41,7 +41,7 @@ func initEnv(size int64) *PriceQueue {
var subcfg subConfig var subcfg subConfig
types.MustDecode(sub.Mempool["price"], &subcfg) types.MustDecode(sub.Mempool["price"], &subcfg)
subcfg.PoolCacheSize = size subcfg.PoolCacheSize = size
cache := NewPriceQueue(subcfg) cache := NewQueue(subcfg)
return cache return cache
} }
......
...@@ -27,6 +27,6 @@ func New(cfg *types.Mempool, sub []byte) queue.Module { ...@@ -27,6 +27,6 @@ func New(cfg *types.Mempool, sub []byte) queue.Module {
if subcfg.PoolCacheSize == 0 { if subcfg.PoolCacheSize == 0 {
subcfg.PoolCacheSize = cfg.PoolCacheSize subcfg.PoolCacheSize = cfg.PoolCacheSize
} }
c.SetQueueCache(NewPriceQueue(subcfg)) c.SetQueueCache(NewQueue(subcfg))
return c return c
} }
...@@ -10,23 +10,23 @@ import ( ...@@ -10,23 +10,23 @@ import (
var mempoolDupResendInterval int64 = 600 // mempool内交易过期时间,10分钟 var mempoolDupResendInterval int64 = 600 // mempool内交易过期时间,10分钟
// ScoreQueue 分数队列模式(分数=常量a*手续费/交易字节数-常量b*时间*定量c,按分数排队,高的优先,常量a,b和定量c可配置) // Queue 分数队列模式(分数=常量a*手续费/交易字节数-常量b*时间*定量c,按分数排队,高的优先,常量a,b和定量c可配置)
type ScoreQueue struct { type Queue struct {
txMap map[string]*SkipValue txMap map[string]*SkipValue
txList *SkipList txList *SkipList
subConfig subConfig subConfig subConfig
} }
// NewScoreQueue 创建队列 // NewQueue 创建队列
func NewScoreQueue(subcfg subConfig) *ScoreQueue { func NewQueue(subcfg subConfig) *Queue {
return &ScoreQueue{ return &Queue{
txMap: make(map[string]*SkipValue, subcfg.PoolCacheSize), txMap: make(map[string]*SkipValue, subcfg.PoolCacheSize),
txList: NewSkipList(&SkipValue{-1, nil}), txList: NewSkipList(&SkipValue{-1, nil}),
subConfig: subcfg, subConfig: subcfg,
} }
} }
func (cache *ScoreQueue) newSkipValue(item *mempool.Item) (*SkipValue, error) { func (cache *Queue) newSkipValue(item *mempool.Item) (*SkipValue, error) {
//tx := item.value //tx := item.value
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
enc := gob.NewEncoder(buf) enc := gob.NewEncoder(buf)
...@@ -39,21 +39,21 @@ func (cache *ScoreQueue) newSkipValue(item *mempool.Item) (*SkipValue, error) { ...@@ -39,21 +39,21 @@ func (cache *ScoreQueue) newSkipValue(item *mempool.Item) (*SkipValue, error) {
} }
// Exist 是否存在 // Exist 是否存在
func (cache *ScoreQueue) Exist(hash string) bool { func (cache *Queue) Exist(hash string) bool {
_, exists := cache.txMap[hash] _, exists := cache.txMap[hash]
return exists return exists
} }
//GetItem 获取数据通过 key //GetItem 获取数据通过 key
func (cache *ScoreQueue) GetItem(hash string) (*mempool.Item, error) { func (cache *Queue) GetItem(hash string) (*mempool.Item, error) {
if k, exist := cache.txMap[hash]; exist { if k, exist := cache.txMap[hash]; exist {
return k.Value.(*mempool.Item), nil return k.Value.(*mempool.Item), nil
} }
return nil, types.ErrNotFound return nil, types.ErrNotFound
} }
// Push 把给定tx添加到ScoreQueue;如果tx已经存在ScoreQueue中或Mempool已满则返回对应error // Push 把给定tx添加到Queue;如果tx已经存在Queue中或Mempool已满则返回对应error
func (cache *ScoreQueue) Push(item *mempool.Item) error { func (cache *Queue) Push(item *mempool.Item) error {
hash := item.Value.Hash() hash := item.Value.Hash()
if cache.Exist(string(hash)) { if cache.Exist(string(hash)) {
s := cache.txMap[string(hash)] s := cache.txMap[string(hash)]
...@@ -99,19 +99,19 @@ func (cache *ScoreQueue) Push(item *mempool.Item) error { ...@@ -99,19 +99,19 @@ func (cache *ScoreQueue) Push(item *mempool.Item) error {
} }
// Remove 删除数据 // Remove 删除数据
func (cache *ScoreQueue) Remove(hash string) error { func (cache *Queue) Remove(hash string) error {
cache.txList.Delete(cache.txMap[hash]) cache.txList.Delete(cache.txMap[hash])
delete(cache.txMap, hash) delete(cache.txMap, hash)
return nil return nil
} }
// Size 数据总数 // Size 数据总数
func (cache *ScoreQueue) Size() int { func (cache *Queue) Size() int {
return cache.txList.Len() return cache.txList.Len()
} }
// Walk 遍历整个队列 // Walk 遍历整个队列
func (cache *ScoreQueue) Walk(count int, cb func(value *mempool.Item) bool) { func (cache *Queue) Walk(count int, cb func(value *mempool.Item) bool) {
i := 0 i := 0
cache.txList.Walk(func(item interface{}) bool { cache.txList.Walk(func(item interface{}) bool {
if !cb(item.(*mempool.Item)) { if !cb(item.(*mempool.Item)) {
......
...@@ -33,7 +33,7 @@ var ( ...@@ -33,7 +33,7 @@ var (
item5 = &drivers.Item{Value: tx5, Priority: tx5.Fee, EnterTime: types.Now().Unix() - 1000} item5 = &drivers.Item{Value: tx5, Priority: tx5.Fee, EnterTime: types.Now().Unix() - 1000}
) )
func initEnv(size int64) *ScoreQueue { func initEnv(size int64) *Queue {
if size == 0 { if size == 0 {
size = 100 size = 100
} }
...@@ -41,7 +41,7 @@ func initEnv(size int64) *ScoreQueue { ...@@ -41,7 +41,7 @@ func initEnv(size int64) *ScoreQueue {
var subcfg subConfig var subcfg subConfig
types.MustDecode(sub.Mempool["score"], &subcfg) types.MustDecode(sub.Mempool["score"], &subcfg)
subcfg.PoolCacheSize = size subcfg.PoolCacheSize = size
cache := NewScoreQueue(subcfg) cache := NewQueue(subcfg)
return cache return cache
} }
......
...@@ -30,6 +30,6 @@ func New(cfg *types.Mempool, sub []byte) queue.Module { ...@@ -30,6 +30,6 @@ func New(cfg *types.Mempool, sub []byte) queue.Module {
if subcfg.PoolCacheSize == 0 { if subcfg.PoolCacheSize == 0 {
subcfg.PoolCacheSize = cfg.PoolCacheSize subcfg.PoolCacheSize = cfg.PoolCacheSize
} }
c.SetQueueCache(NewScoreQueue(subcfg)) c.SetQueueCache(NewQueue(subcfg))
return c return c
} }
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