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
ce76e9bc
Commit
ce76e9bc
authored
Jul 29, 2020
by
madengji
Committed by
33cn
Aug 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
para bind miner fix kvmvcc issue
parent
6d6d870f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
61 deletions
+52
-61
paracross.go
plugin/dapp/paracross/commands/paracross.go
+1
-1
action.go
plugin/dapp/paracross/executor/action.go
+6
-3
exec.go
plugin/dapp/paracross/executor/exec.go
+1
-1
query.go
plugin/dapp/paracross/executor/query.go
+0
-7
reward.go
plugin/dapp/paracross/executor/reward.go
+35
-46
paracross.proto
plugin/dapp/paracross/proto/paracross.proto
+9
-3
No files found.
plugin/dapp/paracross/commands/paracross.go
View file @
ce76e9bc
...
...
@@ -556,7 +556,7 @@ func createNodeBindTx(cmd *cobra.Command, args []string) {
fmt
.
Fprintln
(
os
.
Stderr
,
"coins should bigger than 0"
)
}
payload
:=
&
pt
.
ParaBindMiner
Info
{
BindAction
:
int32
(
action
),
BindCount
:
int64
(
coins
),
TargetNode
:
node
}
payload
:=
&
pt
.
ParaBindMiner
Cmd
{
BindAction
:
int32
(
action
),
BindCoins
:
int64
(
coins
),
TargetNode
:
node
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
getRealExecName
(
paraName
,
pt
.
ParaX
),
ActionName
:
"ParaBindMiner"
,
...
...
plugin/dapp/paracross/executor/action.go
View file @
ce76e9bc
...
...
@@ -300,13 +300,16 @@ func (a *action) getNodesGroup(title string) (map[string]struct{}, []string, err
}
func
(
a
*
action
)
isValidSuperNode
(
addr
string
)
(
bool
,
error
)
{
func
(
a
*
action
)
isValidSuperNode
(
addr
string
)
error
{
cfg
:=
a
.
api
.
GetConfig
()
nodes
,
_
,
err
:=
getParacrossNodes
(
a
.
db
,
cfg
.
GetTitle
())
if
err
!=
nil
{
return
false
,
errors
.
Wrapf
(
err
,
"getNodes for title:%s"
,
cfg
.
GetTitle
())
return
errors
.
Wrapf
(
err
,
"getNodes for title:%s"
,
cfg
.
GetTitle
())
}
return
validNode
(
addr
,
nodes
),
nil
if
!
validNode
(
addr
,
nodes
)
{
return
errors
.
Wrapf
(
pt
.
ErrParaNodeAddrNotExisted
,
"invalid node=%s"
,
addr
)
}
return
nil
}
//相同的BlockHash,只保留一份数据
...
...
plugin/dapp/paracross/executor/exec.go
View file @
ce76e9bc
...
...
@@ -121,7 +121,7 @@ func (e *Paracross) Exec_SelfStageConfig(payload *pt.ParaStageConfig, tx *types.
}
//Exec_ParaBindMiner node group config process
func
(
e
*
Paracross
)
Exec_ParaBindMiner
(
payload
*
pt
.
ParaBindMiner
Info
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
e
*
Paracross
)
Exec_ParaBindMiner
(
payload
*
pt
.
ParaBindMiner
Cmd
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
a
:=
newAction
(
e
,
tx
)
return
a
.
bindMiner
(
payload
)
}
plugin/dapp/paracross/executor/query.go
View file @
ce76e9bc
...
...
@@ -558,12 +558,5 @@ func (p *Paracross) Query_GetNodeBindMinerList(in *types.ReqString) (types.Messa
resp
.
Details
=
append
(
resp
.
Details
,
info
)
}
info
,
err
:=
getBindAddrInfo
(
p
.
GetStateDB
(),
in
.
Data
,
"1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY"
)
if
err
!=
nil
{
clog
.
Error
(
"Query_GetNodeBindMinerList get addr"
,
"err"
,
err
,
"node"
,
in
.
Data
,
"addr"
,
"1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY"
)
return
nil
,
errors
.
Cause
(
err
)
}
resp
.
Details
=
append
(
resp
.
Details
,
info
)
return
&
resp
,
nil
}
plugin/dapp/paracross/executor/reward.go
View file @
ce76e9bc
...
...
@@ -89,7 +89,7 @@ func (a *action) rewardBindAddr(coinReward int64, bindList []*pt.ParaNodeBindLis
var
totalCoins
int64
for
_
,
addr
:=
range
bindAddrList
{
totalCoins
+=
addr
.
BindCo
unt
totalCoins
+=
addr
.
BindCo
ins
}
//分配给矿工的单位奖励
...
...
@@ -100,10 +100,10 @@ func (a *action) rewardBindAddr(coinReward int64, bindList []*pt.ParaNodeBindLis
//如果不等分转到发展基金
change
=
coinReward
%
minerUnit
for
_
,
miner
:=
range
bindAddrList
{
rep
,
err
:=
a
.
coinsAccount
.
ExecDeposit
(
miner
.
Addr
,
a
.
execaddr
,
minerUnit
*
miner
.
BindCo
unt
)
rep
,
err
:=
a
.
coinsAccount
.
ExecDeposit
(
miner
.
Addr
,
a
.
execaddr
,
minerUnit
*
miner
.
BindCo
ins
)
if
err
!=
nil
{
clog
.
Error
(
"paracross bind miner reward deposit err"
,
"height"
,
statusHeight
,
"execAddr"
,
a
.
execaddr
,
"minerAddr"
,
miner
.
Addr
,
"amount"
,
minerUnit
*
miner
.
BindCo
unt
,
"err"
,
err
)
"execAddr"
,
a
.
execaddr
,
"minerAddr"
,
miner
.
Addr
,
"amount"
,
minerUnit
*
miner
.
BindCo
ins
,
"err"
,
err
)
return
nil
,
0
,
err
}
receipt
=
mergeReceipt
(
receipt
,
rep
)
...
...
@@ -195,15 +195,11 @@ func makeAddrBindReceipt(node, addr string, prev, current *pt.ParaBindMinerInfo)
Prev
:
prev
,
Current
:
current
,
}
var
val
[]
byte
if
current
!=
nil
{
val
=
types
.
Encode
(
current
)
}
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
[]
*
types
.
KeyValue
{
{
Key
:
key
,
Value
:
val
},
{
Key
:
key
,
Value
:
types
.
Encode
(
current
)
},
},
Logs
:
[]
*
types
.
ReceiptLog
{
{
...
...
@@ -220,15 +216,11 @@ func makeNodeBindReceipt(addr string, prev, current *pt.ParaNodeBindList) *types
Prev
:
prev
,
Current
:
current
,
}
var
val
[]
byte
if
current
!=
nil
{
val
=
types
.
Encode
(
current
)
}
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
[]
*
types
.
KeyValue
{
{
Key
:
key
,
Value
:
val
},
{
Key
:
key
,
Value
:
types
.
Encode
(
current
)
},
},
Logs
:
[]
*
types
.
ReceiptLog
{
{
...
...
@@ -305,23 +297,15 @@ func getBindAddrInfo(db dbm.KV, node, addr string) (*pt.ParaBindMinerInfo, error
return
&
info
,
nil
}
func
(
a
*
action
)
bindOp
(
cmd
*
pt
.
ParaBindMiner
Info
)
(
*
types
.
Receipt
,
error
)
{
if
len
(
cmd
.
Addr
)
>
0
&&
cmd
.
Addr
!=
a
.
fromaddr
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"bindMiner
addr=%s not from addr %s"
,
cmd
.
Addr
,
a
.
fromaddr
)
func
(
a
*
action
)
bindOp
(
cmd
*
pt
.
ParaBindMiner
Cmd
)
(
*
types
.
Receipt
,
error
)
{
if
cmd
.
BindCoins
<=
0
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"bindMiner
BindCoins nil from addr %s"
,
a
.
fromaddr
)
}
if
cmd
.
BindCount
<=
0
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"bindMiner bindCount nil from addr %s"
,
a
.
fromaddr
)
}
ok
,
err
:=
a
.
isValidSuperNode
(
cmd
.
TargetNode
)
err
:=
a
.
isValidSuperNode
(
cmd
.
TargetNode
)
if
err
!=
nil
{
return
nil
,
err
}
//非有效超级节点
if
!
ok
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"invalid target node=%s"
,
cmd
.
TargetNode
)
}
current
,
err
:=
getBindAddrInfo
(
a
.
db
,
cmd
.
TargetNode
,
a
.
fromaddr
)
if
err
!=
nil
&&
!
isNotFound
(
errors
.
Cause
(
err
))
{
...
...
@@ -329,49 +313,49 @@ func (a *action) bindOp(cmd *pt.ParaBindMinerInfo) (*types.Receipt, error) {
}
//found, 修改当前的绑定
if
current
!=
nil
{
if
current
!=
nil
&&
current
.
BindStatus
==
opBind
{
var
receipt
*
types
.
Receipt
if
cmd
.
BindCo
unt
==
current
.
BindCount
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"bind coins same current=%d, cmd=%d"
,
current
.
BindCo
unt
,
cmd
.
BindCount
)
if
cmd
.
BindCo
ins
==
current
.
BindCoins
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"bind coins same current=%d, cmd=%d"
,
current
.
BindCo
ins
,
cmd
.
BindCoins
)
}
//释放一部分coins
if
cmd
.
BindCo
unt
<
current
.
BindCount
{
receipt
,
err
=
a
.
coinsAccount
.
ExecActive
(
a
.
fromaddr
,
a
.
execaddr
,
(
current
.
BindCo
unt
-
cmd
.
BindCount
)
*
types
.
Coin
)
if
cmd
.
BindCo
ins
<
current
.
BindCoins
{
receipt
,
err
=
a
.
coinsAccount
.
ExecActive
(
a
.
fromaddr
,
a
.
execaddr
,
(
current
.
BindCo
ins
-
cmd
.
BindCoins
)
*
types
.
Coin
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"bindOp Active addr=%s,execaddr=%s,coins=%d"
,
a
.
fromaddr
,
a
.
execaddr
,
current
.
BindCo
unt
-
cmd
.
BindCount
)
return
nil
,
errors
.
Wrapf
(
err
,
"bindOp Active addr=%s,execaddr=%s,coins=%d"
,
a
.
fromaddr
,
a
.
execaddr
,
current
.
BindCo
ins
-
cmd
.
BindCoins
)
}
}
else
{
//冻结更多
receipt
,
err
=
a
.
coinsAccount
.
ExecFrozen
(
a
.
fromaddr
,
a
.
execaddr
,
(
cmd
.
BindCo
unt
-
current
.
BindCount
)
*
types
.
Coin
)
receipt
,
err
=
a
.
coinsAccount
.
ExecFrozen
(
a
.
fromaddr
,
a
.
execaddr
,
(
cmd
.
BindCo
ins
-
current
.
BindCoins
)
*
types
.
Coin
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"bindOp frozen more addr=%s,execaddr=%s,coins=%d"
,
a
.
fromaddr
,
a
.
execaddr
,
cmd
.
BindCo
unt
-
current
.
BindCount
)
return
nil
,
errors
.
Wrapf
(
err
,
"bindOp frozen more addr=%s,execaddr=%s,coins=%d"
,
a
.
fromaddr
,
a
.
execaddr
,
cmd
.
BindCo
ins
-
current
.
BindCoins
)
}
}
acctCopy
:=
*
current
current
.
BindCo
unt
=
cmd
.
BindCount
current
.
BindCo
ins
=
cmd
.
BindCoins
r
:=
makeAddrBindReceipt
(
cmd
.
TargetNode
,
a
.
fromaddr
,
&
acctCopy
,
current
)
return
mergeReceipt
(
receipt
,
r
),
nil
}
//not
fou
nd, 增加新绑定
receipt
,
err
:=
a
.
coinsAccount
.
ExecFrozen
(
a
.
fromaddr
,
a
.
execaddr
,
cmd
.
BindCo
unt
*
types
.
Coin
)
//not
bi
nd, 增加新绑定
receipt
,
err
:=
a
.
coinsAccount
.
ExecFrozen
(
a
.
fromaddr
,
a
.
execaddr
,
cmd
.
BindCo
ins
*
types
.
Coin
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"bindOp frozen addr=%s,execaddr=%s,count=%d"
,
a
.
fromaddr
,
a
.
execaddr
,
cmd
.
BindCo
unt
)
return
nil
,
errors
.
Wrapf
(
err
,
"bindOp frozen addr=%s,execaddr=%s,count=%d"
,
a
.
fromaddr
,
a
.
execaddr
,
cmd
.
BindCo
ins
)
}
//bind addr
acct
:=
&
pt
.
ParaBindMinerInfo
{
newer
:=
&
pt
.
ParaBindMinerInfo
{
Addr
:
a
.
fromaddr
,
Bind
Action
:
opBind
,
BindCo
unt
:
cmd
.
BindCount
,
Bind
Status
:
opBind
,
BindCo
ins
:
cmd
.
BindCoins
,
BlockTime
:
a
.
blocktime
,
BlockHeight
:
a
.
height
,
TargetNode
:
cmd
.
TargetNode
,
}
rBind
:=
makeAddrBindReceipt
(
cmd
.
TargetNode
,
a
.
fromaddr
,
nil
,
acct
)
rBind
:=
makeAddrBindReceipt
(
cmd
.
TargetNode
,
a
.
fromaddr
,
current
,
newer
)
mergeReceipt
(
receipt
,
rBind
)
//增加到列表中
...
...
@@ -384,7 +368,7 @@ func (a *action) bindOp(cmd *pt.ParaBindMinerInfo) (*types.Receipt, error) {
}
func
(
a
*
action
)
unBindOp
(
cmd
*
pt
.
ParaBindMiner
Info
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
unBindOp
(
cmd
*
pt
.
ParaBindMiner
Cmd
)
(
*
types
.
Receipt
,
error
)
{
acct
,
err
:=
getBindAddrInfo
(
a
.
db
,
cmd
.
TargetNode
,
a
.
fromaddr
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -397,13 +381,18 @@ func (a *action) unBindOp(cmd *pt.ParaBindMinerInfo) (*types.Receipt, error) {
}
//unfrozen
receipt
,
err
:=
a
.
coinsAccount
.
ExecActive
(
a
.
fromaddr
,
a
.
execaddr
,
acct
.
BindCo
unt
*
types
.
Coin
)
receipt
,
err
:=
a
.
coinsAccount
.
ExecActive
(
a
.
fromaddr
,
a
.
execaddr
,
acct
.
BindCo
ins
*
types
.
Coin
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"unBindOp addr=%s,execaddr=%s,count=%d"
,
a
.
fromaddr
,
a
.
execaddr
,
acct
.
BindCo
unt
)
return
nil
,
errors
.
Wrapf
(
err
,
"unBindOp addr=%s,execaddr=%s,count=%d"
,
a
.
fromaddr
,
a
.
execaddr
,
acct
.
BindCo
ins
)
}
//删除 bind addr
rUnBind
:=
makeAddrBindReceipt
(
cmd
.
TargetNode
,
a
.
fromaddr
,
acct
,
nil
)
//由于kvmvcc的原因,不能通过把一个key值=nil的方式删除,kvmvcc这样是删除了当前版本,就会查询更早的版本,&struct{}也不行,len=0 也被认为是删除了的
acctCopy
:=
*
acct
acct
.
BindStatus
=
opUnBind
acct
.
BlockHeight
=
a
.
height
acct
.
BlockTime
=
a
.
blocktime
rUnBind
:=
makeAddrBindReceipt
(
cmd
.
TargetNode
,
a
.
fromaddr
,
&
acctCopy
,
acct
)
mergeReceipt
(
receipt
,
rUnBind
)
//从列表删除
...
...
@@ -416,7 +405,7 @@ func (a *action) unBindOp(cmd *pt.ParaBindMinerInfo) (*types.Receipt, error) {
return
receipt
,
nil
}
func
(
a
*
action
)
bindMiner
(
info
*
pt
.
ParaBindMiner
Info
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
bindMiner
(
info
*
pt
.
ParaBindMiner
Cmd
)
(
*
types
.
Receipt
,
error
)
{
if
len
(
info
.
TargetNode
)
<=
0
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"bindMiner TargetNode should not be nil to addr %s"
,
a
.
fromaddr
)
}
...
...
plugin/dapp/paracross/proto/paracross.proto
View file @
ce76e9bc
...
...
@@ -159,10 +159,16 @@ message RespParacrossNodeGroups {
}
//para bind miner
message
ParaBindMinerCmd
{
int32
bindAction
=
1
;
// 1: bind, 2:unbind
int64
bindCoins
=
2
;
// bind coins count
string
targetNode
=
3
;
// super node addr
}
message
ParaBindMinerInfo
{
string
addr
=
1
;
// miner addr
int32
bind
Action
=
2
;
// 1: bind, 2:unbind
int64
bindCo
unt
=
3
;
// bind coins count
int32
bind
Status
=
2
;
// 1: bind, 2:unbind
int64
bindCo
ins
=
3
;
// bind coins count
string
targetNode
=
4
;
// super node addr
int64
blockTime
=
5
;
// action bind block time
int64
blockHeight
=
6
;
// action bind block height
...
...
@@ -334,7 +340,7 @@ message ParacrossAction {
ParaNodeGroupConfig
nodeGroupConfig
=
10
;
ParaStageConfig
selfStageConfig
=
11
;
CrossAssetTransfer
crossAssetTransfer
=
12
;
ParaBindMiner
Info
paraBindMiner
=
13
;
ParaBindMiner
Cmd
paraBindMiner
=
13
;
}
int32
ty
=
2
;
}
...
...
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