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
aa8a0c88
Commit
aa8a0c88
authored
Jun 04, 2019
by
mdj33
Committed by
vipwzw
Jun 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added addr cancel operation
parent
cfa64635
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
193 additions
and
88 deletions
+193
-88
paracross.go
plugin/dapp/paracross/commands/paracross.go
+3
-3
action.go
plugin/dapp/paracross/executor/action.go
+5
-5
superaccount.go
plugin/dapp/paracross/executor/superaccount.go
+160
-68
superaccount_test.go
plugin/dapp/paracross/executor/superaccount_test.go
+8
-9
paracross.proto
plugin/dapp/paracross/proto/paracross.proto
+10
-1
errors.go
plugin/dapp/paracross/types/errors.go
+2
-2
paracross.go
plugin/dapp/paracross/types/paracross.go
+4
-0
type.go
plugin/dapp/paracross/types/type.go
+1
-0
No files found.
plugin/dapp/paracross/commands/paracross.go
View file @
aa8a0c88
...
@@ -251,12 +251,12 @@ func CreateRawNodeManageCmd() *cobra.Command {
...
@@ -251,12 +251,12 @@ func CreateRawNodeManageCmd() *cobra.Command {
}
}
func
addNodeManageFlags
(
cmd
*
cobra
.
Command
)
{
func
addNodeManageFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uint32P
(
"operation"
,
"o"
,
0
,
"operation:1:join,2:vote,3:quit"
)
cmd
.
Flags
()
.
Uint32P
(
"operation"
,
"o"
,
0
,
"operation:1:join,2:vote,3:quit
,4:cancel
"
)
cmd
.
MarkFlagRequired
(
"operation"
)
cmd
.
MarkFlagRequired
(
"operation"
)
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"operating target addr"
)
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"operating target addr
[optional]
"
)
cmd
.
Flags
()
.
StringP
(
"id"
,
"i"
,
""
,
"operating target id"
)
cmd
.
Flags
()
.
StringP
(
"id"
,
"i"
,
""
,
"operating target id
[optional]
"
)
cmd
.
Flags
()
.
Uint32P
(
"value"
,
"v"
,
1
,
"vote value: 1:yes,2:no"
)
cmd
.
Flags
()
.
Uint32P
(
"value"
,
"v"
,
1
,
"vote value: 1:yes,2:no"
)
cmd
.
Flags
()
.
Float64P
(
"coins_frozen"
,
"c"
,
0
,
"frozen coins amount, should not less nodegroup's"
)
cmd
.
Flags
()
.
Float64P
(
"coins_frozen"
,
"c"
,
0
,
"frozen coins amount, should not less nodegroup's"
)
...
...
plugin/dapp/paracross/executor/action.go
View file @
aa8a0c88
...
@@ -261,10 +261,10 @@ func (a *action) getNodesGroup(title string) (map[string]struct{}, error) {
...
@@ -261,10 +261,10 @@ func (a *action) getNodesGroup(title string) (map[string]struct{}, error) {
}
}
//根据nodes过滤掉可能退出了的addrs
//根据nodes过滤掉可能退出了的addrs
func
updateCommitAddrs
(
stat
*
pt
.
ParacrossHeightStatus
,
nodes
map
[
string
]
struct
{})
{
func
updateCommitAddrs
(
stat
*
pt
.
ParacrossHeightStatus
,
nodes
map
[
string
]
struct
{})
{
details
:=
&
pt
.
ParacrossStatusDetails
{}
details
:=
&
pt
.
ParacrossStatusDetails
{}
for
i
,
addr
:=
range
stat
.
Details
.
Addrs
{
for
i
,
addr
:=
range
stat
.
Details
.
Addrs
{
if
_
,
ok
:=
nodes
[
addr
];
ok
{
if
_
,
ok
:=
nodes
[
addr
];
ok
{
details
.
Addrs
=
append
(
details
.
Addrs
,
addr
)
details
.
Addrs
=
append
(
details
.
Addrs
,
addr
)
details
.
BlockHash
=
append
(
details
.
BlockHash
,
stat
.
Details
.
BlockHash
[
i
])
details
.
BlockHash
=
append
(
details
.
BlockHash
,
stat
.
Details
.
BlockHash
[
i
])
}
}
...
@@ -378,8 +378,8 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
...
@@ -378,8 +378,8 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
receipt
=
makeCommitReceipt
(
a
.
fromaddr
,
commit
,
&
copyStat
,
stat
)
receipt
=
makeCommitReceipt
(
a
.
fromaddr
,
commit
,
&
copyStat
,
stat
)
}
}
if
types
.
IsDappFork
(
commit
.
Status
.
MainBlockHeight
,
pt
.
ParaX
,
pt
.
ForkCommitTx
){
if
types
.
IsDappFork
(
commit
.
Status
.
MainBlockHeight
,
pt
.
ParaX
,
pt
.
ForkCommitTx
)
{
updateCommitAddrs
(
stat
,
nodes
)
updateCommitAddrs
(
stat
,
nodes
)
}
}
clog
.
Info
(
"paracross.Commit commit"
,
"stat.title"
,
stat
.
Title
,
"stat.height"
,
stat
.
Height
,
"notes"
,
len
(
nodes
))
clog
.
Info
(
"paracross.Commit commit"
,
"stat.title"
,
stat
.
Title
,
"stat.height"
,
stat
.
Height
,
"notes"
,
len
(
nodes
))
...
...
plugin/dapp/paracross/executor/superaccount.go
View file @
aa8a0c88
...
@@ -111,9 +111,28 @@ func makeVoteDoneReceipt(config *pt.ParaNodeIdStatus, totalCount, commitCount, m
...
@@ -111,9 +111,28 @@ func makeVoteDoneReceipt(config *pt.ParaNodeIdStatus, totalCount, commitCount, m
}
}
}
}
func
makeParaNodeStatusReceipt
(
fromAddr
string
,
prev
,
current
*
pt
.
ParaNodeAddrIdStatus
)
*
types
.
Receipt
{
key
:=
calcParaNodeAddrKey
(
current
.
Title
,
current
.
Addr
)
log
:=
&
pt
.
ReceiptParaNodeAddrStatUpdate
{
FromAddr
:
fromAddr
,
Prev
:
prev
,
Current
:
current
,
}
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
[]
*
types
.
KeyValue
{
{
Key
:
key
,
Value
:
types
.
Encode
(
current
)},
},
Logs
:
[]
*
types
.
ReceiptLog
{
{
Ty
:
pt
.
TyLogParaNodeStatusUpdate
,
Log
:
types
.
Encode
(
log
),
},
},
}
}
func
makeNodeConfigReceipt
(
fromAddr
string
,
config
*
pt
.
ParaNodeAddrConfig
,
prev
,
current
*
pt
.
ParaNodeIdStatus
)
*
types
.
Receipt
{
func
makeNodeConfigReceipt
(
fromAddr
string
,
config
*
pt
.
ParaNodeAddrConfig
,
prev
,
current
*
pt
.
ParaNodeIdStatus
)
*
types
.
Receipt
{
key
:=
calcParaNodeAddrKey
(
current
.
Title
,
current
.
TargetAddr
)
val
:=
&
pt
.
ParaNodeAddrIdStatus
{
ProposalId
:
current
.
Id
}
log
:=
&
pt
.
ReceiptParaNodeConfig
{
log
:=
&
pt
.
ReceiptParaNodeConfig
{
Addr
:
fromAddr
,
Addr
:
fromAddr
,
Config
:
config
,
Config
:
config
,
...
@@ -124,7 +143,6 @@ func makeNodeConfigReceipt(fromAddr string, config *pt.ParaNodeAddrConfig, prev,
...
@@ -124,7 +143,6 @@ func makeNodeConfigReceipt(fromAddr string, config *pt.ParaNodeAddrConfig, prev,
Ty
:
types
.
ExecOk
,
Ty
:
types
.
ExecOk
,
KV
:
[]
*
types
.
KeyValue
{
KV
:
[]
*
types
.
KeyValue
{
{
Key
:
[]
byte
(
current
.
Id
),
Value
:
types
.
Encode
(
current
)},
{
Key
:
[]
byte
(
current
.
Id
),
Value
:
types
.
Encode
(
current
)},
{
Key
:
key
,
Value
:
types
.
Encode
(
val
)},
},
},
Logs
:
[]
*
types
.
ReceiptLog
{
Logs
:
[]
*
types
.
ReceiptLog
{
{
{
...
@@ -193,13 +211,24 @@ func makeParaNodeGroupReceipt(title string, prev, current *types.ConfigItem) *ty
...
@@ -193,13 +211,24 @@ func makeParaNodeGroupReceipt(title string, prev, current *types.ConfigItem) *ty
}
}
}
}
func
(
a
*
action
)
nodeJoin
(
config
*
pt
.
ParaNodeAddrConfig
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
checkValidNode
(
config
*
pt
.
ParaNodeAddrConfig
)
(
bool
,
error
)
{
nodes
,
_
,
err
:=
getParacrossNodes
(
a
.
db
,
config
.
Title
)
nodes
,
_
,
err
:=
getParacrossNodes
(
a
.
db
,
config
.
Title
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"getNodes for title:%s"
,
config
.
Title
)
return
false
,
errors
.
Wrapf
(
err
,
"getNodes for title:%s"
,
config
.
Title
)
}
}
//有可能申请地址和配置地址不是同一个
//有可能申请地址和配置地址不是同一个
if
validNode
(
config
.
Addr
,
nodes
)
{
if
validNode
(
config
.
Addr
,
nodes
)
{
return
true
,
nil
}
return
false
,
nil
}
func
(
a
*
action
)
nodeJoin
(
config
*
pt
.
ParaNodeAddrConfig
)
(
*
types
.
Receipt
,
error
)
{
addrExist
,
err
:=
a
.
checkValidNode
(
config
)
if
err
!=
nil
{
return
nil
,
err
}
if
addrExist
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeAddrExisted
,
"nodeAddr existed:%s"
,
config
.
Addr
)
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeAddrExisted
,
"nodeAddr existed:%s"
,
config
.
Addr
)
}
}
...
@@ -244,19 +273,9 @@ func (a *action) nodeJoin(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
...
@@ -244,19 +273,9 @@ func (a *action) nodeJoin(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
return
receipt
,
nil
return
receipt
,
nil
}
}
stat
,
err
:=
getNodeID
(
a
.
db
,
addrStat
.
ProposalId
)
if
err
!=
nil
{
if
addrStat
.
Status
==
pt
.
ParacrossNodeQuited
{
clog
.
Error
(
"nodeaccount.getNodeID fail"
,
"err"
,
err
.
Error
())
stat
:=
&
pt
.
ParaNodeIdStatus
{
return
nil
,
err
}
var
copyStat
pt
.
ParaNodeIdStatus
err
=
deepCopy
(
&
copyStat
,
stat
)
if
err
!=
nil
{
clog
.
Error
(
"nodeaccount.nodeJoin deep copy fail"
,
"copy"
,
copyStat
,
"stat"
,
stat
)
return
nil
,
err
}
if
stat
.
Status
==
pt
.
ParacrossNodeQuited
{
stat
=
&
pt
.
ParaNodeIdStatus
{
Id
:
calcParaNodeIDKey
(
config
.
Title
,
common
.
ToHex
(
a
.
txhash
)),
Id
:
calcParaNodeIDKey
(
config
.
Title
,
common
.
ToHex
(
a
.
txhash
)),
Status
:
pt
.
ParacrossNodeJoining
,
Status
:
pt
.
ParacrossNodeJoining
,
Title
:
config
.
Title
,
Title
:
config
.
Title
,
...
@@ -265,17 +284,46 @@ func (a *action) nodeJoin(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
...
@@ -265,17 +284,46 @@ func (a *action) nodeJoin(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
Votes
:
&
pt
.
ParaNodeVoteDetail
{},
Votes
:
&
pt
.
ParaNodeVoteDetail
{},
CoinsFrozen
:
config
.
CoinsFrozen
,
CoinsFrozen
:
config
.
CoinsFrozen
,
Height
:
a
.
height
}
Height
:
a
.
height
}
r
:=
makeNodeConfigReceipt
(
a
.
fromaddr
,
config
,
&
copyStat
,
stat
)
r
:=
makeNodeConfigReceipt
(
a
.
fromaddr
,
config
,
nil
,
stat
)
receipt
.
KV
=
append
(
receipt
.
KV
,
r
.
KV
...
)
receipt
.
KV
=
append
(
receipt
.
KV
,
r
.
KV
...
)
receipt
.
Logs
=
append
(
receipt
.
Logs
,
r
.
Logs
...
)
receipt
.
Logs
=
append
(
receipt
.
Logs
,
r
.
Logs
...
)
return
receipt
,
nil
return
receipt
,
nil
}
}
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeAddrExisted
,
"nodeAddr existed:%s,status:%d"
,
config
.
Addr
,
s
tat
.
Status
)
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeAddrExisted
,
"nodeAddr existed:%s,status:%d"
,
config
.
Addr
,
addrS
tat
.
Status
)
}
}
func
(
a
*
action
)
nodeQuit
(
config
*
pt
.
ParaNodeAddrConfig
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
nodeQuit
(
config
*
pt
.
ParaNodeAddrConfig
)
(
*
types
.
Receipt
,
error
)
{
addrExist
,
err
:=
a
.
checkValidNode
(
config
)
if
err
!=
nil
{
return
nil
,
err
}
if
!
addrExist
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeAddrNotExisted
,
"nodeAddr not existed:%s"
,
config
.
Addr
)
}
addrStat
,
err
:=
getNodeAddr
(
a
.
db
,
config
.
Title
,
config
.
Addr
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"nodeAddr:%s get error"
,
config
.
Addr
)
}
if
addrStat
.
Status
!=
pt
.
ParacrossNodeJoined
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeAddrNotExisted
,
"nodeAddr:%s status:%d"
,
config
.
Addr
,
addrStat
.
Status
)
}
stat
:=
&
pt
.
ParaNodeIdStatus
{
Id
:
calcParaNodeIDKey
(
config
.
Title
,
common
.
ToHex
(
a
.
txhash
)),
Status
:
pt
.
ParacrossNodeQuiting
,
Title
:
config
.
Title
,
TargetAddr
:
config
.
Addr
,
FromAddr
:
a
.
fromaddr
,
Votes
:
&
pt
.
ParaNodeVoteDetail
{},
Height
:
a
.
height
}
return
makeNodeConfigReceipt
(
a
.
fromaddr
,
config
,
nil
,
stat
),
nil
}
func
(
a
*
action
)
nodeCancel
(
config
*
pt
.
ParaNodeAddrConfig
)
(
*
types
.
Receipt
,
error
)
{
stat
,
err
:=
getNodeID
(
a
.
db
,
config
.
Id
)
stat
,
err
:=
getNodeID
(
a
.
db
,
config
.
Id
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -285,53 +333,38 @@ func (a *action) nodeQuit(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
...
@@ -285,53 +333,38 @@ func (a *action) nodeQuit(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
return
nil
,
errors
.
Wrapf
(
pt
.
ErrNodeNotForTheTitle
,
"config title:%s,id title:%s"
,
config
.
Title
,
stat
.
Title
)
return
nil
,
errors
.
Wrapf
(
pt
.
ErrNodeNotForTheTitle
,
"config title:%s,id title:%s"
,
config
.
Title
,
stat
.
Title
)
}
}
if
stat
.
Status
!=
pt
.
ParacrossNodeJoining
&&
stat
.
Status
!=
pt
.
ParacrossNodeQuiting
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeOpStatusWrong
,
"config id:%s,status:%d"
,
config
.
Id
,
stat
.
Status
)
}
var
copyStat
pt
.
ParaNodeIdStatus
var
copyStat
pt
.
ParaNodeIdStatus
err
=
deepCopy
(
&
copyStat
,
stat
)
err
=
deepCopy
(
&
copyStat
,
stat
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"nodeaccount.nodeQuit deep copy fail"
,
"copy"
,
copyStat
,
"stat"
,
stat
)
clog
.
Error
(
"nodeaccount.nodeQuit deep copy fail"
,
"copy"
,
copyStat
,
"stat"
,
stat
)
return
nil
,
err
return
nil
,
err
}
}
if
stat
.
Status
==
pt
.
ParacrossNodeJoined
{
nodes
,
_
,
err
:=
getParacrossNodes
(
a
.
db
,
config
.
Title
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"getNodes for title:%s"
,
config
.
Title
)
}
if
!
validNode
(
stat
.
TargetAddr
,
nodes
)
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeAddrNotExisted
,
"nodeAddr not existed:%s"
,
stat
.
TargetAddr
)
}
//不允许最后一个账户退出
if
len
(
nodes
)
==
1
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeGroupLastAddr
,
"nodeAddr last one:%s"
,
stat
.
TargetAddr
)
}
stat
.
Status
=
pt
.
ParacrossNodeQuiting
stat
.
Height
=
a
.
height
stat
.
Votes
=
&
pt
.
ParaNodeVoteDetail
{}
return
makeNodeConfigReceipt
(
a
.
fromaddr
,
config
,
&
copyStat
,
stat
),
nil
}
if
stat
.
Status
==
pt
.
ParacrossNodeJoining
{
if
stat
.
Status
==
pt
.
ParacrossNodeJoining
{
//still adding status, quit directly
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
if
!
types
.
IsPara
()
{
if
!
types
.
IsPara
()
{
r
,
err
:=
a
.
nodeGroupCoinsActive
(
stat
.
FromAddr
,
stat
.
CoinsFrozen
,
1
)
r
,
err
:=
a
.
nodeGroupCoinsActive
(
stat
.
FromAddr
,
stat
.
CoinsFrozen
,
1
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
receipt
.
KV
=
append
(
receipt
.
KV
,
r
.
KV
...
)
receipt
=
mergeReceipt
(
receipt
,
r
)
receipt
.
Logs
=
append
(
receipt
.
Logs
,
r
.
Logs
...
)
}
}
stat
.
Status
=
pt
.
ParacrossNodeCanceled
stat
.
Status
=
pt
.
ParacrossNodeQuited
stat
.
Height
=
a
.
height
stat
.
Height
=
a
.
height
stat
.
Votes
=
&
pt
.
ParaNodeVoteDetail
{}
r
:=
makeNodeConfigReceipt
(
a
.
fromaddr
,
config
,
&
copyStat
,
stat
)
r
:=
makeNodeConfigReceipt
(
a
.
fromaddr
,
config
,
&
copyStat
,
stat
)
receipt
.
KV
=
append
(
receipt
.
KV
,
r
.
KV
...
)
receipt
=
mergeReceipt
(
receipt
,
r
)
receipt
.
Logs
=
append
(
receipt
.
Logs
,
r
.
Logs
...
)
return
receipt
,
nil
return
receipt
,
nil
}
}
if
stat
.
Status
==
pt
.
ParacrossNodeQuiting
{
stat
.
Status
=
pt
.
ParacrossNodeCanceled
stat
.
Height
=
a
.
height
return
makeNodeConfigReceipt
(
a
.
fromaddr
,
config
,
&
copyStat
,
stat
),
nil
}
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaUnSupportNodeOper
,
"nodeid %s was quit status:%d"
,
config
.
Id
,
stat
.
Status
)
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaUnSupportNodeOper
,
"nodeid %s was quit status:%d"
,
config
.
Id
,
stat
.
Status
)
}
}
...
@@ -401,10 +434,10 @@ func (a *action) superManagerVoteProc(title string) error {
...
@@ -401,10 +434,10 @@ func (a *action) superManagerVoteProc(title string) error {
return
nil
return
nil
}
}
func
updateVotes
(
stat
*
pt
.
ParaNodeIdStatus
,
nodes
map
[
string
]
struct
{})
{
func
updateVotes
(
stat
*
pt
.
ParaNodeIdStatus
,
nodes
map
[
string
]
struct
{})
{
votes
:=
&
pt
.
ParaNodeVoteDetail
{}
votes
:=
&
pt
.
ParaNodeVoteDetail
{}
for
i
,
addr
:=
range
stat
.
Votes
.
Addrs
{
for
i
,
addr
:=
range
stat
.
Votes
.
Addrs
{
if
_
,
ok
:=
nodes
[
addr
];
ok
{
if
_
,
ok
:=
nodes
[
addr
];
ok
{
votes
.
Addrs
=
append
(
votes
.
Addrs
,
addr
)
votes
.
Addrs
=
append
(
votes
.
Addrs
,
addr
)
votes
.
Votes
=
append
(
votes
.
Votes
,
stat
.
Votes
.
Votes
[
i
])
votes
.
Votes
=
append
(
votes
.
Votes
,
stat
.
Votes
.
Votes
[
i
])
}
}
...
@@ -412,6 +445,55 @@ func updateVotes(stat *pt.ParaNodeIdStatus,nodes map[string]struct{}){
...
@@ -412,6 +445,55 @@ func updateVotes(stat *pt.ParaNodeIdStatus,nodes map[string]struct{}){
stat
.
Votes
=
votes
stat
.
Votes
=
votes
}
}
func
(
a
*
action
)
updateNodeAddrStatus
(
stat
*
pt
.
ParaNodeIdStatus
)
(
*
types
.
Receipt
,
error
)
{
addrStat
,
err
:=
getNodeAddr
(
a
.
db
,
stat
.
Title
,
stat
.
TargetAddr
)
if
err
!=
nil
{
if
!
isNotFound
(
err
)
{
return
nil
,
errors
.
Wrapf
(
err
,
"nodeAddr:%s get error"
,
stat
.
TargetAddr
)
}
if
stat
.
Status
!=
pt
.
ParacrossNodeJoined
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeOpStatusWrong
,
"nodeAddr:%s int get wrong status"
,
stat
.
TargetAddr
,
stat
.
Status
)
}
addrStat
=
&
pt
.
ParaNodeAddrIdStatus
{}
addrStat
.
Title
=
stat
.
Title
addrStat
.
Addr
=
stat
.
TargetAddr
addrStat
.
Status
=
pt
.
ParacrossNodeJoined
addrStat
.
ProposalId
=
stat
.
Id
addrStat
.
QuitId
=
""
return
makeParaNodeStatusReceipt
(
a
.
fromaddr
,
nil
,
addrStat
),
nil
}
preStat
:=
*
addrStat
if
stat
.
Status
==
pt
.
ParacrossNodeJoined
{
addrStat
.
Status
=
pt
.
ParacrossNodeJoined
addrStat
.
ProposalId
=
stat
.
Id
addrStat
.
QuitId
=
""
return
makeParaNodeStatusReceipt
(
a
.
fromaddr
,
&
preStat
,
addrStat
),
nil
}
if
stat
.
Status
==
pt
.
ParacrossNodeQuited
{
proposalStat
,
err
:=
getNodeID
(
a
.
db
,
addrStat
.
ProposalId
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"nodeAddr:%s quiting wrong proposeid:%s"
,
stat
.
TargetAddr
,
addrStat
.
ProposalId
)
}
addrStat
.
Status
=
pt
.
ParacrossNodeQuited
addrStat
.
QuitId
=
stat
.
Id
receipt
:=
makeParaNodeStatusReceipt
(
a
.
fromaddr
,
&
preStat
,
addrStat
)
if
!
types
.
IsPara
()
{
r
,
err
:=
a
.
nodeGroupCoinsActive
(
proposalStat
.
FromAddr
,
proposalStat
.
CoinsFrozen
,
1
)
if
err
!=
nil
{
return
nil
,
err
}
receipt
=
mergeReceipt
(
receipt
,
r
)
}
return
receipt
,
nil
}
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeOpStatusWrong
,
"nodeAddr:%s get wrong status"
,
stat
.
TargetAddr
,
stat
.
Status
)
}
func
(
a
*
action
)
nodeVote
(
config
*
pt
.
ParaNodeAddrConfig
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
nodeVote
(
config
*
pt
.
ParaNodeAddrConfig
)
(
*
types
.
Receipt
,
error
)
{
nodes
,
_
,
err
:=
getParacrossNodes
(
a
.
db
,
config
.
Title
)
nodes
,
_
,
err
:=
getParacrossNodes
(
a
.
db
,
config
.
Title
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -430,6 +512,9 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
...
@@ -430,6 +512,9 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
return
nil
,
errors
.
Wrapf
(
pt
.
ErrNodeNotForTheTitle
,
"config title:%s,id title:%s"
,
config
.
Title
,
stat
.
Title
)
return
nil
,
errors
.
Wrapf
(
pt
.
ErrNodeNotForTheTitle
,
"config title:%s,id title:%s"
,
config
.
Title
,
stat
.
Title
)
}
}
if
stat
.
Status
!=
pt
.
ParacrossNodeJoining
&&
stat
.
Status
!=
pt
.
ParacrossNodeQuiting
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeOpStatusWrong
,
"config id:%s,status:%d"
,
config
.
Id
,
stat
.
Status
)
}
var
copyStat
pt
.
ParaNodeIdStatus
var
copyStat
pt
.
ParaNodeIdStatus
err
=
deepCopy
(
&
copyStat
,
stat
)
err
=
deepCopy
(
&
copyStat
,
stat
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -474,15 +559,10 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
...
@@ -474,15 +559,10 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
if
vote
==
pt
.
ParaNodeVoteNo
{
if
vote
==
pt
.
ParaNodeVoteNo
{
// 对已经在group里面的node,直接投票remove,对正在申请中的adding or quiting状态保持不变,对quited的保持不变
if
stat
.
Status
==
pt
.
ParacrossNodeJoining
{
if
stat
.
Status
==
pt
.
ParacrossNodeJoined
{
stat
.
Status
=
pt
.
ParacrossNodeCanceled
r
,
err
:=
unpdateNodeGroup
(
a
.
db
,
config
.
Title
,
stat
.
TargetAddr
,
false
)
if
err
!=
nil
{
return
nil
,
err
}
receipt
=
mergeReceipt
(
receipt
,
r
)
stat
.
Status
=
pt
.
ParacrossNodeQuited
stat
.
Height
=
a
.
height
stat
.
Height
=
a
.
height
//active coins
if
!
types
.
IsPara
()
{
if
!
types
.
IsPara
()
{
r
,
err
:=
a
.
nodeGroupCoinsActive
(
stat
.
FromAddr
,
stat
.
CoinsFrozen
,
1
)
r
,
err
:=
a
.
nodeGroupCoinsActive
(
stat
.
FromAddr
,
stat
.
CoinsFrozen
,
1
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -490,7 +570,11 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
...
@@ -490,7 +570,11 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
}
}
receipt
=
mergeReceipt
(
receipt
,
r
)
receipt
=
mergeReceipt
(
receipt
,
r
)
}
}
}
else
if
stat
.
Status
==
pt
.
ParacrossNodeQuiting
{
stat
.
Status
=
pt
.
ParacrossNodeCanceled
stat
.
Height
=
a
.
height
}
}
}
else
{
}
else
{
if
stat
.
Status
==
pt
.
ParacrossNodeJoining
{
if
stat
.
Status
==
pt
.
ParacrossNodeJoining
{
r
,
err
:=
unpdateNodeGroup
(
a
.
db
,
config
.
Title
,
stat
.
TargetAddr
,
true
)
r
,
err
:=
unpdateNodeGroup
(
a
.
db
,
config
.
Title
,
stat
.
TargetAddr
,
true
)
...
@@ -500,6 +584,12 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
...
@@ -500,6 +584,12 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
stat
.
Status
=
pt
.
ParacrossNodeJoined
stat
.
Status
=
pt
.
ParacrossNodeJoined
stat
.
Height
=
a
.
height
stat
.
Height
=
a
.
height
receipt
=
mergeReceipt
(
receipt
,
r
)
receipt
=
mergeReceipt
(
receipt
,
r
)
r
,
err
=
a
.
updateNodeAddrStatus
(
stat
)
if
err
!=
nil
{
return
nil
,
err
}
receipt
=
mergeReceipt
(
receipt
,
r
)
}
else
if
stat
.
Status
==
pt
.
ParacrossNodeQuiting
{
}
else
if
stat
.
Status
==
pt
.
ParacrossNodeQuiting
{
r
,
err
:=
unpdateNodeGroup
(
a
.
db
,
config
.
Title
,
stat
.
TargetAddr
,
false
)
r
,
err
:=
unpdateNodeGroup
(
a
.
db
,
config
.
Title
,
stat
.
TargetAddr
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -509,13 +599,12 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
...
@@ -509,13 +599,12 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
stat
.
Height
=
a
.
height
stat
.
Height
=
a
.
height
receipt
=
mergeReceipt
(
receipt
,
r
)
receipt
=
mergeReceipt
(
receipt
,
r
)
if
!
types
.
IsPara
()
{
r
,
err
=
a
.
updateNodeAddrStatus
(
stat
)
r
,
err
:=
a
.
nodeGroupCoinsActive
(
stat
.
FromAddr
,
stat
.
CoinsFrozen
,
1
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
receipt
=
mergeReceipt
(
receipt
,
r
)
}
}
receipt
=
mergeReceipt
(
receipt
,
r
)
}
}
}
}
r
:=
makeNodeConfigReceipt
(
a
.
fromaddr
,
config
,
&
copyStat
,
stat
)
r
:=
makeNodeConfigReceipt
(
a
.
fromaddr
,
config
,
&
copyStat
,
stat
)
...
@@ -723,7 +812,7 @@ func (a *action) nodeGroupQuit(config *pt.ParaNodeGroupConfig) (*types.Receipt,
...
@@ -723,7 +812,7 @@ func (a *action) nodeGroupQuit(config *pt.ParaNodeGroupConfig) (*types.Receipt,
//approved or quited
//approved or quited
if
status
.
Status
!=
pt
.
ParacrossNodeGroupApply
{
if
status
.
Status
!=
pt
.
ParacrossNodeGroupApply
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNode
Grou
pStatusWrong
,
"node group apply not apply:%d"
,
status
.
Status
)
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNode
O
pStatusWrong
,
"node group apply not apply:%d"
,
status
.
Status
)
}
}
applyAddrs
:=
strings
.
Split
(
status
.
TargetAddrs
,
","
)
applyAddrs
:=
strings
.
Split
(
status
.
TargetAddrs
,
","
)
...
@@ -843,7 +932,7 @@ func (a *action) nodeGroupApprove(config *pt.ParaNodeGroupConfig) (*types.Receip
...
@@ -843,7 +932,7 @@ func (a *action) nodeGroupApprove(config *pt.ParaNodeGroupConfig) (*types.Receip
return
a
.
nodeGroupApproveApply
(
config
,
id
)
return
a
.
nodeGroupApproveApply
(
config
,
id
)
}
}
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNode
Grou
pStatusWrong
,
"nodeGroupApprove id wrong status:%d,id:%s"
,
id
.
Status
,
config
.
Id
)
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNode
O
pStatusWrong
,
"nodeGroupApprove id wrong status:%d,id:%s"
,
id
.
Status
,
config
.
Id
)
}
}
...
@@ -927,10 +1016,13 @@ func (a *action) NodeConfig(config *pt.ParaNodeAddrConfig) (*types.Receipt, erro
...
@@ -927,10 +1016,13 @@ func (a *action) NodeConfig(config *pt.ParaNodeAddrConfig) (*types.Receipt, erro
return
a
.
nodeJoin
(
config
)
return
a
.
nodeJoin
(
config
)
}
else
if
config
.
Op
==
pt
.
ParaNodeQuit
{
}
else
if
config
.
Op
==
pt
.
ParaNodeQuit
{
return
a
.
nodeQuit
(
config
)
}
else
if
config
.
Op
==
pt
.
ParaNodeCancel
{
if
config
.
Id
==
""
{
if
config
.
Id
==
""
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
return
a
.
node
Quit
(
config
)
return
a
.
node
Cancel
(
config
)
}
else
if
config
.
Op
==
pt
.
ParaNodeVote
{
}
else
if
config
.
Op
==
pt
.
ParaNodeVote
{
if
config
.
Id
==
""
||
config
.
Value
>=
pt
.
ParaNodeVoteEnd
{
if
config
.
Id
==
""
||
config
.
Value
>=
pt
.
ParaNodeVoteEnd
{
...
...
plugin/dapp/paracross/executor/superaccount_test.go
View file @
aa8a0c88
...
@@ -353,17 +353,17 @@ func TestGetAddrGroup(t *testing.T) {
...
@@ -353,17 +353,17 @@ func TestGetAddrGroup(t *testing.T) {
}
}
func
TestUpdateVotes
(
t
*
testing
.
T
){
func
TestUpdateVotes
(
t
*
testing
.
T
)
{
stat
:=
&
pt
.
ParaNodeIdStatus
{}
stat
:=
&
pt
.
ParaNodeIdStatus
{}
votes
:=
&
pt
.
ParaNodeVoteDetail
{
votes
:=
&
pt
.
ParaNodeVoteDetail
{
Addrs
:
[]
string
{
"AA"
,
"BB"
,
"CC"
},
Addrs
:
[]
string
{
"AA"
,
"BB"
,
"CC"
},
Votes
:
[]
string
{
"yes"
,
"no"
,
"no"
}}
Votes
:
[]
string
{
"yes"
,
"no"
,
"no"
}}
stat
.
Votes
=
votes
stat
.
Votes
=
votes
nodes
:=
make
(
map
[
string
]
struct
{})
nodes
:=
make
(
map
[
string
]
struct
{})
nodes
[
"BB"
]
=
struct
{}{}
nodes
[
"BB"
]
=
struct
{}{}
nodes
[
"CC"
]
=
struct
{}{}
nodes
[
"CC"
]
=
struct
{}{}
updateVotes
(
stat
,
nodes
)
updateVotes
(
stat
,
nodes
)
assert
.
Equal
(
t
,[]
string
{
"BB"
,
"CC"
},
stat
.
Votes
.
Addrs
)
assert
.
Equal
(
t
,
[]
string
{
"BB"
,
"CC"
},
stat
.
Votes
.
Addrs
)
assert
.
Equal
(
t
,[]
string
{
"no"
,
"no"
},
stat
.
Votes
.
Votes
)
assert
.
Equal
(
t
,
[]
string
{
"no"
,
"no"
},
stat
.
Votes
.
Votes
)
}
}
\ No newline at end of file
plugin/dapp/paracross/proto/paracross.proto
View file @
aa8a0c88
...
@@ -63,7 +63,11 @@ message ParaNodeVoteDetail {
...
@@ -63,7 +63,11 @@ message ParaNodeVoteDetail {
}
}
message
ParaNodeAddrIdStatus
{
message
ParaNodeAddrIdStatus
{
string
proposalId
=
1
;
string
addr
=
1
;
string
proposalId
=
2
;
string
quitId
=
3
;
int32
status
=
4
;
string
title
=
5
;
}
}
message
ParaNodeIdStatus
{
message
ParaNodeIdStatus
{
...
@@ -85,6 +89,11 @@ message ReceiptParaNodeConfig {
...
@@ -85,6 +89,11 @@ message ReceiptParaNodeConfig {
ParaNodeIdStatus
current
=
4
;
ParaNodeIdStatus
current
=
4
;
}
}
message
ReceiptParaNodeAddrStatUpdate
{
string
fromAddr
=
1
;
ParaNodeAddrIdStatus
prev
=
2
;
ParaNodeAddrIdStatus
current
=
3
;
}
message
ReceiptParaNodeVoteDone
{
message
ReceiptParaNodeVoteDone
{
string
id
=
1
;
string
id
=
1
;
...
...
plugin/dapp/paracross/types/errors.go
View file @
aa8a0c88
...
@@ -45,8 +45,8 @@ var (
...
@@ -45,8 +45,8 @@ var (
ErrParaNodeVoteSelf
=
errors
.
New
(
"ErrParaNodeVoteSelf"
)
ErrParaNodeVoteSelf
=
errors
.
New
(
"ErrParaNodeVoteSelf"
)
//ErrParaNodeGroupFrozenCoinsNotEnough node group coins in tx less than conf's minimum coins
//ErrParaNodeGroupFrozenCoinsNotEnough node group coins in tx less than conf's minimum coins
ErrParaNodeGroupFrozenCoinsNotEnough
=
errors
.
New
(
"ErrParaNodeGroupFrozenCoinsNotEnough"
)
ErrParaNodeGroupFrozenCoinsNotEnough
=
errors
.
New
(
"ErrParaNodeGroupFrozenCoinsNotEnough"
)
//ErrParaNode
GroupStatusWrong node group
process wrong status
//ErrParaNode
OpStatusWrong node
process wrong status
ErrParaNode
GroupStatusWrong
=
errors
.
New
(
"ErrParaNodeGrou
pStatusWrong"
)
ErrParaNode
OpStatusWrong
=
errors
.
New
(
"ErrParaNodeO
pStatusWrong"
)
//ErrParaConsensStopBlocksNotReach consensus stop blocks not reach
//ErrParaConsensStopBlocksNotReach consensus stop blocks not reach
ErrParaConsensStopBlocksNotReach
=
errors
.
New
(
"ErrParaConsensStopBlocksNotReach"
)
ErrParaConsensStopBlocksNotReach
=
errors
.
New
(
"ErrParaConsensStopBlocksNotReach"
)
)
)
plugin/dapp/paracross/types/paracross.go
View file @
aa8a0c88
...
@@ -41,6 +41,7 @@ const (
...
@@ -41,6 +41,7 @@ const (
TyLogParaNodeVoteDone
=
658
TyLogParaNodeVoteDone
=
658
TyLogParaNodeGroupAddrsUpdate
=
659
TyLogParaNodeGroupAddrsUpdate
=
659
TyLogParaNodeGroupConfig
=
660
TyLogParaNodeGroupConfig
=
660
TyLogParaNodeStatusUpdate
=
661
TyLogParaNodeGroupStatusUpdate
=
664
TyLogParaNodeGroupStatusUpdate
=
664
)
)
...
@@ -92,6 +93,7 @@ const (
...
@@ -92,6 +93,7 @@ const (
ParaNodeJoin
=
iota
+
1
ParaNodeJoin
=
iota
+
1
ParaNodeVote
ParaNodeVote
ParaNodeQuit
ParaNodeQuit
ParaNodeCancel
)
)
// node vote op
// node vote op
...
@@ -114,6 +116,8 @@ const (
...
@@ -114,6 +116,8 @@ const (
ParacrossNodeQuiting
ParacrossNodeQuiting
// ParacrossNodeQuited pass to quite by votes
// ParacrossNodeQuited pass to quite by votes
ParacrossNodeQuited
ParacrossNodeQuited
// ParacrossNodeCanceled to cancel apply of joining or quiting
ParacrossNodeCanceled
)
)
const
(
const
(
...
...
plugin/dapp/paracross/types/type.go
View file @
aa8a0c88
...
@@ -62,6 +62,7 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
...
@@ -62,6 +62,7 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
TyLogParaAssetDeposit
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaAssetDeposit"
},
TyLogParaAssetDeposit
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaAssetDeposit"
},
TyLogParacrossMiner
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParacrossMiner
{}),
Name
:
"LogParacrossMiner"
},
TyLogParacrossMiner
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParacrossMiner
{}),
Name
:
"LogParacrossMiner"
},
TyLogParaNodeConfig
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeConfig
{}),
Name
:
"LogParaNodeConfig"
},
TyLogParaNodeConfig
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeConfig
{}),
Name
:
"LogParaNodeConfig"
},
TyLogParaNodeStatusUpdate
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeAddrStatUpdate
{}),
Name
:
"LogParaNodeAddrStatUpdate"
},
TyLogParaNodeGroupAddrsUpdate
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptConfig
{}),
Name
:
"LogParaNodeGroupAddrsUpdate"
},
TyLogParaNodeGroupAddrsUpdate
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptConfig
{}),
Name
:
"LogParaNodeGroupAddrsUpdate"
},
TyLogParaNodeVoteDone
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeVoteDone
{}),
Name
:
"LogParaNodeVoteDone"
},
TyLogParaNodeVoteDone
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeVoteDone
{}),
Name
:
"LogParaNodeVoteDone"
},
TyLogParaNodeGroupConfig
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeGroupConfig
{}),
Name
:
"LogParaNodeGroupConfig"
},
TyLogParaNodeGroupConfig
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeGroupConfig
{}),
Name
:
"LogParaNodeGroupConfig"
},
...
...
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