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
913fc189
Commit
913fc189
authored
Dec 14, 2020
by
madengji
Committed by
vipwzw
Jan 03, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
miner register adjust
parent
cf01c685
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
59 deletions
+98
-59
miner.go
plugin/dapp/paracross/executor/miner.go
+3
-17
minerCustom.go
plugin/dapp/paracross/executor/minerrewards/minerCustom.go
+7
-7
minerCustom_test.go
.../dapp/paracross/executor/minerrewards/minerCustom_test.go
+1
-1
nomal.go
plugin/dapp/paracross/executor/minerrewards/nomal.go
+54
-0
register.go
plugin/dapp/paracross/executor/minerrewards/register.go
+28
-0
reward.go
plugin/dapp/paracross/executor/reward.go
+5
-34
No files found.
plugin/dapp/paracross/executor/miner.go
View file @
913fc189
...
@@ -6,6 +6,7 @@ package executor
...
@@ -6,6 +6,7 @@ package executor
import
(
import
(
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/paracross/executor/minerrewards"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/pkg/errors"
"github.com/pkg/errors"
)
)
...
@@ -71,31 +72,16 @@ func (a *action) isSelfConsensOn(miner *pt.ParacrossMinerAction) (bool, error) {
...
@@ -71,31 +72,16 @@ func (a *action) isSelfConsensOn(miner *pt.ParacrossMinerAction) (bool, error) {
return
isSelfConsensOn
,
nil
return
isSelfConsensOn
,
nil
}
}
const
(
normalMiner
=
iota
halveMiner
customMiner
)
type
rewardValFn
func
(
cfg
*
types
.
Chain33Config
,
height
int64
)
(
int64
,
int64
,
int64
)
var
getConfigRewards
=
make
(
map
[
int
]
rewardValFn
)
func
init
()
{
getConfigRewards
[
normalMiner
]
=
getNormalReward
}
func
(
a
*
action
)
issueCoins
(
miner
*
pt
.
ParacrossMinerAction
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
issueCoins
(
miner
*
pt
.
ParacrossMinerAction
)
(
*
types
.
Receipt
,
error
)
{
cfg
:=
a
.
api
.
GetConfig
()
cfg
:=
a
.
api
.
GetConfig
()
mode
:=
int
(
cfg
.
MGInt
(
"mver.consensus.paracross.minerMode"
,
a
.
height
))
mode
:=
int
(
cfg
.
MGInt
(
"mver.consensus.paracross.minerMode"
,
a
.
height
))
if
getConfig
Rewards
[
mode
]
==
nil
{
if
minerrewards
.
Miner
Rewards
[
mode
]
==
nil
{
panic
(
"getTotalReward not be set depend on consensus.paracross.minerMode"
)
panic
(
"getTotalReward not be set depend on consensus.paracross.minerMode"
)
}
}
coinReward
,
coinFundReward
,
_
:=
getConfigRewards
[
mode
]
(
cfg
,
a
.
height
)
coinReward
,
coinFundReward
,
_
:=
minerrewards
.
MinerRewards
[
mode
]
.
GetConfigReward
(
cfg
,
a
.
height
)
totalReward
:=
coinReward
+
coinFundReward
totalReward
:=
coinReward
+
coinFundReward
if
totalReward
>
0
{
if
totalReward
>
0
{
issueReceipt
,
err
:=
a
.
coinsAccount
.
ExecIssueCoins
(
a
.
execaddr
,
totalReward
)
issueReceipt
,
err
:=
a
.
coinsAccount
.
ExecIssueCoins
(
a
.
execaddr
,
totalReward
)
...
...
plugin/dapp/paracross/executor/minerCustom.go
→
plugin/dapp/paracross/executor/miner
rewards/miner
Custom.go
View file @
913fc189
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
package
executor
package
minerrewards
import
(
import
(
"fmt"
"fmt"
...
@@ -29,6 +29,8 @@ const (
...
@@ -29,6 +29,8 @@ const (
var
addrs
=
[]
string
{
addrStaffA
,
addrStaffB
,
addrBoss
}
var
addrs
=
[]
string
{
addrStaffA
,
addrStaffB
,
addrBoss
}
var
addrsMap
=
make
(
map
[
string
]
int64
)
var
addrsMap
=
make
(
map
[
string
]
int64
)
type
custom
struct
{}
func
checkQuota
()
{
func
checkQuota
()
{
var
sum
int64
var
sum
int64
for
_
,
a
:=
range
addrs
{
for
_
,
a
:=
range
addrs
{
...
@@ -46,13 +48,11 @@ func checkQuota() {
...
@@ -46,13 +48,11 @@ func checkQuota() {
}
}
func
init
()
{
func
init
()
{
getConfigRewards
[
customMiner
]
=
getCustomReward
register
(
customMiner
,
&
custom
{})
rewardMiner
[
customMiner
]
=
customRewardMiner
checkQuota
()
checkQuota
()
}
}
func
getCustom
Reward
(
cfg
*
types
.
Chain33Config
,
height
int64
)
(
int64
,
int64
,
int64
)
{
func
(
c
*
custom
)
GetConfig
Reward
(
cfg
*
types
.
Chain33Config
,
height
int64
)
(
int64
,
int64
,
int64
)
{
n
:=
getCurrentN
(
height
)
n
:=
getCurrentN
(
height
)
return
calcCoins
(
n
),
0
,
0
return
calcCoins
(
n
),
0
,
0
...
@@ -94,12 +94,12 @@ func calcCoins(n uint32) int64 {
...
@@ -94,12 +94,12 @@ func calcCoins(n uint32) int64 {
return
int64
(
math
.
Trunc
(
float64
(
vf
)))
return
int64
(
math
.
Trunc
(
float64
(
vf
)))
}
}
func
customRewardMiner
(
coinReward
int64
,
miners
[]
string
,
height
int64
)
([]
*
pt
.
ParaMinerReward
,
int64
)
{
func
(
c
*
custom
)
RewardMiners
(
coinReward
int64
,
miners
[]
string
,
height
int64
)
([]
*
pt
.
ParaMinerReward
,
int64
)
{
//找零
//找零
var
change
int64
var
change
int64
var
rewards
[]
*
pt
.
ParaMinerReward
var
rewards
[]
*
pt
.
ParaMinerReward
coins
,
_
,
_
:=
getCustom
Reward
(
nil
,
height
)
coins
,
_
,
_
:=
c
.
GetConfig
Reward
(
nil
,
height
)
var
sum
int64
var
sum
int64
//get quto to miner
//get quto to miner
for
_
,
m
:=
range
miners
{
for
_
,
m
:=
range
miners
{
...
...
plugin/dapp/paracross/executor/minerCustom_test.go
→
plugin/dapp/paracross/executor/miner
rewards/miner
Custom_test.go
View file @
913fc189
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
package
executor
package
minerrewards
import
(
import
(
"fmt"
"fmt"
...
...
plugin/dapp/paracross/executor/minerrewards/nomal.go
0 → 100644
View file @
913fc189
package
minerrewards
import
(
"github.com/33cn/chain33/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
)
type
normal
struct
{
}
func
init
()
{
register
(
normalMiner
,
&
normal
{})
}
func
(
n
*
normal
)
RewardMiners
(
coinReward
int64
,
miners
[]
string
,
height
int64
)
([]
*
pt
.
ParaMinerReward
,
int64
)
{
//找零
var
change
int64
var
rewards
[]
*
pt
.
ParaMinerReward
//分配给矿工的平均奖励
minerUnit
:=
coinReward
/
int64
(
len
(
miners
))
if
minerUnit
>
0
{
for
_
,
m
:=
range
miners
{
r
:=
&
pt
.
ParaMinerReward
{
Addr
:
m
,
Amount
:
minerUnit
}
rewards
=
append
(
rewards
,
r
)
}
//如果不等分转到发展基金
change
=
coinReward
%
minerUnit
}
return
rewards
,
change
}
func
(
n
*
normal
)
GetConfigReward
(
cfg
*
types
.
Chain33Config
,
height
int64
)
(
int64
,
int64
,
int64
)
{
coinReward
:=
cfg
.
MGInt
(
"mver.consensus.paracross.coinReward"
,
height
)
fundReward
:=
cfg
.
MGInt
(
"mver.consensus.paracross.coinDevFund"
,
height
)
coinBaseReward
:=
cfg
.
MGInt
(
"mver.consensus.paracross.coinBaseReward"
,
height
)
if
coinReward
<
0
||
fundReward
<
0
||
coinBaseReward
<
0
{
panic
(
"para config consensus.paracross.coinReward should bigger than 0"
)
}
//decimalMode=false,意味着精简模式,需要乘1e8
decimalMode
:=
cfg
.
MIsEnable
(
"mver.consensus.paracross.decimalMode"
,
height
)
if
!
decimalMode
{
coinReward
*=
types
.
Coin
fundReward
*=
types
.
Coin
coinBaseReward
*=
types
.
Coin
}
//防止coinBaseReward 设置出错场景, coinBaseReward 一定要比coinReward小
if
coinBaseReward
>=
coinReward
{
coinBaseReward
=
coinReward
/
10
}
return
coinReward
,
fundReward
,
coinBaseReward
}
plugin/dapp/paracross/executor/minerrewards/register.go
0 → 100644
View file @
913fc189
package
minerrewards
import
(
"fmt"
"github.com/33cn/chain33/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
)
type
RewardPolicy
interface
{
GetConfigReward
(
cfg
*
types
.
Chain33Config
,
height
int64
)
(
int64
,
int64
,
int64
)
RewardMiners
(
coinReward
int64
,
miners
[]
string
,
height
int64
)
([]
*
pt
.
ParaMinerReward
,
int64
)
}
const
(
normalMiner
=
iota
halveMiner
customMiner
)
var
MinerRewards
=
make
(
map
[
int
]
RewardPolicy
)
func
register
(
ty
int
,
policy
RewardPolicy
)
{
if
_
,
ok
:=
MinerRewards
[
ty
];
ok
{
panic
(
fmt
.
Sprintf
(
"paracross minerreward ty=%d registered"
,
ty
))
}
MinerRewards
[
ty
]
=
policy
}
plugin/dapp/paracross/executor/reward.go
View file @
913fc189
...
@@ -3,6 +3,8 @@ package executor
...
@@ -3,6 +3,8 @@ package executor
import
(
import
(
"bytes"
"bytes"
"github.com/33cn/plugin/plugin/dapp/paracross/executor/minerrewards"
"github.com/pkg/errors"
"github.com/pkg/errors"
dbm
"github.com/33cn/chain33/common/db"
dbm
"github.com/33cn/chain33/common/db"
...
@@ -40,14 +42,6 @@ func (a *action) getBindAddrs(nodes []string, statusHeight int64) (*pt.ParaNodeB
...
@@ -40,14 +42,6 @@ func (a *action) getBindAddrs(nodes []string, statusHeight int64) (*pt.ParaNodeB
}
}
type
rewardFn
func
(
coinReward
int64
,
miners
[]
string
,
height
int64
)
([]
*
pt
.
ParaMinerReward
,
int64
)
var
rewardMiner
=
make
(
map
[
int
]
rewardFn
)
func
init
()
{
rewardMiner
[
normalMiner
]
=
rewardEven
}
func
rewardEven
(
coinReward
int64
,
miners
[]
string
,
height
int64
)
([]
*
pt
.
ParaMinerReward
,
int64
)
{
func
rewardEven
(
coinReward
int64
,
miners
[]
string
,
height
int64
)
([]
*
pt
.
ParaMinerReward
,
int64
)
{
//找零
//找零
var
change
int64
var
change
int64
...
@@ -71,10 +65,10 @@ func (a *action) rewardSuperNode(coinReward int64, miners []string, statusHeight
...
@@ -71,10 +65,10 @@ func (a *action) rewardSuperNode(coinReward int64, miners []string, statusHeight
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
mode
:=
int
(
cfg
.
MGInt
(
"mver.consensus.paracross.minerMode"
,
a
.
height
))
mode
:=
int
(
cfg
.
MGInt
(
"mver.consensus.paracross.minerMode"
,
a
.
height
))
if
rewardMiner
[
mode
]
==
nil
{
if
minerrewards
.
MinerRewards
[
mode
]
==
nil
{
panic
(
"getReward not be set depend on consensus.paracross.minerMode"
)
panic
(
"getReward not be set depend on consensus.paracross.minerMode"
)
}
}
rewards
,
change
:=
rewardMiner
[
mode
]
(
coinReward
,
miners
,
statusHeight
)
rewards
,
change
:=
minerrewards
.
MinerRewards
[
mode
]
.
RewardMiners
(
coinReward
,
miners
,
statusHeight
)
resp
,
err
:=
a
.
rewardDeposit
(
rewards
,
statusHeight
)
resp
,
err
:=
a
.
rewardDeposit
(
rewards
,
statusHeight
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
err
return
nil
,
0
,
err
...
@@ -139,29 +133,6 @@ func (a *action) rewardBindAddr(coinReward int64, bindList *pt.ParaNodeBindList,
...
@@ -139,29 +133,6 @@ func (a *action) rewardBindAddr(coinReward int64, bindList *pt.ParaNodeBindList,
return
receipt
,
change
,
nil
return
receipt
,
change
,
nil
}
}
func
getNormalReward
(
cfg
*
types
.
Chain33Config
,
height
int64
)
(
int64
,
int64
,
int64
)
{
coinReward
:=
cfg
.
MGInt
(
"mver.consensus.paracross.coinReward"
,
height
)
fundReward
:=
cfg
.
MGInt
(
"mver.consensus.paracross.coinDevFund"
,
height
)
coinBaseReward
:=
cfg
.
MGInt
(
"mver.consensus.paracross.coinBaseReward"
,
height
)
if
coinReward
<
0
||
fundReward
<
0
||
coinBaseReward
<
0
{
panic
(
"para config consensus.paracross.coinReward should bigger than 0"
)
}
//decimalMode=false,意味着精简模式,需要乘1e8
decimalMode
:=
cfg
.
MIsEnable
(
"mver.consensus.paracross.decimalMode"
,
height
)
if
!
decimalMode
{
coinReward
*=
types
.
Coin
fundReward
*=
types
.
Coin
coinBaseReward
*=
types
.
Coin
}
//防止coinBaseReward 设置出错场景, coinBaseReward 一定要比coinReward小
if
coinBaseReward
>=
coinReward
{
coinBaseReward
=
coinReward
/
10
}
return
coinReward
,
fundReward
,
coinBaseReward
}
// reward 挖矿奖励, 主要处理挖矿分配逻辑,先实现基本策略,后面根据需求进行重构
// reward 挖矿奖励, 主要处理挖矿分配逻辑,先实现基本策略,后面根据需求进行重构
func
(
a
*
action
)
reward
(
nodeStatus
*
pt
.
ParacrossNodeStatus
,
stat
*
pt
.
ParacrossHeightStatus
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
reward
(
nodeStatus
*
pt
.
ParacrossNodeStatus
,
stat
*
pt
.
ParacrossHeightStatus
)
(
*
types
.
Receipt
,
error
)
{
//获取挖矿相关配置,这里需注意是共识的高度,而不是交易的高度
//获取挖矿相关配置,这里需注意是共识的高度,而不是交易的高度
...
@@ -172,7 +143,7 @@ func (a *action) reward(nodeStatus *pt.ParacrossNodeStatus, stat *pt.ParacrossHe
...
@@ -172,7 +143,7 @@ func (a *action) reward(nodeStatus *pt.ParacrossNodeStatus, stat *pt.ParacrossHe
}
}
mode
:=
int
(
cfg
.
MGInt
(
"mver.consensus.paracross.minerMode"
,
a
.
height
))
mode
:=
int
(
cfg
.
MGInt
(
"mver.consensus.paracross.minerMode"
,
a
.
height
))
coinReward
,
fundReward
,
coinBaseReward
:=
getConfigRewards
[
mode
]
(
cfg
,
nodeStatus
.
Height
)
coinReward
,
fundReward
,
coinBaseReward
:=
minerrewards
.
MinerRewards
[
mode
]
.
GetConfigReward
(
cfg
,
nodeStatus
.
Height
)
fundAddr
:=
cfg
.
MGStr
(
"mver.consensus.fundKeyAddr"
,
nodeStatus
.
Height
)
fundAddr
:=
cfg
.
MGStr
(
"mver.consensus.fundKeyAddr"
,
nodeStatus
.
Height
)
//超级节点地址
//超级节点地址
...
...
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