Commit 09f609fb authored by mdj33's avatar mdj33 Committed by vipwzw

modify nodegroup and node

parent dd78db9e
......@@ -251,36 +251,30 @@ func CreateRawNodeManageCmd() *cobra.Command {
}
func addNodeManageFlags(cmd *cobra.Command) {
cmd.Flags().StringP("operation", "o", "", "operation:join,quit,vote")
cmd.Flags().Uint32P("operation", "o", 0, "operation:1:join,2:vote,3:quit")
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().Float64P("coins_frozen", "c", 0, "join to frozen coins amount, not less config")
cmd.Flags().StringP("id", "i", "", "operating target id")
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")
}
func createNodeTx(cmd *cobra.Command, args []string) {
op, _ := cmd.Flags().GetString("operation")
op, _ := cmd.Flags().GetUint32("operation")
opAddr, _ := cmd.Flags().GetString("addr")
val, _ := cmd.Flags().GetString("value")
id, _ := cmd.Flags().GetString("id")
val, _ := cmd.Flags().GetUint32("value")
coins, _ := cmd.Flags().GetFloat64("coins_frozen")
if op != "vote" && op != "quit" && op != "join" {
fmt.Println("operation should be one of join,quit,vote")
return
}
if opAddr == "" {
fmt.Println("addr parameter should not be null")
return
}
if op == "vote" && (val != "yes" && val != "no") {
fmt.Println("vote operation value parameter require yes or no value")
return
}
payload := &pt.ParaNodeAddrConfig{Op: op, Value: val, Addr: opAddr, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
payload := &pt.ParaNodeAddrConfig{Op: op, Id: id, Value: val, Addr: opAddr, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pt.ParaX),
ActionName: "NodeConfig",
......@@ -305,11 +299,12 @@ func CreateNodeGroupApplyCmd() *cobra.Command {
}
func addNodeGroupApplyCmdFlags(cmd *cobra.Command) {
cmd.Flags().Uint32P("operation", "o", 0, "operation:1:apply,2:approve,3:quit")
cmd.Flags().Uint32P("operation", "o", 0, "operation:1:apply,2:approve,3:quit,4:modify")
cmd.MarkFlagRequired("operation")
cmd.Flags().StringP("id", "i", "", "apply id for nodegroup ")
cmd.Flags().StringP("addrs", "a", "", "addrs apply for super node,split by ',' ")
cmd.MarkFlagRequired("addrs")
cmd.Flags().Float64P("coins_frozen", "c", 0, "coins amount to frozen, not less config")
......@@ -318,6 +313,7 @@ func addNodeGroupApplyCmdFlags(cmd *cobra.Command) {
func nodeGroupApply(cmd *cobra.Command, args []string) {
op, _ := cmd.Flags().GetUint32("operation")
addrs, _ := cmd.Flags().GetString("addrs")
id, _ := cmd.Flags().GetString("id")
coins, _ := cmd.Flags().GetFloat64("coins_frozen")
if op == 0 || op > 3 {
......@@ -329,7 +325,7 @@ func nodeGroupApply(cmd *cobra.Command, args []string) {
return
}
payload := &pt.ParaNodeGroupConfig{Op: op, Addrs: addrs, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
payload := &pt.ParaNodeGroupConfig{Op: op, Id: id, Addrs: addrs, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pt.ParaX),
ActionName: "NodeGroupConfig",
......@@ -499,7 +495,7 @@ func nodeInfo(cmd *cobra.Command, args []string) {
Title: title,
Addr: addr,
}
var res pt.ParaNodeAddrStatus
var res pt.ParaNodeIdStatus
ctx := jsonclient.NewRPCCtx(rpcLaddr, "paracross.GetNodeStatus", params, &res)
ctx.Run()
}
......
......@@ -418,7 +418,12 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
return receipt, nil
}
if enableParacrossTransfer && commit.Status.Height > 0 && len(commit.Status.CrossTxHashs) > 0 {
haveCrossTxs := len(commit.Status.CrossTxHashs) > 0
if types.IsDappFork(a.height, pt.ParaX, pt.ForkCommitTx) && commit.Status.CrossTxHashs[0] == nil {
haveCrossTxs = false
}
if enableParacrossTransfer && commit.Status.Height > 0 && haveCrossTxs {
clog.Debug("paracross.Commit commitDone", "do cross", "")
crossTxReceipt, err := a.execCrossTxs(commit)
if err != nil {
......
......@@ -64,11 +64,11 @@ func (e *Paracross) ExecDelLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *
}
if g.Prev != nil {
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Current.ApplyAddr, g.Prev.Status), Value: types.Encode(g.Prev)})
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.ApplyAddr, g.Current.Status), Value: nil})
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Current.Status, g.Current.Id), Value: nil})
} else if log.Ty == pt.TyLogParaNodeVoteDone {
var g pt.ReceiptParaNodeVoteDone
err := types.Decode(log.Log, &g)
......@@ -86,8 +86,7 @@ func (e *Paracross) ExecDelLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *
func (e *Paracross) ExecDelLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
var set types.LocalDBSet
for _, log := range receiptData.Logs {
if log.Ty == pt.TyLogParaNodeGroupApply || log.Ty == pt.TyLogParaNodeGroupApprove ||
log.Ty == pt.TyLogParaNodeGroupQuit {
if log.Ty == pt.TyLogParaNodeGroupConfig {
var g pt.ReceiptParaNodeGroupConfig
err := types.Decode(log.Log, &g)
if err != nil {
......@@ -95,11 +94,11 @@ func (e *Paracross) ExecDelLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig
}
if g.Prev != nil {
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeGroupStatusTitle(g.Prev.Status, g.Current.Title), Value: types.Encode(g.Prev)})
Key: calcLocalNodeGroupStatusTitle(g.Prev.Status, g.Current.Title, g.Current.Id), Value: types.Encode(g.Prev)})
}
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeGroupStatusTitle(g.Current.Status, g.Current.Title), Value: nil})
Key: calcLocalNodeGroupStatusTitle(g.Current.Status, g.Current.Title, g.Current.Id), Value: nil})
}
}
return &set, nil
......
......@@ -67,11 +67,11 @@ func (e *Paracross) ExecLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *typ
}
if g.Prev != nil {
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Current.ApplyAddr, g.Prev.Status), Value: nil})
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.ApplyAddr, g.Current.Status),
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Current.Status, g.Current.Id),
Value: types.Encode(g.Current)})
} else if log.Ty == pt.TyLogParaNodeVoteDone {
var g pt.ReceiptParaNodeVoteDone
......@@ -90,8 +90,7 @@ func (e *Paracross) ExecLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *typ
func (e *Paracross) ExecLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
var set types.LocalDBSet
for _, log := range receiptData.Logs {
if log.Ty == pt.TyLogParaNodeGroupApply || log.Ty == pt.TyLogParaNodeGroupApprove ||
log.Ty == pt.TyLogParaNodeGroupQuit || log.Ty == pt.TyLogParaNodeGroupModify {
if log.Ty == pt.TyLogParaNodeGroupConfig {
var g pt.ReceiptParaNodeGroupConfig
err := types.Decode(log.Log, &g)
if err != nil {
......@@ -99,11 +98,11 @@ func (e *Paracross) ExecLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig, t
}
if g.Prev != nil {
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeGroupStatusTitle(g.Prev.Status, g.Current.Title), Value: nil})
Key: calcLocalNodeGroupStatusTitle(g.Prev.Status, g.Current.Title, g.Current.Id), Value: nil})
}
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeGroupStatusTitle(g.Current.Status, g.Current.Title), Value: types.Encode(g.Current)})
Key: calcLocalNodeGroupStatusTitle(g.Current.Status, g.Current.Title, g.Current.Id), Value: types.Encode(g.Current)})
}
}
return &set, nil
......
......@@ -102,22 +102,30 @@ func calcLocalAssetKey(hash []byte) []byte {
return []byte(fmt.Sprintf(localAssetKey+"%s", hash))
}
func calcLocalNodeTitleStatus(title, addr string, status int32) []byte {
return []byte(fmt.Sprintf(localNodeTitleStatus+"%s-%02d-%s", title, status, addr))
func calcLocalNodeTitleStatus(title string, status int32, id string) []byte {
return []byte(fmt.Sprintf(localNodeTitleStatus+"%s-%02d-%s", title, status, id))
}
func calcLocalNodeStatusPrefix(title string, status int32) []byte {
return []byte(fmt.Sprintf(localNodeTitleStatus+"%s-%02d", title, status))
return []byte(fmt.Sprintf(localNodeTitleStatus+"%s-%02d-", title, status))
}
func calcLocalNodeTitlePrefix(title string) []byte {
return []byte(fmt.Sprintf(localNodeTitleStatus+"%s-", title))
}
func calcLocalNodeTitleDone(title, addr string) []byte {
return []byte(fmt.Sprintf(localNodeTitleDone+"%s-%s", title, addr))
}
func calcLocalNodeGroupStatusTitle(status int32, title string) []byte {
return []byte(fmt.Sprintf(localNodeGroupStatusTitle+"%02d-%s", status, title))
func calcLocalNodeGroupStatusTitle(status int32, title, id string) []byte {
return []byte(fmt.Sprintf(localNodeGroupStatusTitle+"%02d-%s-%s", status, title, id))
}
func calcLocalNodeGroupStatusPrefix(status int32) []byte {
return []byte(fmt.Sprintf(localNodeGroupStatusTitle+"%02d", status))
return []byte(fmt.Sprintf(localNodeGroupStatusTitle+"%02d-", status))
}
func calcLocalNodeGroupAllPrefix() []byte {
return []byte(fmt.Sprintf(localNodeGroupStatusTitle))
}
......@@ -85,7 +85,11 @@ func (p *Paracross) Query_GetNodeAddrInfo(in *pt.ReqParacrossNodeInfo) (types.Me
if in == nil || in.Title == "" || in.Addr == "" {
return nil, types.ErrInvalidParam
}
stat, err := getNodeAddr(p.GetStateDB(), in.Title, in.Addr)
addrStat, err := getNodeAddr(p.GetStateDB(), in.Title, in.Addr)
if err != nil {
return nil, err
}
stat, err := getNodeId(p.GetStateDB(), addrStat.ProposalId)
if err != nil {
return nil, err
}
......@@ -230,7 +234,7 @@ func listNodeStatus(db dbm.KVDB, prefix []byte) (types.Message, error) {
var resp pt.RespParacrossNodeAddrs
for _, r := range res {
var st pt.ParaNodeAddrStatus
var st pt.ParaNodeIdStatus
err = types.Decode(r, &st)
if err != nil {
panic(err)
......
......@@ -108,7 +108,7 @@ func checkGroupApplyReceipt(suite *NodeManageTestSuite, receipt *types.Receipt)
err := types.Decode(receipt.KV[0].Value, &stat)
assert.Nil(suite.T(), err, "decode ParaNodeAddrStatus failed")
//suite.T().Log("titleHeight", titleHeight)
assert.Equal(suite.T(), int32(pt.TyLogParaNodeGroupApply), receipt.Logs[0].Ty)
assert.Equal(suite.T(), int32(pt.TyLogParaNodeGroupConfig), receipt.Logs[0].Ty)
assert.Equal(suite.T(), int32(pt.ParacrossNodeGroupApply), stat.Status)
}
......@@ -124,7 +124,7 @@ func checkGroupApproveReceipt(suite *NodeManageTestSuite, receipt *types.Receipt
err := types.Decode(receipt.KV[len-1].Value, &stat)
assert.Nil(suite.T(), err, "decode ParaNodeAddrStatus failed")
//suite.T().Log("titleHeight", titleHeight)
assert.Equal(suite.T(), int32(pt.TyLogParaNodeGroupApprove), receipt.Logs[len-1].Ty)
assert.Equal(suite.T(), int32(pt.TyLogParaNodeGroupConfig), receipt.Logs[len-1].Ty)
assert.Equal(suite.T(), int32(pt.ParacrossNodeGroupApprove), stat.Status)
}
......
......@@ -47,26 +47,30 @@ message ParacrossConsensusStatus {
string consensBlockHash = 4;
}
message ParaNodeAddrConfig{
message ParaNodeAddrConfig {
string title = 1;
string op = 2;
uint32 op = 2;
string id = 3;
string addr = 4;
string value = 5;
uint32 value = 5;
int64 coinsFrozen = 6;
}
message ParaNodeVoteDetail{
message ParaNodeVoteDetail {
repeated string addrs = 1;
repeated string votes = 2;
}
message ParaNodeAddrStatus{
message ParaNodeAddrIdStatus {
string proposalId = 1;
}
message ParaNodeIdStatus {
string id = 1;
int32 status = 2;
string title = 3;
string applyAddr = 4;
string targetAddr = 4;
int64 coinsFrozen = 5;
ParaNodeVoteDetail votes = 6;
string fromAddr = 7;
......@@ -76,8 +80,8 @@ message ParaNodeAddrStatus{
message ReceiptParaNodeConfig {
string addr = 1;
ParaNodeAddrConfig config = 2;
ParaNodeAddrStatus prev = 3;
ParaNodeAddrStatus current = 4;
ParaNodeIdStatus prev = 3;
ParaNodeIdStatus current = 4;
}
......@@ -107,7 +111,7 @@ message ParaNodeGroupStatus {
string id = 1;
int32 status = 2;
string title = 3;
string applyAddrs = 4;
string targetAddrs = 4;
int64 coinsFrozen = 5;
uint32 emptyBlockInterval = 6;
int64 mainHeight = 7;
......@@ -130,7 +134,7 @@ message ReqParacrossNodeInfo {
}
message RespParacrossNodeAddrs {
repeated ParaNodeAddrStatus addrs = 1;
repeated ParaNodeIdStatus addrs = 1;
}
message RespParacrossNodeGroups {
......
......@@ -180,13 +180,13 @@ func (c *Jrpc) GetBlock2MainInfo(req *types.ReqBlocks, result *interface{}) erro
}
// GetNodeStatus get super node status
func (c *channelClient) GetNodeStatus(ctx context.Context, req *pt.ReqParacrossNodeInfo) (*pt.ParaNodeAddrStatus, error) {
func (c *channelClient) GetNodeStatus(ctx context.Context, req *pt.ReqParacrossNodeInfo) (*pt.ParaNodeIdStatus, error) {
r := *req
data, err := c.Query(pt.GetExecName(), "GetNodeAddrInfo", &r)
if err != nil {
return nil, err
}
if resp, ok := data.(*pt.ParaNodeAddrStatus); ok {
if resp, ok := data.(*pt.ParaNodeIdStatus); ok {
return resp, nil
}
return nil, types.ErrDecode
......
......@@ -40,10 +40,7 @@ const (
TyLogParaNodeConfig = 657
TyLogParaNodeVoteDone = 658
TyLogParaNodeGroupAddrsUpdate = 659
TyLogParaNodeGroupApply = 660
TyLogParaNodeGroupApprove = 661
TyLogParaNodeGroupQuit = 662
TyLogParaNodeGroupModify = 663
TyLogParaNodeGroupConfig = 660
TyLogParaNodeGroupStatusUpdate = 664
)
......@@ -92,14 +89,20 @@ const (
// node config op
const (
ParaNodeJoin = "join"
ParaNodeQuit = "quit"
ParaNodeVote = "vote"
ParaNodeJoin = iota + 1
ParaNodeVote
ParaNodeQuit
)
ParaNodeVoteYes = "yes"
ParaNodeVoteNo = "no"
const (
ParaNodeVoteInvalid = iota
ParaNodeVoteYes
ParaNodeVoteNo
ParaNodeVoteEnd
)
var ParaNodeVoteStr = []string{"invalid", "yes", "no"}
const (
// ParacrossNodeJoining apply for adding group
ParacrossNodeJoining = iota + 1
......@@ -183,6 +186,7 @@ func createRawCommitTx(status *ParacrossNodeStatus, name string, fee int64) (*ty
func CreateRawNodeConfigTx(config *ParaNodeAddrConfig) (*types.Transaction, error) {
config.Title = types.GetTitle()
config.Addr = strings.Trim(config.Addr, " ")
config.Id = strings.Trim(config.Id, " ")
action := &ParacrossAction{
Ty: ParacrossActionNodeConfig,
......@@ -199,6 +203,7 @@ func CreateRawNodeConfigTx(config *ParaNodeAddrConfig) (*types.Transaction, erro
func CreateRawNodeGroupApplyTx(apply *ParaNodeGroupConfig) (*types.Transaction, error) {
apply.Title = types.GetTitle()
apply.EmptyBlockInterval = 4
apply.Id = strings.Trim(apply.Id, " ")
interval := types.Conf("config.consensus.sub.para").GInt("emptyBlockInterval")
if interval > 0 {
apply.EmptyBlockInterval = uint32(interval)
......
......@@ -64,10 +64,7 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
TyLogParaNodeConfig: {Ty: reflect.TypeOf(ReceiptParaNodeConfig{}), Name: "LogParaNodeConfig"},
TyLogParaNodeGroupAddrsUpdate: {Ty: reflect.TypeOf(types.ReceiptConfig{}), Name: "LogParaNodeGroupAddrsUpdate"},
TyLogParaNodeVoteDone: {Ty: reflect.TypeOf(ReceiptParaNodeVoteDone{}), Name: "LogParaNodeVoteDone"},
TyLogParaNodeGroupApply: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupApply"},
TyLogParaNodeGroupApprove: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupApprove"},
TyLogParaNodeGroupQuit: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupQuit"},
TyLogParaNodeGroupModify: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupModify"},
TyLogParaNodeGroupConfig: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupApply"},
TyLogParaNodeGroupStatusUpdate: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupStatusUpdate"},
}
}
......
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