Commit b1ed6b60 authored by mdj33's avatar mdj33 Committed by 33cn

refactor para bind miner

parent 808969f4
......@@ -345,6 +345,7 @@ func superNodeCmd() *cobra.Command {
cmd.AddCommand(getNodeListCmd())
cmd.AddCommand(nodeModifyCmd())
cmd.AddCommand(getNodeBindListCmd())
cmd.AddCommand(getMinerBindListCmd())
return cmd
}
......@@ -598,8 +599,44 @@ func createNodeBindTx(cmd *cobra.Command, args []string) {
func getNodeBindListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "bind_list",
Use: "miner_list",
Short: "Get node bind miner account list",
Run: minerBindInfo,
}
addMinerBindCmdFlags(cmd)
return cmd
}
func addMinerBindCmdFlags(cmd *cobra.Command) {
cmd.Flags().StringP("node", "n", "", "super node addr to bind miner")
cmd.MarkFlagRequired("node")
cmd.Flags().StringP("miner", "m", "", "bind miner addr")
cmd.Flags().BoolP("unbind", "u", false, "query with unbinded miner,default false")
}
func minerBindInfo(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
node, _ := cmd.Flags().GetString("node")
miner, _ := cmd.Flags().GetString("miner")
unbind, _ := cmd.Flags().GetBool("unbind")
var params rpctypes.Query4Jrpc
params.Execer = pt.ParaX
params.FuncName = "GetNodeBindMinerList"
params.Payload = types.MustPBToJSON(&pt.ParaNodeMinerListReq{Node: node, Miner: miner, WithUnBind: unbind})
var res pt.ParaBindMinerList
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run()
}
func getMinerBindListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "node_list",
Short: "Get miner bind consensus node account list",
Run: nodeBindInfo,
}
addNodeBindCmdFlags(cmd)
......@@ -607,22 +644,21 @@ func getNodeBindListCmd() *cobra.Command {
}
func addNodeBindCmdFlags(cmd *cobra.Command) {
cmd.Flags().StringP("node", "n", "", "super node addr to bind miner")
cmd.Flags().StringP("miner", "m", "", "bind miner addr")
cmd.MarkFlagRequired("miner")
}
func nodeBindInfo(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
node, _ := cmd.Flags().GetString("node")
miner, _ := cmd.Flags().GetString("miner")
var params rpctypes.Query4Jrpc
params.Execer = pt.ParaX
params.FuncName = "GetNodeBindMinerList"
params.FuncName = "GetMinerBindNodeList"
params.Payload = types.MustPBToJSON(&pt.ParaNodeBindOne{SuperNode: node, Miner: miner})
params.Payload = types.MustPBToJSON(&types.ReqString{Data: miner})
var res pt.RespParaNodeBindList
var res types.ReplyStrings
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run()
}
......
This diff is collapsed.
......@@ -36,8 +36,8 @@ var (
paraSelfConsensStages string
paraSelfConsensStageIDPrefix string
paraBindMinderAddr string
paraBindMinderNode string
paraBindMinderAddr string
//监督节点
paraSupervisionNodes string
......@@ -58,9 +58,9 @@ func setPrefix() {
paraSelfConsensStages = "mavl-paracross-selfconsens-stages-"
paraSelfConsensStageIDPrefix = "mavl-paracross-selfconsens-id-"
//bind miner
paraBindMinderAddr = "mavl-paracross-bindmineraddr-"
//bind miner,node和miner角色要区分开,不然如果miner也是node,就会混淆
paraBindMinderNode = "mavl-paracross-bindminernode-"
paraBindMinderAddr = "mavl-paracross-bindmineraddr-"
localTx = "LODB-paracross-titleHeightAddr-"
localTitle = "LODB-paracross-title-"
......@@ -195,15 +195,32 @@ func calcLocalNodeGroupAllPrefix() []byte {
return []byte(fmt.Sprintf(localNodeGroupStatusTitle))
}
//bind miner
func calcParaBindMinerAddr(node, bind string) []byte {
return []byte(fmt.Sprintf(paraBindMinderAddr+"%s-%s", node, bind))
/////bind miner
//统计共识节点绑定挖矿地址总数量
//key: prefix-nodeAddr val: bindTotalCount
func calcParaNodeBindMinerCount(node string) []byte {
return []byte(fmt.Sprintf(paraBindMinderNode+"%s", node))
}
//记录共识节点某一索引绑定的挖矿地址,一一对应,以此地址获取更详细信息
//key: prefix-nodeAddr-index val:bindMinerAddr
func calcParaNodeBindMinerIndex(node string, index int64) []byte {
return []byte(fmt.Sprintf(paraBindMinderNode+"%s-%d", node, index))
}
//记录node和miner bind详细信息
//key: prefix-nodeAddr-miner val:miner detail info
func calcParaBindMinerAddr(node, miner string) []byte {
return []byte(fmt.Sprintf(paraBindMinderNode+"%s-%s", node, miner))
}
func calcParaBindMinerNode() []byte {
return []byte(paraBindMinderNode)
//key: prefix-minerAddr val: node list
func calcParaMinerBindNodeList(miner string) []byte {
return []byte(fmt.Sprintf(paraBindMinderAddr+"%s", miner))
}
/////supervision
func calcParaSupervisionNodeGroupAddrsKey(title string) []byte {
return []byte(fmt.Sprintf(paraSupervisionNodes+"%s", title))
}
......
......@@ -598,63 +598,58 @@ func (p *Paracross) Query_GetHeight(req *types.ReqString) (*pt.ParacrossConsensu
return nil, types.ErrDecode
}
func getMinerListResp(db dbm.KV, list *pt.ParaNodeBindList) (types.Message, error) {
var resp pt.RespParaNodeBindList
resp.List = list
// Query_GetNodeBindMinerList query get super node bind miner list
func (p *Paracross) Query_GetNodeBindMinerList(in *pt.ParaNodeMinerListReq) (types.Message, error) {
if in == nil || len(in.Node) <= 0 {
return nil, types.ErrInvalidParam
}
db := p.GetStateDB()
var lists pt.ParaBindMinerList
for _, n := range list.Miners {
info, err := getBindAddrInfo(db, n.SuperNode, n.Miner)
//单独查询 node-miner 绑定
if len(in.Miner) > 0 {
minerInfo, err := getBindAddrInfo(db, in.Node, in.Miner)
if err != nil {
clog.Error("Query_GetNodeBindMinerList get addr", "err", err, "node", n.SuperNode, "addr", n.Miner)
return nil, errors.Cause(err)
return nil, err
}
resp.Details = append(resp.Details, info)
lists.List = append(lists.List, minerInfo)
return &lists, nil
}
return &resp, nil
}
// Query_GetNodeBindMinerList query get super node bind miner list
func (p *Paracross) Query_GetNodeBindMinerList(in *pt.ParaNodeBindOne) (types.Message, error) {
if in == nil {
return nil, types.ErrInvalidParam
}
list, err := getBindNodeInfo(p.GetStateDB())
//按node query all
//从内存获取
miners, err := getBindMinerList(db, in.Node)
if err != nil {
clog.Error("Query_GetNodeBindMinerList get node", "err", err)
return nil, errors.Cause(err)
return nil, err
}
var newList pt.ParaNodeBindList
//按node query
if len(in.SuperNode) != 0 && len(in.Miner) == 0 {
for _, n := range list.Miners {
if n.SuperNode == in.SuperNode {
newList.Miners = append(newList.Miners, n)
if in.WithUnBind {
lists.List = append(lists.List, miners...)
} else {
for _, m := range miners {
if m.BindStatus == opBind {
lists.List = append(lists.List, m)
}
}
return getMinerListResp(p.GetStateDB(), &newList)
}
//按miner query
if len(in.SuperNode) == 0 && len(in.Miner) != 0 {
for _, n := range list.Miners {
if n.Miner == in.Miner {
newList.Miners = append(newList.Miners, n)
}
}
return getMinerListResp(p.GetStateDB(), &newList)
}
//按唯一绑定查询
if len(in.SuperNode) != 0 && len(in.Miner) != 0 {
for _, n := range list.Miners {
if n.SuperNode == in.SuperNode && n.Miner == in.Miner {
newList.Miners = append(newList.Miners, n)
}
}
return getMinerListResp(p.GetStateDB(), &newList)
return &lists, nil
}
// Query_GetMinerBindNodeList query get miner bind super node list
func (p *Paracross) Query_GetMinerBindNodeList(in *types.ReqString) (types.Message, error) {
if in == nil || len(in.Data) <= 0 {
return nil, types.ErrInvalidParam
}
//获取所有
return getMinerListResp(p.GetStateDB(), list)
db := p.GetStateDB()
nodeInfo, err := getMinerBindNodeList(db, in.Data)
if err != nil {
return nil, errors.Wrapf(err, "getBindNodeCount miner=%s", in.Data)
}
var nodeAddrs types.ReplyStrings
nodeAddrs.Datas = append(nodeAddrs.Datas, nodeInfo.Nodes...)
return &nodeAddrs, nil
}
This diff is collapsed.
syntax = "proto3";
import "transaction.proto";
package types;
option go_package = "../types";
message ParaBlsSignSumDetails {
int64 height = 1;
repeated string addrs = 2;
repeated bytes msgs = 3;
repeated bytes signs = 4;
}
message ParaBlsSignSumDetailsShow {
int64 height = 1;
repeated string addrs = 2;
repeated string msgs = 3;
}
message ParaBlsSignSumInfo {
repeated ParaBlsSignSumDetailsShow info = 1;
repeated string topics = 2;
}
message LeaderSyncInfo {
string ID = 1; //self id
int32 baseIdx = 2; //calculated by corrent consensus height and remainder by len(nodes)
int32 offset = 3;
uint32 count = 4; //发送计数器
}
message ParaP2PSubMsg {
int32 ty = 1;
oneof value {
Transaction commitTx = 10;
LeaderSyncInfo syncMsg = 11;
}
}
//bls sign leader info
message ElectionStatus {
bool isLeader = 1;
LeaderSyncInfo leader = 2;
}
message BlsPubKey{
string key = 1;
}
syntax = "proto3";
import "transaction.proto";
package types;
option go_package = "../types";
message ParaLocalDbBlock {
int64 height = 1;
bytes mainHash = 2;
int64 mainHeight = 3;
bytes parentMainHash = 4;
int64 blockTime = 5;
repeated Transaction txs = 6;
}
message ParaLocalDbBlockInfo {
int64 height = 1;
string mainHash = 2;
int64 mainHeight = 3;
string parentMainHash = 4;
int64 blockTime = 5;
repeated string txs = 6;
}
......@@ -4,6 +4,9 @@ import "transaction.proto";
import "common.proto";
import "blockchain.proto";
import "paraminer.proto";
import "paranodegroup.proto";
package types;
option go_package = "../types";
......@@ -58,152 +61,6 @@ message ParacrossConsensusStatus {
string consensBlockHash = 4;
}
message ParaNodeAddrConfig {
string title = 1;
uint32 op = 2;
string id = 3;
string addr = 4;
uint32 value = 5;
int64 coinsFrozen = 6;
string blsPubKey = 7; //本地址私钥对应的bls聚合签名的公钥
}
message ParaNodeVoteDetail {
repeated string addrs = 1;
repeated string votes = 2;
}
message ParaNodeAddrIdStatus {
string addr = 1;
string proposalId = 2;
string quitId = 3;
int32 status = 4;
string title = 5;
string blsPubKey = 6;
}
message ParaNodeIdStatus {
string id = 1;
int32 status = 2;
string title = 3;
string targetAddr = 4;
int64 coinsFrozen = 5;
ParaNodeVoteDetail votes = 6;
string fromAddr = 7;
int64 height = 8;
string blsPubKey = 9;
}
message ReceiptParaNodeConfig {
string addr = 1;
ParaNodeAddrConfig config = 2;
ParaNodeIdStatus prev = 3;
ParaNodeIdStatus current = 4;
}
message ReceiptParaNodeAddrStatUpdate {
string fromAddr = 1;
ParaNodeAddrIdStatus prev = 2;
ParaNodeAddrIdStatus current = 3;
}
message ReceiptParaNodeVoteDone {
string id = 1;
string title = 2;
string targetAddr = 3;
int32 totalNodes = 4;
int32 totalVote = 5;
int32 mostVote = 6;
string voteRst = 7;
int32 doneStatus = 8;
}
message ParaNodeGroupConfig {
string title = 1;
uint32 op = 2;
string id = 3;
string addrs = 4;
int64 coinsFrozen = 5;
string blsPubKeys = 6;
string autonomyItemID = 7;
}
message ParaNodeGroupStatus {
string id = 1;
int32 status = 2;
string title = 3;
string targetAddrs = 4;
int64 coinsFrozen = 5;
string fromAddr = 6;
int64 height = 7;
string blsPubKeys = 8;
}
message ReceiptParaNodeGroupConfig {
string addr = 1;
ParaNodeGroupConfig config = 2;
ParaNodeGroupStatus prev = 3;
ParaNodeGroupStatus current = 4;
}
// node query
message ReqParacrossNodeInfo {
string title = 1;
string id = 2;
string addr = 3;
int32 status = 4;
string blsPubKey = 5;
}
message RespParacrossNodeAddrs {
repeated ParaNodeIdStatus ids = 1;
}
message RespParacrossNodeGroups {
repeated ParaNodeGroupStatus ids = 1;
}
//para bind miner
message ParaBindMinerCmd{
int32 bindAction = 1; // 1: bind, 2:unbind
int64 bindCoins = 2; // bind coins count
string targetNode = 3; // super node addr
}
message ParaBindMinerInfo{
string addr = 1; // miner addr
int32 bindStatus = 2; // 1: bind, 2:unbind
int64 bindCoins = 3; // bind coins count
string targetNode = 4; // super node addr
int64 blockTime = 5; // action bind block time
int64 blockHeight = 6; // action bind block height
}
message ReceiptParaBindMinerInfo{
string addr = 1; // miner addr
ParaBindMinerInfo prev = 2;
ParaBindMinerInfo current = 3;
}
message ParaNodeBindOne{
string superNode = 1;
string miner = 2;
}
message ParaNodeBindList{
string title = 1;
repeated ParaNodeBindOne miners = 2;
}
message ReceiptParaNodeBindListUpdate{
ParaNodeBindList prev = 1;
ParaNodeBindList current = 2;
}
message RespParaNodeBindList{
ParaNodeBindList list = 1;
repeated ParaBindMinerInfo details = 2;
}
message ParaBlock2MainMap {
int64 height = 1;
......@@ -455,69 +312,6 @@ message ParacrossAsset {
}
message ParaLocalDbBlock {
int64 height = 1;
bytes mainHash = 2;
int64 mainHeight = 3;
bytes parentMainHash = 4;
int64 blockTime = 5;
repeated Transaction txs = 6;
}
message ParaLocalDbBlockInfo {
int64 height = 1;
string mainHash = 2;
int64 mainHeight = 3;
string parentMainHash = 4;
int64 blockTime = 5;
repeated string txs = 6;
}
message ParaBlsSignSumDetails {
int64 height = 1;
repeated string addrs = 2;
repeated bytes msgs = 3;
repeated bytes signs = 4;
}
message ParaBlsSignSumDetailsShow {
int64 height = 1;
repeated string addrs = 2;
repeated string msgs = 3;
}
message ParaBlsSignSumInfo {
repeated ParaBlsSignSumDetailsShow info = 1;
repeated string topics = 2;
}
message LeaderSyncInfo {
string ID = 1; //self id
int32 baseIdx = 2; //calculated by corrent consensus height and remainder by len(nodes)
int32 offset = 3;
uint32 count = 4; //发送计数器
}
message ParaP2PSubMsg {
int32 ty = 1;
oneof value {
Transaction commitTx = 10;
LeaderSyncInfo syncMsg = 11;
}
}
//bls sign leader info
message ElectionStatus {
bool isLeader = 1;
LeaderSyncInfo leader = 2;
}
message BlsPubKey{
string key = 1;
}
service paracross {
rpc IsSync(ReqNil) returns (IsCaughtUp) {}
}
syntax = "proto3";
import "transaction.proto";
import "common.proto";
import "blockchain.proto";
package types;
option go_package = "../types";
//para bind miner
message ParaBindMinerCmd{
int32 bindAction = 1; // 1: bind, 2:unbind
int64 bindCoins = 2; // bind coins count
string targetNode = 3; // consensus node addr
}
message ParaBindMinerInfo{
string addr = 1; // miner addr
int32 bindStatus = 2; // 1: bind, 2:unbind
int64 bindCoins = 3; // bind coins count
string consensusNode = 4; // consensus node addr
int64 blockTime = 5; // action bind block time
int64 blockHeight = 6; // action bind block height
int64 globalIndex = 7; // bind global only index to the consensus node
}
message ReceiptParaBindMinerInfo{
string addr = 1; // miner addr
ParaBindMinerInfo prev = 2;
ParaBindMinerInfo current = 3;
}
//共识节点绑定全局状态
message ParaBindNodeInfo{
int64 bindTotalCount = 1; // total bind count to the consensus node
}
message ReceiptParaBindConsensusNodeInfo{
string nodeAddr = 1; // node addr
ParaBindNodeInfo prev = 2;
ParaBindNodeInfo current = 3;
}
//共识节点索引绑定挖矿地址
message ParaBindAddr{
string addr = 1; // bind addr
}
message ParaMinerBindNodes{
repeated string nodes = 1; // bind nodes
}
message ReceiptParaMinerBindNodeList{
string miner = 1; // node addr
string node = 2;
ParaMinerBindNodes current = 3;
}
message ReceiptParaBindIndex{
string selfAddr = 1; // self addr
string bindAddr = 2;
int64 index = 3;
}
message ParaNodeMinerListReq{
string node = 1; //共识节点
string miner = 2; //唯一miner 地址
bool withUnBind = 3; //是否也查询未绑定的
}
message ParaBindMinerList{
repeated ParaBindMinerInfo list = 1;
}
//
//message ParaNodeBindList{
// string title = 1;
// repeated ParaNodeBindOne miners = 2;
//}
//message ReceiptParaNodeBindListUpdate{
// ParaNodeBindList prev = 1;
// ParaNodeBindList current = 2;
//}
//
//message RespParaNodeBindList{
// ParaNodeBindList list = 1;
// repeated ParaBindMinerInfo details = 2;
//}
syntax = "proto3";
import "transaction.proto";
import "common.proto";
import "blockchain.proto";
package types;
option go_package = "../types";
message ParaNodeAddrConfig {
string title = 1;
uint32 op = 2;
string id = 3;
string addr = 4;
uint32 value = 5;
int64 coinsFrozen = 6;
string blsPubKey = 7; //本地址私钥对应的bls聚合签名的公钥
}
message ParaNodeVoteDetail {
repeated string addrs = 1;
repeated string votes = 2;
}
message ParaNodeAddrIdStatus {
string addr = 1;
string proposalId = 2;
string quitId = 3;
int32 status = 4;
string title = 5;
string blsPubKey = 6;
}
message ParaNodeIdStatus {
string id = 1;
int32 status = 2;
string title = 3;
string targetAddr = 4;
int64 coinsFrozen = 5;
ParaNodeVoteDetail votes = 6;
string fromAddr = 7;
int64 height = 8;
string blsPubKey = 9;
}
message ReceiptParaNodeConfig {
string addr = 1;
ParaNodeAddrConfig config = 2;
ParaNodeIdStatus prev = 3;
ParaNodeIdStatus current = 4;
}
message ReceiptParaNodeAddrStatUpdate {
string fromAddr = 1;
ParaNodeAddrIdStatus prev = 2;
ParaNodeAddrIdStatus current = 3;
}
message ReceiptParaNodeVoteDone {
string id = 1;
string title = 2;
string targetAddr = 3;
int32 totalNodes = 4;
int32 totalVote = 5;
int32 mostVote = 6;
string voteRst = 7;
int32 doneStatus = 8;
}
message ParaNodeGroupConfig {
string title = 1;
uint32 op = 2;
string id = 3;
string addrs = 4;
int64 coinsFrozen = 5;
string blsPubKeys = 6;
}
message ParaNodeGroupStatus {
string id = 1;
int32 status = 2;
string title = 3;
string targetAddrs = 4;
int64 coinsFrozen = 5;
string fromAddr = 6;
int64 height = 7;
string blsPubKeys = 8;
}
message ReceiptParaNodeGroupConfig {
string addr = 1;
ParaNodeGroupConfig config = 2;
ParaNodeGroupStatus prev = 3;
ParaNodeGroupStatus current = 4;
}
// node query
message ReqParacrossNodeInfo {
string title = 1;
string id = 2;
string addr = 3;
int32 status = 4;
string blsPubKey = 5;
}
message RespParacrossNodeAddrs {
repeated ParaNodeIdStatus ids = 1;
}
message RespParacrossNodeGroups {
repeated ParaNodeGroupStatus ids = 1;
}
This diff is collapsed.
This diff is collapsed.
......@@ -49,6 +49,8 @@ const (
TyLogParaCrossAssetTransfer = 670
TyLogParaBindMinerAddr = 671
TyLogParaBindMinerNode = 672
TyLogParaBindMinerIndex = 673
TyLogParaMinerBindNodeList = 674
// Supervision Node
TyLogParaSupervisionNodeConfig = 680
TyLogParaSupervisionNodeGroupAddrsUpdate = 681
......
This diff is collapsed.
This diff is collapsed.
......@@ -126,7 +126,9 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
TyLogParaStageVoteDone: {Ty: reflect.TypeOf(ReceiptSelfConsStageVoteDone{}), Name: "LogParaSelfConfStageVoteDoen"},
TyLogParaStageGroupUpdate: {Ty: reflect.TypeOf(ReceiptSelfConsStagesUpdate{}), Name: "LogParaSelfConfStagesUpdate"},
TyLogParaBindMinerAddr: {Ty: reflect.TypeOf(ReceiptParaBindMinerInfo{}), Name: "TyLogParaBindMinerAddrUpdate"},
TyLogParaBindMinerNode: {Ty: reflect.TypeOf(ReceiptParaNodeBindListUpdate{}), Name: "TyLogParaBindNodeListUpdate"},
TyLogParaBindMinerNode: {Ty: reflect.TypeOf(ReceiptParaBindConsensusNodeInfo{}), Name: "TyLogParaBindNodeUpdate"},
TyLogParaBindMinerIndex: {Ty: reflect.TypeOf(ReceiptParaBindIndex{}), Name: "TyLogParaBindIndex"},
TyLogParaMinerBindNodeList: {Ty: reflect.TypeOf(ReceiptParaMinerBindNodeList{}), Name: "TyLogParaMinerBindNodeList"},
TyLogParaSupervisionNodeConfig: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaSupervisionNodeConfig"},
TyLogParaSupervisionNodeGroupAddrsUpdate: {Ty: reflect.TypeOf(types.ReceiptConfig{}), Name: "LogParaSupervisionNodeGroupAddrsUpdate"},
TyLogParaSupervisionNodeStatusUpdate: {Ty: reflect.TypeOf(ReceiptParaNodeAddrStatUpdate{}), Name: "LogParaSupervisionNodeStatusUpdate"},
......
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