Commit 5867e799 authored by mdj33's avatar mdj33 Committed by vipwzw

added addr cancel operation

parent c6625029
......@@ -498,7 +498,7 @@ function para_create_nodegroup() {
##quit fail
txhash=$(${PARA_CLI} send para nodegroup -o 3 -i "$id" -k 0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b)
echo "tx=$txhash"
query_tx "${CLI}" "${txhash}"
query_tx "${PARA_CLI}" "${txhash}"
status=$(${CLI} para nodegroup_status -t user.p.para. | jq -r ".status")
if [ "$status" != 2 ]; then
echo "status quit not approve status=$status"
......@@ -513,7 +513,7 @@ function para_create_nodegroup() {
echo "=========== # para chain modify node group coin=5 ============="
txhash=$(${PARA_CLI} send para nodegroup -o 4 -c 5 -k 0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b)
echo "tx=$txhash"
query_tx "${CLI}" "${txhash}"
query_tx "${PARA_CLI}" "${txhash}"
modifyid=$(${PARA_CLI} para nodegroup_list -s 4 | jq -r ".ids[0].id")
if [ -z "$modifyid" ]; then
echo "query modify error "
......@@ -554,17 +554,18 @@ function para_nodegroup_behalf_quit_test() {
exit 1
fi
hash=$(${PARA_CLI} send para node -o 3 -i "$id" -k 0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b)
echo "${hash}"
query_tx "${PARA_CLI}" "${hash}"
status=$(${PARA_CLI} para node_status -t user.p.para. -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY | jq -r ".status")
if [ "${status}" != "3" ]; then
echo "wrong vote status"
if [ "${status}" != "2" ]; then
echo "wrong 1E5 status"
${PARA_CLI} para node_status -t user.p.para. -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY
exit 1
fi
hash=$(${PARA_CLI} send para node -o 3 -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -k 0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b)
echo "${hash}"
query_tx "${PARA_CLI}" "${hash}"
${PARA_CLI} send para node -o 2 -i "$id" -v 1 -k 0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b
${PARA_CLI} send para node -o 2 -i "$id" -v 1 -k 0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4
${PARA_CLI} send para node -o 2 -i "$id" -v 1 -k 0x9c451df9e5cb05b88b28729aeaaeb3169a2414097401fcb4c79c1971df734588
......@@ -651,7 +652,7 @@ function para_nodemanage_node_behalf_join() {
${PARA_CLI} para node_status -t user.p.para. -a 1Luh4AziYyaC5zP3hUXtXFZS873xAxm6rH
exit 1
fi
hash=$(${PARA_CLI} send para node -o 3 -i "$id" -k 0xfdf2bbff853ecff2e7b86b2a8b45726c6538ca7d1403dc94e50131ef379bdca0)
hash=$(${PARA_CLI} send para node -o 4 -i "$id" -k 0xfdf2bbff853ecff2e7b86b2a8b45726c6538ca7d1403dc94e50131ef379bdca0)
echo "${hash}"
query_tx "${PARA_CLI}" "${hash}"
......
......@@ -100,6 +100,20 @@ func (e *Paracross) ExecDelLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeGroupStatusTitle(g.Current.Status, g.Current.Title, g.Current.Id), Value: nil})
}
if log.Ty == pt.TyLogParaNodeConfig {
var g pt.ReceiptParaNodeConfig
err := types.Decode(log.Log, &g)
if err != nil {
return nil, err
}
if g.Prev != nil {
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Prev.Status, g.Prev.Id), Value: types.Encode(g.Prev)})
}
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Current.Status, g.Current.Id), Value: nil})
}
}
return &set, nil
}
......
......@@ -104,6 +104,21 @@ func (e *Paracross) ExecLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig, t
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeGroupStatusTitle(g.Current.Status, g.Current.Title, g.Current.Id), Value: types.Encode(g.Current)})
}
if log.Ty == pt.TyLogParaNodeConfig {
var g pt.ReceiptParaNodeConfig
err := types.Decode(log.Log, &g)
if err != nil {
return nil, err
}
if g.Prev != nil {
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Prev.Status, g.Current.Id), Value: nil})
}
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Current.Status, g.Current.Id),
Value: types.Encode(g.Current)})
}
}
return &set, nil
}
......
......@@ -450,9 +450,6 @@ func (a *action) updateNodeAddrStatus(stat *pt.ParaNodeIdStatus) (*types.Receipt
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
......@@ -463,14 +460,14 @@ func (a *action) updateNodeAddrStatus(stat *pt.ParaNodeIdStatus) (*types.Receipt
}
preStat := *addrStat
if stat.Status == pt.ParacrossNodeJoined {
if stat.Status == pt.ParacrossNodeJoining {
addrStat.Status = pt.ParacrossNodeJoined
addrStat.ProposalId = stat.Id
addrStat.QuitId = ""
return makeParaNodeStatusReceipt(a.fromaddr, &preStat, addrStat), nil
}
if stat.Status == pt.ParacrossNodeQuited {
if stat.Status == pt.ParacrossNodeQuiting {
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)
......@@ -559,7 +556,7 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
receipt := &types.Receipt{Ty: types.ExecOk}
if vote == pt.ParaNodeVoteNo {
if stat.Status == pt.ParacrossNodeJoining {
stat.Status = pt.ParacrossNodeCanceled
stat.Status = pt.ParacrossNodeClosed
stat.Height = a.height
//active coins
if !types.IsPara() {
......@@ -570,7 +567,7 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
receipt = mergeReceipt(receipt, r)
}
} else if stat.Status == pt.ParacrossNodeQuiting {
stat.Status = pt.ParacrossNodeCanceled
stat.Status = pt.ParacrossNodeClosed
stat.Height = a.height
}
......@@ -580,8 +577,6 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
if err != nil {
return nil, err
}
stat.Status = pt.ParacrossNodeJoined
stat.Height = a.height
receipt = mergeReceipt(receipt, r)
r, err = a.updateNodeAddrStatus(stat)
......@@ -589,13 +584,14 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
return nil, err
}
receipt = mergeReceipt(receipt, r)
stat.Status = pt.ParacrossNodeClosed
stat.Height = a.height
} else if stat.Status == pt.ParacrossNodeQuiting {
r, err := unpdateNodeGroup(a.db, config.Title, stat.TargetAddr, false)
if err != nil {
return nil, err
}
stat.Status = pt.ParacrossNodeQuited
stat.Height = a.height
receipt = mergeReceipt(receipt, r)
r, err = a.updateNodeAddrStatus(stat)
......@@ -604,6 +600,8 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
}
receipt = mergeReceipt(receipt, r)
stat.Status = pt.ParacrossNodeClosed
stat.Height = a.height
}
}
r := makeNodeConfigReceipt(a.fromaddr, config, &copyStat, stat)
......@@ -887,7 +885,10 @@ func (a *action) nodeGroupApproveApply(config *pt.ParaNodeGroupConfig, apply *pt
receipt := &types.Receipt{Ty: types.ExecOk}
//create the node group
r := a.nodeGroupCreate(apply)
r,err := a.nodeGroupCreate(apply)
if err != nil{
return nil, errors.Wrapf(err, "nodegroup create:title:%s,addrs:%s", config.Title,apply.TargetAddrs)
}
receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
......@@ -935,7 +936,7 @@ func (a *action) nodeGroupApprove(config *pt.ParaNodeGroupConfig) (*types.Receip
}
func (a *action) nodeGroupCreate(status *pt.ParaNodeGroupStatus) *types.Receipt {
func (a *action) nodeGroupCreate(status *pt.ParaNodeGroupStatus) (*types.Receipt,error) {
nodes := strings.Split(status.TargetAddrs, ",")
var item types.ConfigItem
......@@ -953,7 +954,7 @@ func (a *action) nodeGroupCreate(status *pt.ParaNodeGroupStatus) *types.Receipt
for i, addr := range nodes {
stat := &pt.ParaNodeIdStatus{
Id: status.Id + "-" + strconv.Itoa(i),
Status: pt.ParacrossNodeJoined,
Status: pt.ParacrossNodeClosed,
Title: status.Title,
TargetAddr: addr,
Votes: &pt.ParaNodeVoteDetail{Addrs: []string{a.fromaddr}, Votes: []string{"yes"}},
......@@ -962,10 +963,15 @@ func (a *action) nodeGroupCreate(status *pt.ParaNodeGroupStatus) *types.Receipt
Height: a.height}
r := makeNodeConfigReceipt(a.fromaddr, nil, nil, stat)
receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
receipt = mergeReceipt(receipt,r)
r,err :=a.updateNodeAddrStatus(stat)
if err != nil{
return nil, err
}
receipt = mergeReceipt(receipt,r)
}
return receipt
return receipt,nil
}
//NodeGroupConfig support super node group config
......
......@@ -120,23 +120,18 @@ func checkGroupApplyReceipt(suite *NodeManageTestSuite, receipt *types.Receipt)
func checkGroupApproveReceipt(suite *NodeManageTestSuite, receipt *types.Receipt) {
assert.Equal(suite.T(), receipt.Ty, int32(types.ExecOk))
assert.Len(suite.T(), receipt.KV, 11)
assert.Len(suite.T(), receipt.Logs, 7)
len := len(receipt.KV)
var stat pt.ParaNodeIdStatus
err := types.Decode(receipt.KV[len-1].Value, &stat)
assert.Nil(suite.T(), err, "decode ParaNodeAddrStatus failed")
//suite.T().Log("ty len-1", receipt.Logs[lenLogs-1].Ty,"len",lenLogs)
assert.Equal(suite.T(), int32(pt.TyLogParaNodeGroupStatusUpdate), receipt.Logs[7-1].Ty)
assert.Equal(suite.T(), int32(pt.ParacrossNodeGroupApprove), stat.Status)
}
func checkJoinReceipt(suite *NodeManageTestSuite, receipt *types.Receipt) {
assert.Equal(suite.T(), receipt.Ty, int32(types.ExecOk))
assert.Len(suite.T(), receipt.KV, 2)
assert.Len(suite.T(), receipt.KV, 1)
assert.Len(suite.T(), receipt.Logs, 1)
var stat pt.ParaNodeIdStatus
......@@ -151,7 +146,7 @@ func checkJoinReceipt(suite *NodeManageTestSuite, receipt *types.Receipt) {
func checkQuitReceipt(suite *NodeManageTestSuite, receipt *types.Receipt) {
assert.Equal(suite.T(), receipt.Ty, int32(types.ExecOk))
assert.Len(suite.T(), receipt.KV, 2)
assert.Len(suite.T(), receipt.KV, 1)
assert.Len(suite.T(), receipt.Logs, 1)
var stat pt.ParaNodeIdStatus
......@@ -299,13 +294,17 @@ func (suite *NodeManageTestSuite) testNodeConfig() {
//Quit test
config = &pt.ParaNodeAddrConfig{
Op: pt.ParaNodeQuit,
Id: g.Current.Id,
Addr: Account14K,
}
tx, err = pt.CreateRawNodeConfigTx(config)
suite.Nil(err)
receipt = nodeCommit(suite, PrivKeyD, tx)
checkQuitReceipt(suite, receipt)
suite.Equal(int32(pt.TyLogParaNodeConfig), receipt.Logs[0].Ty)
err = types.Decode(receipt.Logs[0].Log, &g)
suite.Nil(err)
//vote test
voteTest(suite, g.Current.Id, false)
}
......
......@@ -108,14 +108,20 @@ const (
var ParaNodeVoteStr = []string{"invalid", "yes", "no"}
const (
// ParacrossNodeJoining apply for adding group
ParacrossNodeJoining = iota + 1
// ParacrossNodeJoined pass to add by votes
ParacrossNodeJoined
// ParacrossNodeQuiting apply for quiting
ParacrossNodeQuiting
ParacrossNodeJoined =iota + 10
// ParacrossNodeQuited pass to quite by votes
ParacrossNodeQuited
)
//voting status
const (
// ParacrossNodeIDJoining apply for join group
ParacrossNodeJoining = iota
// ParacrossNodeIDQuiting apply for quiting group
ParacrossNodeQuiting
// ParacrossNodeIDClosed id voting closed
ParacrossNodeClosed
// ParacrossNodeCanceled to cancel apply of joining or quiting
ParacrossNodeCanceled
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment