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