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
88942a63
Commit
88942a63
authored
Apr 24, 2019
by
mdj33
Committed by
vipwzw
May 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add node group apply and coin frozen process
parent
645fdab2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
151 additions
and
15 deletions
+151
-15
chain33.toml
chain33.toml
+4
-0
paracross.go
plugin/dapp/paracross/commands/paracross.go
+72
-8
exec.go
plugin/dapp/paracross/executor/exec.go
+5
-0
kv.go
plugin/dapp/paracross/executor/kv.go
+6
-0
paracross.go
plugin/dapp/paracross/executor/paracross.go
+2
-1
query.go
plugin/dapp/paracross/executor/query.go
+2
-2
superaccount.go
plugin/dapp/paracross/executor/superaccount.go
+0
-0
paracross.proto
plugin/dapp/paracross/proto/paracross.proto
+14
-1
rpc.go
plugin/dapp/paracross/rpc/rpc.go
+2
-2
errors.go
plugin/dapp/paracross/types/errors.go
+6
-0
paracross.go
plugin/dapp/paracross/types/paracross.go
+27
-1
type.go
plugin/dapp/paracross/types/type.go
+11
-0
No files found.
chain33.toml
View file @
88942a63
...
...
@@ -212,3 +212,7 @@ superManager=[
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
,
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"
]
[exec.sub.paracross]
nodeGroupFrozenCoins
=
0
plugin/dapp/paracross/commands/paracross.go
View file @
88942a63
...
...
@@ -33,6 +33,7 @@ func ParcCmd() *cobra.Command {
CreateRawWithdrawCmd
(),
CreateRawTransferToExecCmd
(),
CreateRawNodeManageCmd
(),
CreateNodeGroupApplyCmd
(),
GetParaInfoCmd
(),
GetParaListCmd
(),
GetNodeGroupCmd
(),
...
...
@@ -248,22 +249,27 @@ func CreateRawNodeManageCmd() *cobra.Command {
}
func
addNodeManageFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"operation"
,
"o"
,
""
,
"operation:join,quit,vote
,takeover
"
)
cmd
.
Flags
()
.
StringP
(
"operation"
,
"o"
,
""
,
"operation:join,quit,vote"
)
cmd
.
MarkFlagRequired
(
"operation"
)
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"operating target addr"
)
cmd
.
MarkFlagRequired
(
"addrs"
)
cmd
.
Flags
()
.
StringP
(
"value"
,
"v"
,
""
,
"vote value: yes,no"
)
cmd
.
Flags
()
.
Int64P
(
"coins_frozen"
,
"c"
,
0
,
"join to frozen coins amount, not less config"
)
}
func
createNodeTx
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
op
,
_
:=
cmd
.
Flags
()
.
GetString
(
"operation"
)
opAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addr"
)
val
,
_
:=
cmd
.
Flags
()
.
GetString
(
"value"
)
if
op
!=
"vote"
&&
op
!=
"quit"
&&
op
!=
"join"
&&
op
!=
"takeover"
{
fmt
.
Println
(
"operation should be one of join,quit,vote,takeover"
)
coins
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"coins_frozen"
)
if
op
!=
"vote"
&&
op
!=
"quit"
&&
op
!=
"join"
{
fmt
.
Println
(
"operation should be one of join,quit,vote"
)
return
}
if
(
op
==
"vote"
||
op
==
"join"
||
op
==
"quit"
)
&&
opAddr
==
""
{
if
opAddr
==
""
{
fmt
.
Println
(
"addr parameter should not be null"
)
return
}
...
...
@@ -272,7 +278,7 @@ func createNodeTx(cmd *cobra.Command, args []string) {
return
}
payload
:=
&
pt
.
ParaNodeAddrConfig
{
Op
:
op
,
Value
:
val
,
Addr
:
opAddr
}
payload
:=
&
pt
.
ParaNodeAddrConfig
{
Op
:
op
,
Value
:
val
,
Addr
:
opAddr
,
CoinsFrozen
:
coins
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pt
.
ParaX
),
ActionName
:
"NodeConfig"
,
...
...
@@ -285,6 +291,54 @@ func createNodeTx(cmd *cobra.Command, args []string) {
}
// CreateNodeGroupApplyCmd get node group addr
func
CreateNodeGroupApplyCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"nodegroup"
,
Short
:
"apply for para chain's super node group"
,
Run
:
nodeGroupApply
,
}
addNodeGroupApplyCmdFlags
(
cmd
)
return
cmd
}
func
addNodeGroupApplyCmdFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uint32P
(
"operation"
,
"o"
,
0
,
"operation:1:apply,2:approve,3:quit"
)
cmd
.
MarkFlagRequired
(
"operation"
)
cmd
.
Flags
()
.
StringP
(
"addrs"
,
"a"
,
""
,
"addrs apply for super node,split by ',' "
)
cmd
.
MarkFlagRequired
(
"addrs"
)
cmd
.
Flags
()
.
Int64P
(
"coins_frozen"
,
"c"
,
0
,
"coins amount to frozen, not less config"
)
}
func
nodeGroupApply
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
op
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"operation"
)
addrs
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addrs"
)
coins
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"coins_frozen"
)
if
op
==
0
||
op
>
3
{
fmt
.
Println
(
"operation should be one of 1:apply,2:approve,3:quit"
)
return
}
if
addrs
==
""
{
fmt
.
Println
(
"addrs should not be nil"
)
return
}
payload
:=
&
pt
.
ParaNodeGroupApply
{
Op
:
op
,
Addrs
:
addrs
,
CoinsFrozen
:
coins
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pt
.
ParaX
),
ActionName
:
"NodeGroupApply"
,
Payload
:
types
.
MustPBToJSON
(
payload
),
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
nil
)
ctx
.
RunWithoutMarshal
()
}
// IsSyncCmd query parachain is sync
func
IsSyncCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
...
...
@@ -315,6 +369,7 @@ func GetHeightCmd() *cobra.Command {
func
addTitleFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"title"
,
"t"
,
""
,
"parallel chain's title, default null in para chain"
)
cmd
.
MarkFlagRequired
(
"title"
)
}
func
consusHeight
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -484,8 +539,8 @@ func nodeList(cmd *cobra.Command, args []string) {
// GetNodeGroupCmd get node group addr
func
GetNodeGroupCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"node
_group
"
,
Short
:
"Get super node group
by title
"
,
Use
:
"node
group_list
"
,
Short
:
"Get super node group
list by title or status
"
,
Run
:
nodeGroup
,
}
addNodeGroupCmdFlags
(
cmd
)
...
...
@@ -495,13 +550,22 @@ func GetNodeGroupCmd() *cobra.Command {
func
addNodeGroupCmdFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"title"
,
"t"
,
""
,
"parallel chain's title"
)
cmd
.
MarkFlagRequired
(
"title"
)
cmd
.
Flags
()
.
Int32P
(
"status"
,
"s"
,
0
,
"status:1:apply,2:approve,3:quit"
)
cmd
.
MarkFlagRequired
(
"status"
)
}
func
nodeGroup
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
status
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"status"
)
params
:=
pt
.
ReqParacrossNodeInfo
{
Title
:
title
,
Status
:
status
,
}
var
res
types
.
ReplyConfig
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"paracross.GetNodeGroup"
,
types
.
ReqString
{
Data
:
title
}
,
&
res
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"paracross.GetNodeGroup"
,
params
,
&
res
)
ctx
.
Run
()
}
plugin/dapp/paracross/executor/exec.go
View file @
88942a63
...
...
@@ -92,3 +92,8 @@ func (e *Paracross) Exec_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *types.Tr
a
:=
newAction
(
e
,
tx
)
return
a
.
NodeConfig
(
payload
)
}
func
(
e
*
Paracross
)
Exec_NodeGroupConfig
(
payload
*
pt
.
ParaNodeGroupApply
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
a
:=
newAction
(
e
,
tx
)
return
a
.
NodeGroupConfig
(
payload
)
}
plugin/dapp/paracross/executor/kv.go
View file @
88942a63
...
...
@@ -16,6 +16,7 @@ var (
managerConfigNodes
string
//manager 合约配置的nodes
paraConfigNodes
string
//平行链自组织配置的nodes,最初是从manager同步过来
paraConfigNodeAddr
string
//平行链配置节点账户
paraNodeGroupApplyAddrs
string
localTx
string
localTitle
string
localTitleHeight
string
...
...
@@ -30,6 +31,7 @@ func setPrefix() {
managerConfigNodes
=
"paracross-nodes-"
paraConfigNodes
=
"mavl-paracross-nodes-title-"
paraConfigNodeAddr
=
"mavl-paracross-nodes-titleAddr-"
paraNodeGroupApplyAddrs
=
"mavl-paracross-nodegroup-apply-title-"
localTx
=
"LODB-paracross-titleHeightAddr-"
localTitle
=
"LODB-paracross-title-"
localTitleHeight
=
"LODB-paracross-titleHeight-"
...
...
@@ -65,6 +67,10 @@ func calcParaNodeAddrKey(title string, addr string) []byte {
return
[]
byte
(
fmt
.
Sprintf
(
paraConfigNodeAddr
+
"%s-%s"
,
title
,
addr
))
}
func
calcParaNodeGroupApplyKey
(
title
string
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
paraNodeGroupApplyAddrs
+
"%s"
,
title
))
}
func
calcLocalTxKey
(
title
string
,
height
int64
,
addr
string
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
localTx
+
"%s-%012-%s"
,
title
,
height
,
addr
))
}
...
...
plugin/dapp/paracross/executor/paracross.go
View file @
88942a63
...
...
@@ -300,7 +300,8 @@ func (c *Paracross) allow(tx *types.Transaction, index int) error {
return
nil
}
if
types
.
IsDappFork
(
c
.
GetHeight
(),
pt
.
ParaX
,
pt
.
ForkCommitTx
)
{
if
payload
.
Ty
==
pt
.
ParacrossActionCommit
||
payload
.
Ty
==
pt
.
ParacrossActionNodeConfig
{
if
payload
.
Ty
==
pt
.
ParacrossActionCommit
||
payload
.
Ty
==
pt
.
ParacrossActionNodeConfig
||
payload
.
Ty
==
pt
.
ParacrossActionNodeGroupApply
{
return
nil
}
}
...
...
plugin/dapp/paracross/executor/query.go
View file @
88942a63
...
...
@@ -36,11 +36,11 @@ func (p *Paracross) Query_GetTitleByHash(in *pt.ReqParacrossTitleHash) (types.Me
}
//Query_GetNodeGroup get node group addrs
func
(
p
*
Paracross
)
Query_GetNodeGroup
(
in
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
func
(
p
*
Paracross
)
Query_GetNodeGroup
(
in
*
pt
.
ReqParacrossNodeInfo
)
(
types
.
Message
,
error
)
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
key
:=
calcParaNodeGroupKey
(
in
.
Get
Data
())
key
:=
calcParaNodeGroupKey
(
in
.
Get
Title
())
ret
,
_
,
err
:=
getNodes
(
p
.
GetStateDB
(),
key
)
if
err
!=
nil
{
return
nil
,
errors
.
Cause
(
err
)
...
...
plugin/dapp/paracross/executor/superaccount.go
View file @
88942a63
This diff is collapsed.
Click to expand it.
plugin/dapp/paracross/proto/paracross.proto
View file @
88942a63
...
...
@@ -39,6 +39,7 @@ message ParaNodeAddrConfig{
string
op
=
2
;
string
addr
=
3
;
string
value
=
4
;
int64
coinsFrozen
=
5
;
}
...
...
@@ -51,7 +52,8 @@ message ParaNodeAddrStatus{
int32
status
=
1
;
string
title
=
2
;
string
applyAddr
=
3
;
ParaNodeVoteDetail
votes
=
4
;
int64
coinsFrozen
=
4
;
ParaNodeVoteDetail
votes
=
5
;
}
...
...
@@ -79,6 +81,15 @@ message ReceiptParaNodeVoteDone {
}
message
ParaNodeGroupApply
{
string
title
=
1
;
uint32
op
=
2
;
string
addrs
=
3
;
int64
coinsFrozen
=
4
;
}
// node query
message
ReqParacrossNodeInfo
{
string
title
=
1
;
...
...
@@ -137,6 +148,8 @@ message ParacrossAction {
AssetsWithdraw
withdraw
=
7
;
AssetsTransferToExec
transferToExec
=
8
;
ParaNodeAddrConfig
nodeConfig
=
9
;
ParaNodeGroupApply
nodeGroupConfig
=
10
;
}
int32
ty
=
2
;
...
...
plugin/dapp/paracross/rpc/rpc.go
View file @
88942a63
...
...
@@ -169,7 +169,7 @@ func (c *Jrpc) GetBlock2MainInfo(req *types.ReqBlocks, result *interface{}) erro
}
// GetNodeGroup get super node group
func
(
c
*
channelClient
)
GetNodeGroup
(
ctx
context
.
Context
,
req
*
types
.
ReqString
)
(
*
types
.
ReplyConfig
,
error
)
{
func
(
c
*
channelClient
)
GetNodeGroup
(
ctx
context
.
Context
,
req
*
pt
.
ReqParacrossNodeInfo
)
(
*
types
.
ReplyConfig
,
error
)
{
r
:=
*
req
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"GetNodeGroup"
,
&
r
)
if
err
!=
nil
{
...
...
@@ -182,7 +182,7 @@ func (c *channelClient) GetNodeGroup(ctx context.Context, req *types.ReqString)
}
// GetNodeGroup get super node group
func
(
c
*
Jrpc
)
GetNodeGroup
(
req
*
types
.
ReqString
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
GetNodeGroup
(
req
*
pt
.
ReqParacrossNodeInfo
,
result
*
interface
{})
error
{
data
,
err
:=
c
.
cli
.
GetNodeGroup
(
context
.
Background
(),
req
)
*
result
=
data
return
err
...
...
plugin/dapp/paracross/types/errors.go
View file @
88942a63
...
...
@@ -43,4 +43,10 @@ var (
ErrParaNodeGroupLastAddr
=
errors
.
New
(
"ErrParaNodeGroupLastAddr"
)
//ErrParaNodeVoteSelf vote self not allow
ErrParaNodeVoteSelf
=
errors
.
New
(
"ErrParaNodeVoteSelf"
)
//ErrParaNodeGroupLessFrozenCoins node group coins in tx less than conf's minimum coins
ErrParaNodeGroupFrozenCoinsNotEnough
=
errors
.
New
(
"ErrParaNodeGroupFrozenCoinsNotEnough"
)
//ErrParaNodeGroupStatusWrong node group process wrong status
ErrParaNodeGroupStatusWrong
=
errors
.
New
(
"ErrParaNodeGroupStatusWrong"
)
//ErrParaNodeGroupAddrNotMatch
ErrParaNodeGroupAddrNotMatch
=
errors
.
New
(
"ErrParaNodeGroupAddrNotMatch"
)
)
plugin/dapp/paracross/types/paracross.go
View file @
88942a63
...
...
@@ -39,6 +39,9 @@ const (
TyLogParaNodeConfig
=
657
TyLogParaNodeVoteDone
=
658
TyLogParaNodeGroupUpdate
=
659
TyLogParaNodeGroupApply
=
660
TyLogParaNodeGroupApprove
=
661
TyLogParaNodeGroupQuit
=
662
)
type
paracrossCommitTx
struct
{
...
...
@@ -72,6 +75,8 @@ const (
ParacrossActionAssetWithdraw
//ParacrossActionNodeConfig para super node config
ParacrossActionNodeConfig
//ParacrossActionNodeGroupApply
ParacrossActionNodeGroupApply
)
// status
...
...
@@ -87,7 +92,6 @@ const (
ParaNodeJoin
=
"join"
ParaNodeQuit
=
"quit"
ParaNodeVote
=
"vote"
ParaNodeTakeover
=
"takeover"
ParaNodeVoteYes
=
"yes"
ParaNodeVoteNo
=
"no"
...
...
@@ -104,6 +108,12 @@ const (
ParacrossNodeQuited
)
const
(
ParacrossNodeGroupApply
=
iota
+
1
ParacrossNodeGroupApprove
ParacrossNodeGroupQuit
)
var
(
// ParacrossActionCommitStr Commit string
ParacrossActionCommitStr
=
string
(
"Commit"
)
...
...
@@ -176,6 +186,22 @@ func CreateRawNodeConfigTx(config *ParaNodeAddrConfig) (*types.Transaction, erro
return
tx
,
nil
}
func
CreateRawNodeGroupApplyTx
(
apply
*
ParaNodeGroupApply
)
(
*
types
.
Transaction
,
error
)
{
apply
.
Title
=
types
.
GetTitle
()
action
:=
&
ParacrossAction
{
Ty
:
ParacrossActionNodeGroupApply
,
Value
:
&
ParacrossAction_NodeGroupConfig
{
apply
},
}
tx
:=
&
types
.
Transaction
{
Payload
:
types
.
Encode
(
action
),
}
return
tx
,
nil
}
// CreateRawAssetTransferTx create asset transfer tx
func
CreateRawAssetTransferTx
(
param
*
types
.
CreateTx
)
(
*
types
.
Transaction
,
error
)
{
// 跨链交易需要在主链和平行链上执行, 所以应该可以在主链和平行链上构建
...
...
plugin/dapp/paracross/types/type.go
View file @
88942a63
...
...
@@ -122,6 +122,17 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawNodeConfigTx
(
&
param
)
}
else
if
action
==
"NodeGroupApply"
{
if
!
types
.
IsPara
()
{
return
nil
,
types
.
ErrNotSupport
}
var
param
ParaNodeGroupApply
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
glog
.
Error
(
"CreateTx.NodeGroupApply"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawNodeGroupApplyTx
(
&
param
)
}
return
nil
,
types
.
ErrNotSupport
...
...
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