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
86ea79a1
Commit
86ea79a1
authored
Dec 14, 2018
by
陈德海
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix linter
parent
1c0c6d72
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
34 additions
and
38 deletions
+34
-38
init.go
plugin/mempool/init/init.go
+2
-6
cache.go
plugin/mempool/price/cache.go
+13
-13
cache_test.go
plugin/mempool/price/cache_test.go
+2
-2
mempool.go
plugin/mempool/price/mempool.go
+1
-1
cache.go
plugin/mempool/score/cache.go
+13
-13
cache_test.go
plugin/mempool/score/cache_test.go
+2
-2
mempool.go
plugin/mempool/score/mempool.go
+1
-1
No files found.
plugin/mempool/init/init.go
View file @
86ea79a1
// 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
)
)
plugin/mempool/price/cache.go
View file @
86ea79a1
...
@@ -10,23 +10,23 @@ import (
...
@@ -10,23 +10,23 @@ import (
var
mempoolDupResendInterval
int64
=
600
// mempool内交易过期时间,10分钟
var
mempoolDupResendInterval
int64
=
600
// mempool内交易过期时间,10分钟
//
Price
Queue 价格队列模式(价格=手续费/交易字节数,价格高者优先,同价则时间早优先)
// Queue 价格队列模式(价格=手续费/交易字节数,价格高者优先,同价则时间早优先)
type
Price
Queue
struct
{
type
Queue
struct
{
txMap
map
[
string
]
*
SkipValue
txMap
map
[
string
]
*
SkipValue
txList
*
SkipList
txList
*
SkipList
subConfig
subConfig
subConfig
subConfig
}
}
// New
Price
Queue 创建队列
// NewQueue 创建队列
func
New
PriceQueue
(
subcfg
subConfig
)
*
Price
Queue
{
func
New
Queue
(
subcfg
subConfig
)
*
Queue
{
return
&
Price
Queue
{
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
*
Price
Queue
)
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
*
Price
Queue
)
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
*
Price
Queue
)
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已经存在Price
Queue中或Mempool已满则返回对应error
// Push 把给定tx添加到
Queue;如果tx已经存在
Queue中或Mempool已满则返回对应error
func
(
cache
*
Price
Queue
)
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
*
Price
Queue
)
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
*
Price
Queue
)
Size
()
int
{
func
(
cache
*
Queue
)
Size
()
int
{
return
cache
.
txList
.
Len
()
return
cache
.
txList
.
Len
()
}
}
// Walk 遍历整个队列
// Walk 遍历整个队列
func
(
cache
*
Price
Queue
)
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
))
{
...
...
plugin/mempool/price/cache_test.go
View file @
86ea79a1
...
@@ -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
)
*
Price
Queue
{
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
:=
New
Price
Queue
(
subcfg
)
cache
:=
NewQueue
(
subcfg
)
return
cache
return
cache
}
}
...
...
plugin/mempool/price/mempool.go
View file @
86ea79a1
...
@@ -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
(
New
Price
Queue
(
subcfg
))
c
.
SetQueueCache
(
NewQueue
(
subcfg
))
return
c
return
c
}
}
plugin/mempool/score/cache.go
View file @
86ea79a1
...
@@ -10,23 +10,23 @@ import (
...
@@ -10,23 +10,23 @@ import (
var
mempoolDupResendInterval
int64
=
600
// mempool内交易过期时间,10分钟
var
mempoolDupResendInterval
int64
=
600
// mempool内交易过期时间,10分钟
//
Score
Queue 分数队列模式(分数=常量a*手续费/交易字节数-常量b*时间*定量c,按分数排队,高的优先,常量a,b和定量c可配置)
// Queue 分数队列模式(分数=常量a*手续费/交易字节数-常量b*时间*定量c,按分数排队,高的优先,常量a,b和定量c可配置)
type
Score
Queue
struct
{
type
Queue
struct
{
txMap
map
[
string
]
*
SkipValue
txMap
map
[
string
]
*
SkipValue
txList
*
SkipList
txList
*
SkipList
subConfig
subConfig
subConfig
subConfig
}
}
// New
Score
Queue 创建队列
// NewQueue 创建队列
func
New
ScoreQueue
(
subcfg
subConfig
)
*
Score
Queue
{
func
New
Queue
(
subcfg
subConfig
)
*
Queue
{
return
&
Score
Queue
{
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
*
Score
Queue
)
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
*
Score
Queue
)
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
*
Score
Queue
)
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已经存在Score
Queue中或Mempool已满则返回对应error
// Push 把给定tx添加到
Queue;如果tx已经存在
Queue中或Mempool已满则返回对应error
func
(
cache
*
Score
Queue
)
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
*
Score
Queue
)
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
*
Score
Queue
)
Size
()
int
{
func
(
cache
*
Queue
)
Size
()
int
{
return
cache
.
txList
.
Len
()
return
cache
.
txList
.
Len
()
}
}
// Walk 遍历整个队列
// Walk 遍历整个队列
func
(
cache
*
Score
Queue
)
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
))
{
...
...
plugin/mempool/score/cache_test.go
View file @
86ea79a1
...
@@ -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
)
*
Score
Queue
{
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
:=
New
Score
Queue
(
subcfg
)
cache
:=
NewQueue
(
subcfg
)
return
cache
return
cache
}
}
...
...
plugin/mempool/score/mempool.go
View file @
86ea79a1
...
@@ -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
(
New
Score
Queue
(
subcfg
))
c
.
SetQueueCache
(
NewQueue
(
subcfg
))
return
c
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