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