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
a02f9889
Commit
a02f9889
authored
Apr 15, 2019
by
jiangpeng
Committed by
vipwzw
Apr 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix parachain mining
parent
03552689
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
34 deletions
+59
-34
para.go
plugin/consensus/para/para.go
+4
-1
action.go
plugin/dapp/paracross/executor/action.go
+30
-12
paracross_test.go
plugin/dapp/paracross/executor/paracross_test.go
+1
-1
reward.go
plugin/dapp/paracross/executor/reward.go
+20
-15
paracross.proto
plugin/dapp/paracross/proto/paracross.proto
+1
-0
paracross.go
plugin/dapp/paracross/types/paracross.go
+3
-5
paracross.pb.go
plugin/dapp/paracross/types/paracross.pb.go
+0
-0
No files found.
plugin/consensus/para/para.go
View file @
a02f9889
...
...
@@ -703,7 +703,10 @@ func (client *client) addMinerTx(preStateHash []byte, block *types.Block, main *
MainBlockHash
:
main
.
Seq
.
Hash
,
MainBlockHeight
:
main
.
Detail
.
Block
.
Height
,
}
tx
,
err
:=
paracross
.
CreateRawMinerTx
(
status
)
tx
,
err
:=
paracross
.
CreateRawMinerTx
(
&
pt
.
ParacrossMinerAction
{
Status
:
status
,
IsSelfConsensus
:
isParaSelfConsensusForked
(
status
.
MainBlockHeight
),
})
if
err
!=
nil
{
return
err
}
...
...
plugin/dapp/paracross/executor/action.go
View file @
a02f9889
...
...
@@ -359,6 +359,10 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
saveTitleHeight
(
a
.
db
,
calcTitleHeightKey
(
commit
.
Status
.
Title
,
commit
.
Status
.
Height
),
stat
)
return
receipt
,
nil
}
//add commit done receipt
receiptDone
:=
makeDoneReceipt
(
a
.
fromaddr
,
commit
,
stat
,
int32
(
most
),
int32
(
commitCount
),
int32
(
len
(
nodes
)))
receipt
.
KV
=
append
(
receipt
.
KV
,
receiptDone
.
KV
...
)
receipt
.
Logs
=
append
(
receipt
.
Logs
,
receiptDone
.
Logs
...
)
//平行连进行奖励分配,考虑可能的失败,需要在保存共识高度等数据之前处理
if
types
.
IsPara
()
{
...
...
@@ -376,9 +380,6 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
clog
.
Info
(
"paracross.Commit commit ----pass"
,
"most"
,
most
,
"mostHash"
,
hex
.
EncodeToString
([]
byte
(
mostHash
)))
stat
.
Status
=
pt
.
ParacrossStatusCommitDone
receiptDone
:=
makeDoneReceipt
(
a
.
fromaddr
,
commit
,
stat
,
int32
(
most
),
int32
(
commitCount
),
int32
(
len
(
nodes
)))
receipt
.
KV
=
append
(
receipt
.
KV
,
receiptDone
.
KV
...
)
receipt
.
Logs
=
append
(
receipt
.
Logs
,
receiptDone
.
Logs
...
)
saveTitleHeight
(
a
.
db
,
calcTitleHeightKey
(
commit
.
Status
.
Title
,
commit
.
Status
.
Height
),
stat
)
titleStatus
.
Title
=
commit
.
Status
.
Title
...
...
@@ -526,18 +527,35 @@ func (a *action) Miner(miner *pt.ParacrossMinerAction) (*types.Receipt, error) {
logs
=
append
(
logs
,
log
)
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
//自共识后才挖矿
if
miner
.
IsSelfConsensus
{
//增发coins到paracross合约中,只处理发放,不做分配
totalReward
:=
int64
(
0
)
coinReward
:=
types
.
MGInt
(
"mver.consensus.coinReward"
,
a
.
height
)
fundReward
:=
types
.
MGInt
(
"mver.consensus.coinDevFund"
,
a
.
height
)
if
coinReward
>
0
{
totalReward
+=
coinReward
}
if
fundReward
>
0
{
totalReward
+=
fundReward
}
totalReward
*=
types
.
Coin
if
totalReward
>
0
{
issueReceipt
,
err
:=
a
.
coinsAccount
.
ExecIssueCoins
(
a
.
execaddr
,
totalReward
)
if
err
!=
nil
{
clog
.
Error
(
"paracross miner issue err"
,
"height"
,
miner
.
Status
.
Height
,
"execAddr"
,
a
.
execaddr
,
"amount"
,
totalReward
/
types
.
Coin
)
return
nil
,
err
}
minerReceipt
=
mergeReceipt
(
minerReceipt
,
issueReceipt
)
}
}
return
m
ergeReceipt
(
minerReceipt
,
issueReceipt
)
,
nil
return
m
inerReceipt
,
nil
}
func
getTitleFrom
(
exec
[]
byte
)
([]
byte
,
error
)
{
...
...
plugin/dapp/paracross/executor/paracross_test.go
View file @
a02f9889
...
...
@@ -449,7 +449,7 @@ func (s *VoteTestSuite) TestVoteTx() {
}
func
(
s
*
VoteTestSuite
)
createVoteTx
(
status
*
pt
.
ParacrossNodeStatus
,
privFrom
string
)
(
*
types
.
Transaction
,
error
)
{
tx
,
err
:=
pt
.
CreateRawMinerTx
(
status
)
tx
,
err
:=
pt
.
CreateRawMinerTx
(
&
pt
.
ParacrossMinerAction
{
Status
:
status
}
)
assert
.
Nil
(
s
.
T
(),
err
,
"create asset transfer failed"
)
if
err
!=
nil
{
return
nil
,
err
...
...
plugin/dapp/paracross/executor/reward.go
View file @
a02f9889
...
...
@@ -16,31 +16,36 @@ func (a *action) reward(nodeStatus *pt.ParacrossNodeStatus, stat *pt.ParacrossHe
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
minerUnit
>
0
{
//如果不等分转到发展基金
fundReward
+=
coinReward
%
minerUnit
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
)
}
}
if
fundReward
>
0
{
rep
,
err
:=
a
.
coinsAccount
.
ExecDeposit
(
fundAddr
,
a
.
execaddr
,
fundReward
)
if
err
!=
nil
{
clog
.
Error
(
"paracross
miner
reward deposit err"
,
"height"
,
nodeStatus
.
Height
,
"execAddr"
,
a
.
execaddr
,
"
minerAddr"
,
addr
,
"amount"
,
minerUnit
,
"err"
,
err
)
clog
.
Error
(
"paracross
fund
reward deposit err"
,
"height"
,
nodeStatus
.
Height
,
"execAddr"
,
a
.
execaddr
,
"
fundAddr"
,
fundAddr
,
"amount"
,
fundReward
,
"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
return
receipt
,
nil
}
// getMiners 获取提交共识消息的矿工地址
...
...
plugin/dapp/paracross/proto/paracross.proto
View file @
a02f9889
...
...
@@ -124,6 +124,7 @@ message ParacrossCommitAction {
message
ParacrossMinerAction
{
ParacrossNodeStatus
status
=
1
;
bool
isSelfConsensus
=
2
;
}
message
ParacrossAction
{
...
...
plugin/dapp/paracross/types/paracross.go
View file @
a02f9889
...
...
@@ -209,13 +209,11 @@ func CreateRawAssetTransferTx(param *types.CreateTx) (*types.Transaction, error)
}
// CreateRawMinerTx create miner tx
func
CreateRawMinerTx
(
status
*
ParacrossNodeStatus
)
(
*
types
.
Transaction
,
error
)
{
v
:=
&
ParacrossMinerAction
{
Status
:
status
,
}
func
CreateRawMinerTx
(
value
*
ParacrossMinerAction
)
(
*
types
.
Transaction
,
error
)
{
action
:=
&
ParacrossAction
{
Ty
:
ParacrossActionMiner
,
Value
:
&
ParacrossAction_Miner
{
v
},
Value
:
&
ParacrossAction_Miner
{
v
alue
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
ParaX
)),
...
...
plugin/dapp/paracross/types/paracross.pb.go
View file @
a02f9889
This diff is collapsed.
Click to expand it.
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