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())
}
......
......@@ -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