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
df5938dd
Commit
df5938dd
authored
Apr 12, 2019
by
jiangpeng
Committed by
vipwzw
Apr 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add para mining
parent
76f2ea54
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
1 deletion
+91
-1
action.go
plugin/dapp/paracross/executor/action.go
+27
-1
reward.go
plugin/dapp/paracross/executor/reward.go
+64
-0
No files found.
plugin/dapp/paracross/executor/action.go
View file @
df5938dd
...
...
@@ -359,6 +359,20 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
saveTitleHeight
(
a
.
db
,
calcTitleHeightKey
(
commit
.
Status
.
Title
,
commit
.
Status
.
Height
),
stat
)
return
receipt
,
nil
}
//平行连进行奖励分配,考虑可能的失败,需要在保存共识高度等数据之前处理
if
types
.
IsPara
()
{
rewardReceipt
,
err
:=
a
.
reward
(
commit
.
Status
,
stat
)
//错误会导致和主链处理的共识结果不一致
if
err
!=
nil
{
clog
.
Error
(
"paracross mining reward err"
,
"height"
,
titleStatus
.
Height
,
"blockhash"
,
hex
.
EncodeToString
(
titleStatus
.
BlockHash
),
"err"
,
err
)
return
nil
,
err
}
receipt
=
mergeReceipt
(
receipt
,
rewardReceipt
)
}
clog
.
Info
(
"paracross.Commit commit ----pass"
,
"most"
,
most
,
"mostHash"
,
hex
.
EncodeToString
([]
byte
(
mostHash
)))
stat
.
Status
=
pt
.
ParacrossStatusCommitDone
...
...
@@ -510,8 +524,20 @@ func (a *action) Miner(miner *pt.ParacrossMinerAction) (*types.Receipt, error) {
log
.
Log
=
types
.
Encode
(
receipt
)
logs
=
append
(
logs
,
log
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
nil
,
Logs
:
logs
},
nil
minerReceipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
nil
,
Logs
:
logs
}
//增发coins到paracross合约中,只处理发放,不做分配
reward
:=
(
types
.
MGInt
(
"mver.consensus.coinReward"
,
a
.
height
)
+
types
.
MGInt
(
"mver.consensus.coinDevFund"
,
a
.
height
))
*
types
.
Coin
issueReceipt
,
err
:=
a
.
coinsAccount
.
ExecIssueCoins
(
a
.
execaddr
,
reward
)
if
err
!=
nil
{
clog
.
Error
(
"paracross miner issue err"
,
"height"
,
miner
.
Status
.
Height
,
"execAddr"
,
a
.
execaddr
,
"amount"
,
reward
/
types
.
Coin
)
return
nil
,
err
}
return
mergeReceipt
(
minerReceipt
,
issueReceipt
),
nil
}
func
getTitleFrom
(
exec
[]
byte
)
([]
byte
,
error
)
{
...
...
plugin/dapp/paracross/executor/reward.go
0 → 100644
View file @
df5938dd
package
executor
import
(
"bytes"
"github.com/33cn/chain33/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
)
// reward 挖矿奖励,主要处理挖矿分配逻辑,先实现基本策略,后面根据需求进行重构
func
(
a
*
action
)
reward
(
nodeStatus
*
pt
.
ParacrossNodeStatus
,
stat
*
pt
.
ParacrossHeightStatus
)
(
*
types
.
Receipt
,
error
)
{
//获取挖矿相关配置,这里需注意是共识的高度,而不是交易的高度
coinReward
:=
types
.
MGInt
(
"mver.consensus.coinReward"
,
nodeStatus
.
Height
)
*
types
.
Coin
fundReward
:=
types
.
MGInt
(
"mver.consensus.coinDevFund"
,
nodeStatus
.
Height
)
*
types
.
Coin
fundAddr
:=
types
.
MGStr
(
"mver.consensus.fundKeyAddr"
,
nodeStatus
.
Height
)
minerAddrs
:=
getMiners
(
stat
.
Details
,
nodeStatus
.
BlockHash
)
//分配给矿工的单位奖励,如果不等分转到发展基金
minerUnit
:=
coinReward
/
int64
(
len
(
minerAddrs
))
fundReward
+=
coinReward
%
minerUnit
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
for
_
,
addr
:=
range
minerAddrs
{
rep
,
err
:=
a
.
coinsAccount
.
ExecDeposit
(
addr
,
a
.
execaddr
,
minerUnit
)
if
err
!=
nil
{
clog
.
Error
(
"paracross miner reward deposit err"
,
"height"
,
nodeStatus
.
Height
,
"execAddr"
,
a
.
execaddr
,
"minerAddr"
,
addr
,
"amount"
,
minerUnit
,
"err"
,
err
)
return
nil
,
err
}
receipt
=
mergeReceipt
(
receipt
,
rep
)
}
rep
,
err
:=
a
.
coinsAccount
.
ExecDeposit
(
fundAddr
,
a
.
execaddr
,
fundReward
)
if
err
!=
nil
{
clog
.
Error
(
"paracross fund reward deposit err"
,
"height"
,
nodeStatus
.
Height
,
"execAddr"
,
a
.
execaddr
,
"fundAddr"
,
fundAddr
,
"amount"
,
fundReward
,
"err"
,
err
)
return
nil
,
err
}
return
mergeReceipt
(
receipt
,
rep
),
nil
}
// getMiners 获取提交共识消息的矿工地址
func
getMiners
(
detail
*
pt
.
ParacrossStatusDetails
,
blockHash
[]
byte
)
[]
string
{
addrs
:=
make
([]
string
,
0
)
for
i
,
hash
:=
range
detail
.
BlockHash
{
if
bytes
.
Equal
(
hash
,
blockHash
)
{
addrs
=
append
(
addrs
,
detail
.
Addrs
[
i
])
}
}
return
addrs
}
//
func
mergeReceipt
(
receipt1
,
receipt2
*
types
.
Receipt
)
*
types
.
Receipt
{
receipt1
.
KV
=
append
(
receipt1
.
KV
,
receipt2
.
KV
...
)
receipt1
.
Logs
=
append
(
receipt1
.
Logs
,
receipt2
.
Logs
...
)
return
receipt1
}
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