Commit 8738c5a7 authored by mdj33's avatar mdj33 Committed by vipwzw

added super manager height process

parent 3417653c
......@@ -329,7 +329,7 @@ func nodeGroupApply(cmd *cobra.Command, args []string) {
return
}
payload := &pt.ParaNodeGroupApply{Op: op, Addrs: addrs, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
payload := &pt.ParaNodeGroupConfig{Op: op, Addrs: addrs, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pt.ParaX),
ActionName: "NodeGroupApply",
......
......@@ -71,6 +71,16 @@ func getNodes(db dbm.KV, key []byte) (map[string]struct{}, []string, error) {
return nodesMap, nodesArray, nil
}
func getConfigManageNodes(db dbm.KV, title string) (map[string]struct{}, []string, error) {
key := calcManageConfigNodesKey(title)
return getNodes(db, key)
}
func getParacrossNodes(db dbm.KV, title string) (map[string]struct{}, []string, error) {
key := calcParaNodeGroupKey(title)
return getNodes(db, key)
}
func validTitle(title string) bool {
if types.IsPara() {
return types.GetTitle() == title
......@@ -214,31 +224,38 @@ func hasCommited(addrs []string, addr string) (bool, int) {
return false, 0
}
func (a *action) getNodesGroup(title string) (map[string]struct{}, error) {
forkHeight := types.GetDappFork(pt.ParaX, pt.ForkCommitTx)
func getDappForkHeight(fork string) int64 {
paraConfigFork := ""
if fork == pt.ForkCommitTx {
paraConfigFork = "MainForkParacrossCommitTx"
}
var forkHeight int64
if types.IsPara() {
forkHeight = types.Conf("config.consensus.sub.para").GInt("MainForkParacrossCommitTx")
forkHeight = types.Conf("config.consensus.sub.para").GInt(paraConfigFork)
if forkHeight <= 0 {
forkHeight = types.MaxHeight
}
} else {
forkHeight = types.GetDappFork(pt.ParaX, fork)
}
if a.exec.GetMainHeight() < forkHeight {
key := calcManageConfigNodesKey(title)
nodes, _, err := getNodes(a.db, key)
return forkHeight
}
func (a *action) getNodesGroup(title string) (map[string]struct{}, error) {
if a.exec.GetMainHeight() < getDappForkHeight(pt.ForkCommitTx) {
nodes, _, err := getConfigManageNodes(a.db, title)
if err != nil {
return nil, errors.Wrapf(err, "getNodes for title:%s", title)
}
return nodes, nil
}
key := calcParaNodeGroupKey(title)
nodes, _, err := getNodes(a.db, key)
nodes, _, err := getParacrossNodes(a.db, title)
if err != nil {
if errors.Cause(err) != pt.ErrTitleNotExist {
return nil, errors.Wrapf(err, "getNodes para for title:%s", title)
}
key = calcManageConfigNodesKey(title)
nodes, _, err = getNodes(a.db, key)
nodes, _, err = getConfigManageNodes(a.db, title)
if err != nil {
return nil, errors.Wrapf(err, "getNodes manager for title:%s", title)
}
......@@ -329,6 +346,9 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
BlockHash: [][]byte{commit.Status.BlockHash},
},
}
if a.exec.GetMainHeight() >= getDappForkHeight(pt.ForkCommitTx) {
stat.MainHeight = commit.Status.MainBlockHeight
}
receipt = makeCommitReceipt(a.fromaddr, commit, nil, stat)
} else {
var copyStat pt.ParacrossHeightStatus
......
......@@ -94,7 +94,7 @@ func (e *Paracross) Exec_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *types.Tr
}
//Exec_NodeGroupConfig node group config process
func (e *Paracross) Exec_NodeGroupConfig(payload *pt.ParaNodeGroupApply, tx *types.Transaction, index int) (*types.Receipt, error) {
func (e *Paracross) Exec_NodeGroupConfig(payload *pt.ParaNodeGroupConfig, tx *types.Transaction, index int) (*types.Receipt, error) {
a := newAction(e, tx)
return a.NodeGroupConfig(payload)
}
......@@ -80,7 +80,7 @@ func (e *Paracross) ExecDelLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *
}
// ExecDelLocal_NodeGroupConfig node group config tx delete process
func (e *Paracross) ExecDelLocal_NodeGroupConfig(payload *pt.ParaNodeGroupApply, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
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 ||
......
......@@ -81,7 +81,7 @@ func (e *Paracross) ExecLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *typ
}
//ExecLocal_NodeGroupConfig node group config add process
func (e *Paracross) ExecLocal_NodeGroupConfig(payload *pt.ParaNodeGroupApply, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
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 ||
......@@ -169,10 +169,7 @@ func (e *Paracross) ExecLocal_Miner(payload *pt.ParacrossMinerAction, tx *types.
var set types.LocalDBSet
txs := e.GetTxs()
forkHeight := types.Conf("config.consensus.sub.para").GInt("MainForkParacrossCommitTx")
if forkHeight == -1 || forkHeight == 0 {
forkHeight = types.MaxHeight
}
forkHeight := getDappForkHeight(pt.ForkCommitTx)
//removed the 0 vote tx
if payload.Status.MainBlockHeight >= forkHeight {
......
......@@ -40,8 +40,7 @@ func (p *Paracross) Query_GetNodeGroupAddrs(in *pt.ReqParacrossNodeInfo) (types.
if in == nil {
return nil, types.ErrInvalidParam
}
key := calcParaNodeGroupKey(in.GetTitle())
ret, _, err := getNodes(p.GetStateDB(), key)
ret, _, err := getParacrossNodes(p.GetStateDB(), in.GetTitle())
if err != nil {
return nil, errors.Cause(err)
}
......@@ -50,7 +49,7 @@ func (p *Paracross) Query_GetNodeGroupAddrs(in *pt.ReqParacrossNodeInfo) (types.
nodes = append(nodes, k)
}
var reply types.ReplyConfig
reply.Key = string(key)
reply.Key = string(calcParaNodeGroupKey(in.GetTitle()))
reply.Value = fmt.Sprint(nodes)
return &reply, nil
}
......@@ -60,8 +59,7 @@ func (p *Paracross) Query_GetNodeAddrInfo(in *pt.ReqParacrossNodeInfo) (types.Me
if in == nil || in.Title == "" || in.Addr == "" {
return nil, types.ErrInvalidParam
}
key := calcParaNodeAddrKey(in.Title, in.Addr)
stat, err := getNodeAddr(p.GetStateDB(), key)
stat, err := getNodeAddr(p.GetStateDB(), in.Title, in.Addr)
if err != nil {
return nil, err
}
......@@ -81,8 +79,7 @@ func (p *Paracross) Query_GetNodeGroupStatus(in *pt.ReqParacrossNodeInfo) (types
if in == nil || in.Title == "" {
return nil, types.ErrInvalidParam
}
key := calcParaNodeGroupApplyKey(in.Title)
stat, err := getNodeAddr(p.GetStateDB(), key)
stat, err := getNodeGroupStatus(p.GetStateDB(), in.Title)
if err != nil {
return nil, err
}
......@@ -158,6 +155,14 @@ func (p *Paracross) paracrossGetHeight(title string) (types.Message, error) {
return ret, nil
}
func (p *Paracross) paracrossGetStateTitleHeight(title string, height int64) (types.Message, error) {
ret, err := getTitleHeight(p.GetStateDB(), calcTitleHeightKey(title, height))
if err != nil {
return nil, errors.Cause(err)
}
return ret, nil
}
func (p *Paracross) paracrossListTitles() (types.Message, error) {
return listLocalTitles(p.GetLocalDB())
}
......
......@@ -31,7 +31,8 @@ func deepCopy(dst, src interface{}) error {
return gob.NewDecoder(bytes.NewBuffer(buf.Bytes())).Decode(dst)
}
func getNodeAddr(db dbm.KV, key []byte) (*pt.ParaNodeAddrStatus, error) {
func getNodeAddr(db dbm.KV, title, addr string) (*pt.ParaNodeAddrStatus, error) {
key := calcParaNodeAddrKey(title, addr)
val, err := db.Get(key)
if err != nil {
return nil, err
......@@ -42,11 +43,33 @@ func getNodeAddr(db dbm.KV, key []byte) (*pt.ParaNodeAddrStatus, error) {
return &status, err
}
func saveNodeAddr(db dbm.KV, key []byte, status types.Message) error {
func getNodeGroupStatus(db dbm.KV, title string) (*pt.ParaNodeGroupStatus, error) {
key := calcParaNodeGroupApplyKey(title)
val, err := db.Get(key)
if err != nil {
return nil, err
}
var status pt.ParaNodeGroupStatus
err = types.Decode(val, &status)
return &status, err
}
func saveDb(db dbm.KV, key []byte, status types.Message) error {
val := types.Encode(status)
return db.Set(key, val)
}
func saveNodeAddr(db dbm.KV, title, addr string, status types.Message) error {
key := calcParaNodeAddrKey(title, addr)
return saveDb(db, key, status)
}
func saveNodeGroup(db dbm.KV, title string, status types.Message) error {
key := calcParaNodeGroupApplyKey(title)
return saveDb(db, key, status)
}
func makeVoteDoneReceipt(config *pt.ParaNodeAddrConfig, totalCount, commitCount, most int, pass string, status int32) *types.Receipt {
log := &pt.ReceiptParaNodeVoteDone{
Title: config.Title,
......@@ -92,9 +115,9 @@ func makeNodeConfigReceipt(addr string, config *pt.ParaNodeAddrConfig, prev, cur
}
}
func makeParaNodeGroupApplyReiceipt(title, addr string, prev, current *pt.ParaNodeAddrStatus, logTy int32) *types.Receipt {
func makeParaNodeGroupApplyReiceipt(title, addr string, prev, current *pt.ParaNodeGroupStatus, logTy int32) *types.Receipt {
key := calcParaNodeGroupApplyKey(title)
log := &pt.ReceiptParaNodeConfig{
log := &pt.ReceiptParaNodeGroupConfig{
Addr: addr,
Prev: prev,
Current: current,
......@@ -131,8 +154,7 @@ func makeParaNodeGroupReiceipt(title string, prev, current *types.ConfigItem) *t
}
func (a *action) nodeJoin(config *pt.ParaNodeAddrConfig) (*types.Receipt, error) {
key := calcParaNodeGroupKey(config.Title)
nodes, _, err := getNodes(a.db, key)
nodes, _, err := getParacrossNodes(a.db, config.Title)
if err != nil {
return nil, errors.Wrapf(err, "getNodes for title:%s", config.Title)
}
......@@ -150,19 +172,18 @@ func (a *action) nodeJoin(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
receipt.Logs = append(receipt.Logs, r.Logs...)
}
key = calcParaNodeAddrKey(config.Title, config.Addr)
stat, err := getNodeAddr(a.db, key)
stat, err := getNodeAddr(a.db, config.Title, config.Addr)
if err != nil {
if !isNotFound(err) {
return nil, err
}
clog.Info("first time add node addr", "key", string(key))
clog.Info("first time add node addr", "title", config.Title, "addr", config.Addr)
stat := &pt.ParaNodeAddrStatus{Status: pt.ParacrossNodeAdding,
Title: config.Title,
ApplyAddr: config.Addr,
Votes: &pt.ParaNodeVoteDetail{},
CoinsFrozen: config.CoinsFrozen}
saveNodeAddr(a.db, key, stat)
saveNodeAddr(a.db, config.Title, config.Addr, stat)
r := makeNodeConfigReceipt(a.fromaddr, config, nil, stat)
receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
......@@ -176,13 +197,13 @@ func (a *action) nodeJoin(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
return nil, err
}
if stat.Status != pt.ParacrossNodeQuited {
clog.Error("nodeaccount.nodeJoin key exist", "key", string(key), "status", stat)
clog.Error("nodeaccount.nodeJoin key exist", "addr", config.Addr, "status", stat)
return nil, pt.ErrParaNodeAddrExisted
}
stat.Status = pt.ParacrossNodeAdding
stat.CoinsFrozen = config.CoinsFrozen
stat.Votes = &pt.ParaNodeVoteDetail{}
saveNodeAddr(a.db, key, stat)
saveNodeAddr(a.db, config.Title, config.Addr, stat)
r := makeNodeConfigReceipt(a.fromaddr, config, &copyStat, stat)
receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
......@@ -191,20 +212,18 @@ func (a *action) nodeJoin(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
}
func (a *action) nodeQuit(config *pt.ParaNodeAddrConfig) (*types.Receipt, error) {
addrKey := calcParaNodeAddrKey(config.Title, config.Addr)
stat, err := getNodeAddr(a.db, addrKey)
stat, err := getNodeAddr(a.db, config.Title, config.Addr)
if err != nil {
return nil, err
}
if stat.Status == pt.ParacrossNodeQuiting || stat.Status == pt.ParacrossNodeQuited {
clog.Error("nodeaccount.nodeQuit wrong status", "key", string(addrKey), "status", stat)
clog.Error("nodeaccount.nodeQuit wrong status", "status", stat)
return nil, errors.Wrapf(pt.ErrParaUnSupportNodeOper, "nodeAddr %s was quit status:%d", a.fromaddr, stat.Status)
}
if stat.Status == pt.ParacrossNodeAdded {
groupKey := calcParaNodeGroupKey(config.Title)
nodes, _, err := getNodes(a.db, groupKey)
nodes, _, err := getParacrossNodes(a.db, config.Title)
if err != nil {
return nil, errors.Wrapf(err, "getNodes for title:%s", config.Title)
}
......@@ -226,7 +245,7 @@ func (a *action) nodeQuit(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
if stat.Status == pt.ParacrossNodeAdded {
stat.Status = pt.ParacrossNodeQuiting
stat.Votes = &pt.ParaNodeVoteDetail{}
saveNodeAddr(a.db, addrKey, stat)
saveNodeAddr(a.db, config.Title, config.Addr, stat)
return makeNodeConfigReceipt(a.fromaddr, config, &copyStat, stat), nil
}
......@@ -243,7 +262,7 @@ func (a *action) nodeQuit(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
stat.Status = pt.ParacrossNodeQuited
stat.Votes = &pt.ParaNodeVoteDetail{}
saveNodeAddr(a.db, addrKey, stat)
saveNodeAddr(a.db, config.Title, config.Addr, stat)
r := makeNodeConfigReceipt(a.fromaddr, config, &copyStat, stat)
receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
......@@ -282,9 +301,44 @@ func hasVoted(addrs []string, addr string) (bool, int) {
return hasCommited(addrs, addr)
}
//主链配置平行链停止块数, 反应到主链上为对应平行链空块间隔×停止块数,如果主链当前高度超过平行链共识高度对应主链高度后面这个主链块数就表示通过
func (a *action) superManagerVoteProc(title string) error {
status, err := getNodeGroupStatus(a.db, title)
if err != nil {
return err
}
if status.Status != pt.ParacrossNodeGroupApprove {
return pt.ErrParaNodeGroupStatusWrong
}
confStopBlocks := conf.GInt("paraConsensusStopBlocks")
data, err := a.exec.paracrossGetHeight(title)
if err != nil {
clog.Info("paracross.nodeVote get consens height", "err", err.Error())
return err
}
var consensMainHeight int64
consensHeight := data.(*pt.ParacrossStatus).Height
//如果group建立后一直没有共识,则从approve时候开始算
if consensHeight == -1 {
consensMainHeight = status.MainHeight
} else {
stat, err := a.exec.paracrossGetStateTitleHeight(title, consensMainHeight)
if err != nil {
return err
}
consensMainHeight = stat.(*pt.ParacrossHeightStatus).MainHeight
}
//return err to stop tx pass to para chain
if a.exec.GetMainHeight() <= consensMainHeight+confStopBlocks*int64(status.EmptyBlockInterval) {
clog.Error("paracross.nodeVote, super manager height not reach", "currHeight", a.exec.GetMainHeight(), "consensHeight", consensHeight, "confHeight", confStopBlocks)
return pt.ErrParaConsensStopBlocksNotReach
}
return nil
}
func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error) {
key := calcParaNodeGroupKey(config.Title)
nodes, _, err := getNodes(a.db, key)
nodes, _, err := getParacrossNodes(a.db, config.Title)
if err != nil {
return nil, errors.Wrapf(err, "getNodes for title:%s", config.Title)
}
......@@ -307,8 +361,7 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
nodes = temp
}
key = calcParaNodeAddrKey(config.Title, config.Addr)
stat, err := getNodeAddr(a.db, key)
stat, err := getNodeAddr(a.db, config.Title, config.Addr)
if err != nil {
return nil, err
}
......@@ -334,24 +387,19 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
if !isCommitDone(stat, nodes, most) {
superManagerPass := false
if isSuperManager(a.fromaddr) {
confStopBlocks := conf.GInt("paraConsensusStopBlocks")
data, err := a.exec.paracrossGetHeight(config.Title)
//如果主链执行失败,交易不会过滤到平行链,如果主链成功,平行链直接成功
if !types.IsPara() {
err := a.superManagerVoteProc(config.Title)
if err != nil {
clog.Info("paracross.nodeVote get consens height", "err", err.Error())
return nil, err
}
consensHeight := data.(*pt.ParacrossStatus).Height
//return err to stop tx pass to para chain
if a.exec.GetMainHeight() <= consensHeight+confStopBlocks {
clog.Error("paracross.nodeVote, super manager height not reach", "currHeight", a.exec.GetMainHeight(), "consensHeight", consensHeight, "confHeight", confStopBlocks)
return nil, pt.ErrParaConsensStopBlocksNotReach
}
superManagerPass = true
}
//超级用户投yes票,共识停止了一定高度就可以通过,防止当前所有授权节点都忘掉私钥场景
if !(superManagerPass && most > 0 && vote == pt.ParaNodeVoteYes) {
saveNodeAddr(a.db, key, stat)
saveNodeAddr(a.db, config.Title, config.Addr, stat)
return makeNodeConfigReceipt(a.fromaddr, config, &copyStat, stat), nil
}
}
......@@ -391,7 +439,7 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
}
}
}
saveNodeAddr(a.db, key, stat)
saveNodeAddr(a.db, config.Title, config.Addr, stat)
receipt := makeNodeConfigReceipt(a.fromaddr, config, &copyStat, stat)
if receiptGroup != nil {
receipt.KV = append(receipt.KV, receiptGroup.KV...)
......@@ -547,9 +595,8 @@ func (a *action) nodeGroupCoinsActive(addrs []string, configCoinsFrozen int64) (
}
// NodeGroupApply
func (a *action) nodeGroupApply(config *pt.ParaNodeGroupApply) (*types.Receipt, error) {
key := calcParaNodeGroupApplyKey(config.Title)
status, err := getNodeAddr(a.db, key)
func (a *action) nodeGroupApply(config *pt.ParaNodeGroupConfig) (*types.Receipt, error) {
status, err := getNodeGroupStatus(a.db, config.Title)
if err != nil && !isNotFound(err) {
return nil, err
}
......@@ -571,11 +618,12 @@ func (a *action) nodeGroupApply(config *pt.ParaNodeGroupApply) (*types.Receipt,
receipt.Logs = append(receipt.Logs, r.Logs...)
}
stat := &pt.ParaNodeAddrStatus{Status: pt.ParacrossNodeGroupApply,
stat := &pt.ParaNodeGroupStatus{Status: pt.ParacrossNodeGroupApply,
Title: config.Title,
ApplyAddr: strings.Join(addrs, ","),
CoinsFrozen: config.CoinsFrozen}
saveNodeAddr(a.db, key, stat)
CoinsFrozen: config.CoinsFrozen,
MainHeight: a.exec.GetMainHeight()}
saveNodeGroup(a.db, config.Title, stat)
r := makeParaNodeGroupApplyReiceipt(config.Title, a.fromaddr, status, stat, pt.TyLogParaNodeGroupApply)
receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
......@@ -583,9 +631,8 @@ func (a *action) nodeGroupApply(config *pt.ParaNodeGroupApply) (*types.Receipt,
return receipt, nil
}
func (a *action) nodeGroupQuit(config *pt.ParaNodeGroupApply) (*types.Receipt, error) {
key := calcParaNodeGroupApplyKey(config.Title)
status, err := getNodeAddr(a.db, key)
func (a *action) nodeGroupQuit(config *pt.ParaNodeGroupConfig) (*types.Receipt, error) {
status, err := getNodeGroupStatus(a.db, config.Title)
if err != nil {
return nil, err
}
......@@ -610,11 +657,12 @@ func (a *action) nodeGroupQuit(config *pt.ParaNodeGroupApply) (*types.Receipt, e
receipt.Logs = append(receipt.Logs, r.Logs...)
}
stat := &pt.ParaNodeAddrStatus{Status: pt.ParacrossNodeGroupQuit,
stat := &pt.ParaNodeGroupStatus{Status: pt.ParacrossNodeGroupQuit,
Title: config.Title,
ApplyAddr: status.ApplyAddr,
CoinsFrozen: status.CoinsFrozen}
saveNodeAddr(a.db, key, stat)
CoinsFrozen: status.CoinsFrozen,
MainHeight: a.exec.GetMainHeight()}
saveNodeGroup(a.db, config.Title, stat)
r := makeParaNodeGroupApplyReiceipt(config.Title, a.fromaddr, status, stat, pt.TyLogParaNodeGroupQuit)
receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
......@@ -654,14 +702,13 @@ func checkNodeGroupAddrsMatch(applyAddr, confAddr string) ([]string, error) {
}
// NodeGroupApprove super addr approve the node group apply
func (a *action) nodeGroupApprove(config *pt.ParaNodeGroupApply) (*types.Receipt, error) {
func (a *action) nodeGroupApprove(config *pt.ParaNodeGroupConfig) (*types.Receipt, error) {
if !isSuperManager(a.fromaddr) {
clog.Error("node group approve not super manager", "addr", a.fromaddr)
return nil, types.ErrNotAllow
}
key := calcParaNodeGroupApplyKey(config.Title)
status, err := getNodeAddr(a.db, key)
status, err := getNodeGroupStatus(a.db, config.Title)
if err != nil {
return nil, err
}
......@@ -684,11 +731,12 @@ func (a *action) nodeGroupApprove(config *pt.ParaNodeGroupApply) (*types.Receipt
receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
stat := &pt.ParaNodeAddrStatus{Status: pt.ParacrossNodeGroupApprove,
stat := &pt.ParaNodeGroupStatus{Status: pt.ParacrossNodeGroupApprove,
Title: config.Title,
ApplyAddr: status.ApplyAddr,
CoinsFrozen: status.CoinsFrozen}
saveNodeAddr(a.db, key, stat)
CoinsFrozen: status.CoinsFrozen,
MainHeight: a.exec.GetMainHeight()}
saveNodeGroup(a.db, config.Title, stat)
r = makeParaNodeGroupApplyReiceipt(config.Title, a.fromaddr, status, stat, pt.TyLogParaNodeGroupApprove)
receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
......@@ -711,13 +759,12 @@ func (a *action) nodeGroupCreate(title string, nodes []string, coinFrozen int64)
//update addr status
for _, addr := range nodes {
key = calcParaNodeAddrKey(title, addr)
stat := &pt.ParaNodeAddrStatus{Status: pt.ParacrossNodeAdded,
Title: title,
ApplyAddr: addr,
Votes: &pt.ParaNodeVoteDetail{},
CoinsFrozen: coinFrozen}
saveNodeAddr(a.db, key, stat)
saveNodeAddr(a.db, title, addr, stat)
config := &pt.ParaNodeAddrConfig{
Title: title,
Addr: addr,
......@@ -731,7 +778,7 @@ func (a *action) nodeGroupCreate(title string, nodes []string, coinFrozen int64)
}
//NodeGroupConfig support super node group config
func (a *action) NodeGroupConfig(config *pt.ParaNodeGroupApply) (*types.Receipt, error) {
func (a *action) NodeGroupConfig(config *pt.ParaNodeGroupConfig) (*types.Receipt, error) {
if !validTitle(config.Title) {
return nil, pt.ErrInvalidTitle
}
......
......@@ -82,7 +82,7 @@ message ReceiptParaNodeVoteDone {
}
message ParaNodeGroupApply{
message ParaNodeGroupConfig {
string title = 1;
uint32 op = 2;
string addrs = 3;
......@@ -91,6 +91,23 @@ message ParaNodeGroupApply{
}
message ParaNodeGroupStatus {
int32 status = 1;
string title = 2;
string applyAddr = 3;
int64 coinsFrozen = 4;
uint32 emptyBlockInterval = 5;
int64 mainHeight = 6;
}
message ReceiptParaNodeGroupConfig {
string addr = 1;
ParaNodeGroupConfig config = 2;
ParaNodeGroupStatus prev = 3;
ParaNodeGroupStatus current = 4;
}
// node query
message ReqParacrossNodeInfo {
string title = 1;
......@@ -149,7 +166,7 @@ message ParacrossAction {
AssetsWithdraw withdraw = 7;
AssetsTransferToExec transferToExec = 8;
ParaNodeAddrConfig nodeConfig = 9;
ParaNodeGroupApply nodeGroupConfig= 10;
ParaNodeGroupConfig nodeGroupConfig = 10;
}
......
......@@ -190,8 +190,13 @@ func CreateRawNodeConfigTx(config *ParaNodeAddrConfig) (*types.Transaction, erro
}
//CreateRawNodeGroupApplyTx create raw tx for node group
func CreateRawNodeGroupApplyTx(apply *ParaNodeGroupApply) (*types.Transaction, error) {
func CreateRawNodeGroupApplyTx(apply *ParaNodeGroupConfig) (*types.Transaction, error) {
apply.Title = types.GetTitle()
apply.EmptyBlockInterval = 4
interval := types.Conf("config.consensus.sub.para").GInt("emptyBlockInterval")
if interval > 0 {
apply.EmptyBlockInterval = uint32(interval)
}
action := &ParacrossAction{
Ty: ParacrossActionNodeGroupApply,
......
......@@ -130,7 +130,7 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
if !types.IsPara() {
return nil, types.ErrNotSupport
}
var param ParaNodeGroupApply
var param ParaNodeGroupConfig
err := types.JSONToPB(message, &param)
//err := json.Unmarshal(message, &param)
if err != nil {
......
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