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
7387817f
Commit
7387817f
authored
Nov 17, 2021
by
mdj33
Committed by
33cn
Nov 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split bind node reward
parent
ddcea039
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
40 deletions
+62
-40
chain33.para.toml
chain33.para.toml
+1
-1
bindminer.go
plugin/dapp/paracross/executor/bindminer.go
+8
-29
nomal.go
plugin/dapp/paracross/executor/minerrewards/nomal.go
+1
-1
reward.go
plugin/dapp/paracross/executor/reward.go
+51
-8
reward_test.go
plugin/dapp/paracross/executor/reward_test.go
+1
-1
No files found.
chain33.para.toml
View file @
7387817f
...
@@ -97,7 +97,7 @@ coinDevFund=12
...
@@ -97,7 +97,7 @@ coinDevFund=12
coinBaseReward
=
3
coinBaseReward
=
3
#委托账户最少解绑定时间(按小时)
#委托账户最少解绑定时间(按小时)
unBindTime
=
24
unBindTime
=
24
#支持挖矿奖励的1e8小数模式,比如18coin 需要配置成1800000000 以支持小数位后的配置,如果true,意味着已经打开即coinReward=1800000000
#支持挖矿奖励的1e8小数模式,比如18coin 需要配置成1800000000 以支持小数位后的配置,如果true,意味着已经打开即
须配置
coinReward=1800000000
decimalMode
=
false
decimalMode
=
false
#挖矿模式, normal:缺省挖矿,其他自定义,注册名字需要和配置名字保持一致
#挖矿模式, normal:缺省挖矿,其他自定义,注册名字需要和配置名字保持一致
minerMode
=
"normal"
minerMode
=
"normal"
...
...
plugin/dapp/paracross/executor/bindminer.go
View file @
7387817f
...
@@ -14,50 +14,29 @@ const (
...
@@ -14,50 +14,29 @@ const (
opModify
=
3
opModify
=
3
)
)
//根据挖矿共识节点地址 过滤整体共识节点映射列表, 获取委托挖矿地址
//func (a *action) getBindAddrs(nodes []string, statusHeight int64) ([]*pt.ParaBindMinerInfo, error) {
// nodesMap := make(map[string]bool)
// for _, n := range nodes {
// nodesMap[n] = true
// }
//
// var newLists pt.ParaNodeBindList
// list, err := getBindNodeInfo(a.db)
// if err != nil {
// clog.Error("paracross getBindAddrs err", "height", statusHeight)
// return nil, err
// }
// //这样检索是按照list的映射顺序,不是按照nodes的顺序(需要循环嵌套)
// for _, m := range list.Miners {
// if nodesMap[m.SuperNode] {
// newLists.Miners = append(newLists.Miners, m)
// }
// }
//
// return &newLists, nil
//
//}
//从内存中获取bin状态的miner list
//从内存中获取bin状态的miner list
func
(
a
*
action
)
getBindAddrs
(
nodes
[]
string
,
statusHeight
int64
)
([]
*
pt
.
ParaBindMinerInfo
,
error
)
{
func
(
a
*
action
)
getBindAddrs
(
nodes
[]
string
,
statusHeight
int64
)
(
bool
,
map
[
string
][]
*
pt
.
ParaBindMinerInfo
,
error
)
{
var
minerList
[]
*
pt
.
ParaBindMinerInfo
nodeBinders
:=
make
(
map
[
string
][]
*
pt
.
ParaBindMinerInfo
)
var
foundBinder
bool
for
_
,
node
:=
range
nodes
{
for
_
,
node
:=
range
nodes
{
var
minerList
[]
*
pt
.
ParaBindMinerInfo
list
,
err
:=
getBindMinerList
(
a
.
db
,
node
)
list
,
err
:=
getBindMinerList
(
a
.
db
,
node
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"paracross getBindAddrs err"
,
"height"
,
statusHeight
,
"err"
,
err
)
clog
.
Error
(
"paracross getBindAddrs err"
,
"height"
,
statusHeight
,
"err"
,
err
)
return
nil
,
err
return
false
,
nil
,
err
}
}
for
_
,
l
:=
range
list
{
for
_
,
l
:=
range
list
{
//过滤所有bind状态的miner
//过滤所有bind状态的miner
if
l
.
BindStatus
==
opBind
{
if
l
.
BindStatus
==
opBind
{
foundBinder
=
true
minerList
=
append
(
minerList
,
l
)
minerList
=
append
(
minerList
,
l
)
}
}
}
}
nodeBinders
[
node
]
=
minerList
}
}
return
minerList
,
nil
return
foundBinder
,
nodeBinders
,
nil
}
}
//
func
mergeReceipt
(
receipt1
,
receipt2
*
types
.
Receipt
)
*
types
.
Receipt
{
func
mergeReceipt
(
receipt1
,
receipt2
*
types
.
Receipt
)
*
types
.
Receipt
{
if
receipt2
!=
nil
{
if
receipt2
!=
nil
{
receipt1
.
KV
=
append
(
receipt1
.
KV
,
receipt2
.
KV
...
)
receipt1
.
KV
=
append
(
receipt1
.
KV
,
receipt2
.
KV
...
)
...
...
plugin/dapp/paracross/executor/minerrewards/nomal.go
View file @
7387817f
...
@@ -30,7 +30,7 @@ func (n *normal) GetConfigReward(cfg *types.Chain33Config, height int64) (int64,
...
@@ -30,7 +30,7 @@ func (n *normal) GetConfigReward(cfg *types.Chain33Config, height int64) (int64,
}
}
//防止coinBaseReward 设置出错场景, coinBaseReward 一定要比coinReward小
//防止coinBaseReward 设置出错场景, coinBaseReward 一定要比coinReward小
if
coinBaseReward
>=
coinReward
{
if
coinBaseReward
>=
coinReward
{
coinBaseReward
=
coinReward
/
10
panic
(
"mver.consensus.paracross.coinBaseReward should < coinReward"
)
}
}
return
coinReward
,
fundReward
,
coinBaseReward
return
coinReward
,
fundReward
,
coinBaseReward
}
}
...
...
plugin/dapp/paracross/executor/reward.go
View file @
7387817f
...
@@ -40,8 +40,45 @@ func (a *action) rewardDeposit(rewards []*pt.ParaMinerReward, statusHeight int64
...
@@ -40,8 +40,45 @@ func (a *action) rewardDeposit(rewards []*pt.ParaMinerReward, statusHeight int64
}
}
//奖励委托挖矿账户
//奖励委托挖矿账户
func
(
a
*
action
)
rewardBindAddr
(
coinReward
int64
,
bindAddrList
[]
*
pt
.
ParaBindMinerInfo
,
statusHeight
int64
)
(
*
types
.
Receipt
,
int64
,
error
)
{
func
(
a
*
action
)
rewardBindAddr
(
coinReward
int64
,
nodes
[]
string
,
bindNodeList
map
[
string
][]
*
pt
.
ParaBindMinerInfo
,
statusHeight
int64
)
(
*
types
.
Receipt
,
int64
,
error
)
{
if
coinReward
<=
0
{
if
coinReward
<=
0
||
len
(
bindNodeList
)
<=
0
{
return
nil
,
0
,
nil
}
//分配给矿工的单位奖励
nodeUnit
:=
coinReward
/
int64
(
len
(
bindNodeList
))
var
nodeUnitChange
int64
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
if
nodeUnit
>
0
{
//如果不等分转到发展基金
nodeUnitChange
=
coinReward
%
nodeUnit
//需要nodes遍历,不然用map会导致分叉
for
_
,
node
:=
range
nodes
{
//如果node没有bind,则奖励都分给node
if
len
(
bindNodeList
[
node
])
<=
0
{
rwd
:=
&
pt
.
ParaMinerReward
{
Addr
:
node
,
Amount
:
nodeUnit
}
r
,
err
:=
a
.
rewardDeposit
([]
*
pt
.
ParaMinerReward
{
rwd
},
statusHeight
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
receipt
=
mergeReceipt
(
receipt
,
r
)
continue
}
//如果node有binder,则奖励平均分给binder
r
,
change
,
err
:=
a
.
rewardBindAddrList
(
nodeUnit
,
node
,
bindNodeList
[
node
],
statusHeight
)
if
err
!=
nil
{
clog
.
Error
(
"paracross bind miner reward deposit err"
,
"node"
,
node
)
return
nil
,
0
,
err
}
receipt
=
mergeReceipt
(
receipt
,
r
)
nodeUnitChange
+=
change
}
}
return
receipt
,
nodeUnitChange
,
nil
}
func
(
a
*
action
)
rewardBindAddrList
(
coinReward
int64
,
node
string
,
bindAddrList
[]
*
pt
.
ParaBindMinerInfo
,
statusHeight
int64
)
(
*
types
.
Receipt
,
int64
,
error
)
{
if
coinReward
<=
0
||
len
(
bindAddrList
)
<=
0
{
return
nil
,
0
,
nil
return
nil
,
0
,
nil
}
}
...
@@ -50,6 +87,11 @@ func (a *action) rewardBindAddr(coinReward int64, bindAddrList []*pt.ParaBindMin
...
@@ -50,6 +87,11 @@ func (a *action) rewardBindAddr(coinReward int64, bindAddrList []*pt.ParaBindMin
totalCoins
+=
addr
.
BindCoins
totalCoins
+=
addr
.
BindCoins
}
}
if
totalCoins
<=
0
{
clog
.
Info
(
"paracross bind miner reward deposit total zero"
,
"node"
,
node
)
return
nil
,
0
,
nil
}
//分配给矿工的单位奖励
//分配给矿工的单位奖励
minerUnit
:=
coinReward
/
totalCoins
minerUnit
:=
coinReward
/
totalCoins
var
change
int64
var
change
int64
...
@@ -89,7 +131,7 @@ func (a *action) reward(nodeStatus *pt.ParacrossNodeStatus, stat *pt.ParacrossHe
...
@@ -89,7 +131,7 @@ func (a *action) reward(nodeStatus *pt.ParacrossNodeStatus, stat *pt.ParacrossHe
//超级节点地址
//超级节点地址
nodeAddrs
:=
getSuperNodes
(
stat
.
Details
,
nodeStatus
.
BlockHash
)
nodeAddrs
:=
getSuperNodes
(
stat
.
Details
,
nodeStatus
.
BlockHash
)
//委托地址
//委托地址
bindAddrs
,
err
:=
a
.
getBindAddrs
(
nodeAddrs
,
nodeStatus
.
Height
)
foundBinder
,
bindAddrs
,
err
:=
a
.
getBindAddrs
(
nodeAddrs
,
nodeStatus
.
Height
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -101,10 +143,10 @@ func (a *action) reward(nodeStatus *pt.ParacrossNodeStatus, stat *pt.ParacrossHe
...
@@ -101,10 +143,10 @@ func (a *action) reward(nodeStatus *pt.ParacrossNodeStatus, stat *pt.ParacrossHe
}
}
//奖励超级节点
//奖励超级节点
minder
Rewards
:=
coinReward
superNode
Rewards
:=
coinReward
//如果有委托挖矿地址,则超级节点分baseReward部分,否则全部
//如果有委托挖矿地址,则超级节点分baseReward部分,否则全部
if
len
(
bindAddrs
)
>
0
{
if
foundBinder
{
minder
Rewards
=
coinBaseReward
superNode
Rewards
=
coinBaseReward
}
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
...
@@ -112,7 +154,7 @@ func (a *action) reward(nodeStatus *pt.ParacrossNodeStatus, stat *pt.ParacrossHe
...
@@ -112,7 +154,7 @@ func (a *action) reward(nodeStatus *pt.ParacrossNodeStatus, stat *pt.ParacrossHe
for
_
,
addr
:=
range
supervisionAddrs
{
for
_
,
addr
:=
range
supervisionAddrs
{
miners
=
append
(
miners
,
addr
)
miners
=
append
(
miners
,
addr
)
}
}
r
,
change
,
err
:=
a
.
rewardSuperNode
(
minder
Rewards
,
miners
,
nodeStatus
.
Height
)
r
,
change
,
err
:=
a
.
rewardSuperNode
(
superNode
Rewards
,
miners
,
nodeStatus
.
Height
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -120,7 +162,8 @@ func (a *action) reward(nodeStatus *pt.ParacrossNodeStatus, stat *pt.ParacrossHe
...
@@ -120,7 +162,8 @@ func (a *action) reward(nodeStatus *pt.ParacrossNodeStatus, stat *pt.ParacrossHe
mergeReceipt
(
receipt
,
r
)
mergeReceipt
(
receipt
,
r
)
//奖励委托挖矿地址
//奖励委托挖矿地址
r
,
change
,
err
=
a
.
rewardBindAddr
(
coinReward
-
minderRewards
,
bindAddrs
,
nodeStatus
.
Height
)
//为了统一处理,若无委托挖矿地址,则不影响当前版本,若部分节点有委托挖矿,则委托挖矿地址平分节点的奖励,无绑定挖矿的节点,再补上本来给委托挖矿的奖励
r
,
change
,
err
=
a
.
rewardBindAddr
(
coinReward
-
superNodeRewards
,
nodeAddrs
,
bindAddrs
,
nodeStatus
.
Height
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
plugin/dapp/paracross/executor/reward_test.go
View file @
7387817f
...
@@ -87,7 +87,7 @@ func (suite *RewardTestSuite) TestRewardBindAddr() {
...
@@ -87,7 +87,7 @@ func (suite *RewardTestSuite) TestRewardBindAddr() {
list
=
append
(
list
,
newer
)
list
=
append
(
list
,
newer
)
list
=
append
(
list
,
&
new2
)
list
=
append
(
list
,
&
new2
)
recp
,
change
,
err
:=
suite
.
action
.
rewardBindAddr
(
50000005
,
list
,
1
)
recp
,
change
,
err
:=
suite
.
action
.
rewardBindAddr
List
(
50000005
,
node
,
list
,
1
)
suite
.
Nil
(
err
)
suite
.
Nil
(
err
)
suite
.
Equal
(
int64
(
5
),
change
)
suite
.
Equal
(
int64
(
5
),
change
)
suite
.
Equal
(
int32
(
types
.
ExecOk
),
recp
.
Ty
)
suite
.
Equal
(
int32
(
types
.
ExecOk
),
recp
.
Ty
)
...
...
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