Commit 2aa47b88 authored by madengji's avatar madengji Committed by 33cn

bls sign commit part

parent 9bc6a7df
......@@ -91,6 +91,7 @@ type subConfig struct {
MultiDownServerRspTime uint32 `json:"multiDownServerRspTime,omitempty"`
RmCommitParamMainHeight int64 `json:"rmCommitParamMainHeight,omitempty"`
JumpDownloadClose bool `json:"jumpDownloadClose,omitempty"`
BlsSignOff bool `json:"blsSignOff,omitempty"`
}
// New function to init paracross env
......
......@@ -19,11 +19,14 @@ import (
"bytes"
"math/big"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/types"
paracross "github.com/33cn/plugin/plugin/dapp/paracross/types"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/phoreproject/bls/g2pubs"
"github.com/pkg/errors"
)
......@@ -60,6 +63,8 @@ type commitMsgClient struct {
txFeeRate int64
selfConsEnableList []*paraSelfConsEnable //适配在自共识合约配置前有自共识的平行链项目,fork之后,采用合约配置
privateKey crypto.PrivKey
blsPriKey *g2pubs.SecretKey
blsPubKey *g2pubs.PublicKey
quit chan struct{}
mutex sync.Mutex
}
......@@ -360,7 +365,19 @@ func (client *commitMsgClient) getSendingTx(startHeight, endHeight int64) (*type
return nil, 0
}
signTx, count, err := client.calcCommitMsgTxs(status, atomic.LoadInt64(&client.txFeeRate))
var commits []*pt.ParacrossCommitAction
for _, stat := range status {
commits = append(commits, &pt.ParacrossCommitAction{Status: stat})
}
if !client.paraClient.subCfg.BlsSignOff {
err = client.blsSign(commits)
if err != nil {
return nil, 0
}
}
signTx, count, err := client.calcCommitMsgTxs(commits, atomic.LoadInt64(&client.txFeeRate))
if err != nil || signTx == nil {
return nil, 0
}
......@@ -376,12 +393,12 @@ func (client *commitMsgClient) getSendingTx(startHeight, endHeight int64) (*type
return signTx, count
}
func (client *commitMsgClient) calcCommitMsgTxs(notifications []*pt.ParacrossNodeStatus, feeRate int64) (*types.Transaction, int64, error) {
func (client *commitMsgClient) calcCommitMsgTxs(notifications []*pt.ParacrossCommitAction, feeRate int64) (*types.Transaction, int64, error) {
txs, count, err := client.batchCalcTxGroup(notifications, feeRate)
if err != nil {
txs, err = client.singleCalcTx((notifications)[0], feeRate)
if err != nil {
plog.Error("single calc tx", "height", notifications[0].Height)
plog.Error("single calc tx", "height", notifications[0].Status.Height)
return nil, 0, err
}
......@@ -429,14 +446,14 @@ func (client *commitMsgClient) getExecName(commitHeight int64) string {
}
func (client *commitMsgClient) batchCalcTxGroup(notifications []*pt.ParacrossNodeStatus, feeRate int64) (*types.Transaction, int, error) {
func (client *commitMsgClient) batchCalcTxGroup(notifications []*pt.ParacrossCommitAction, feeRate int64) (*types.Transaction, int, error) {
var rawTxs types.Transactions
cfg := client.paraClient.GetAPI().GetConfig()
for _, status := range notifications {
execName := client.getExecName(status.Height)
tx, err := paracross.CreateRawCommitTx4MainChain(cfg, status, execName, feeRate)
for _, notify := range notifications {
execName := client.getExecName(notify.Status.Height)
tx, err := paracross.CreateRawCommitTx4MainChain(cfg, notify, execName, feeRate)
if err != nil {
plog.Error("para get commit tx", "block height", status.Height)
plog.Error("para get commit tx", "block height", notify.Status.Height)
return nil, 0, err
}
rawTxs.Txs = append(rawTxs.Txs, tx)
......@@ -449,12 +466,12 @@ func (client *commitMsgClient) batchCalcTxGroup(notifications []*pt.ParacrossNod
return txs, len(notifications), nil
}
func (client *commitMsgClient) singleCalcTx(status *pt.ParacrossNodeStatus, feeRate int64) (*types.Transaction, error) {
func (client *commitMsgClient) singleCalcTx(notify *pt.ParacrossCommitAction, feeRate int64) (*types.Transaction, error) {
cfg := client.paraClient.GetAPI().GetConfig()
execName := client.getExecName(status.Height)
tx, err := paracross.CreateRawCommitTx4MainChain(cfg, status, execName, feeRate)
execName := client.getExecName(notify.Status.Height)
tx, err := paracross.CreateRawCommitTx4MainChain(cfg, notify, execName, feeRate)
if err != nil {
plog.Error("para get commit tx", "block height", status.Height)
plog.Error("para get commit tx", "block height", notify.Status.Height)
return nil, err
}
tx.Sign(types.SECP256K1, client.privateKey)
......@@ -902,6 +919,10 @@ func (client *commitMsgClient) fetchPriKey() error {
}
client.privateKey = priKey
client.blsPriKey = getBlsPriKey(priKey.Bytes())
client.blsPubKey = g2pubs.PrivToPub(client.blsPriKey)
serial := client.blsPubKey.Serialize()
plog.Info("para commit get pub bls", "final keys", common.ToHex(serial[:]))
plog.Info("para commit fetchPriKey success")
return nil
}
......@@ -958,3 +979,62 @@ func (client *commitMsgClient) isSelfConsEnable(height int64) bool {
}
return false
}
//to repeat get prikey's hash until in range of bls's private key
func getBlsPriKey(key []byte) *g2pubs.SecretKey {
var newKey [common.Sha256Len]byte
copy(newKey[:], key[:])
for {
plog.Info("para commit getBlsPriKey", "keys", common.ToHex(newKey[:]))
secret := g2pubs.DeserializeSecretKey(newKey)
if nil != secret.GetFRElement() {
serial := secret.Serialize()
plog.Info("para commit getBlsPriKey", "final keys", common.ToHex(serial[:]), "string", secret.String())
return secret
}
copy(newKey[:], common.Sha256(newKey[:]))
}
}
func (client *commitMsgClient) blsSign(commits []*pt.ParacrossCommitAction) error {
nodeStr, err := client.getNodeGroupAddrs()
if err != nil || len(nodeStr) <= 0 {
plog.Info("bls sign", "nodestr", nodeStr, "err", err)
return types.ErrInvalidParam
}
nodes := strings.Split(nodeStr, ",")
bitMap, remains := setAddrsBitMap(nodes, []string{client.authAccount})
if len(remains) > 0 {
plog.Error("bls sign addrs remains", "remains", remains, "nodestr", nodeStr, "bitmap", bitMap, "nodes", nodes)
}
if remains[client.authAccount] {
plog.Error("bls sign addrs miss setmap", "auth", client.authAccount, "remains", remains)
return types.ErrInvalidParam
}
for _, cmt := range commits {
data := types.Encode(cmt.Status)
plog.Debug("blsign msg", "data", common.ToHex(data), "height", cmt.Status.Height, "map", bitMap)
sign := g2pubs.Sign(data, client.blsPriKey).Serialize()
cmt.Bls = &pt.ParacrossCommitBlsInfo{Sign: sign[:], Addrs: bitMap}
}
return nil
}
//设置nodes范围内的bitmap,如果addrs在node不存在,也不设置,返回未命中的addrs
func setAddrsBitMap(nodes, addrs []string) ([]byte, map[string]bool) {
rst := big.NewInt(0)
addrsMap := make(map[string]bool)
for _, n := range addrs {
addrsMap[n] = true
}
for i, a := range nodes {
if _, exist := addrsMap[a]; exist {
rst.SetBit(rst, i, 1)
delete(addrsMap, a)
}
}
return rst.Bytes(), addrsMap
}
......@@ -7,6 +7,8 @@ package para
import (
"testing"
"encoding/hex"
"github.com/33cn/chain33/queue"
_ "github.com/33cn/chain33/system"
drivers "github.com/33cn/chain33/system/consensus"
......@@ -71,3 +73,10 @@ func TestSetSelfConsEnable(t *testing.T) {
assert.Equal(t, ep1, para.commitMsgClient.selfConsEnableList)
}
func TestSetAddrsBitMap(t *testing.T) {
nodes := []string{"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4", "1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR", "1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k", "1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs"}
addrs := []string{"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"}
val, remain := setAddrsBitMap(nodes, addrs)
t.Log("val", hex.EncodeToString(val), "remain", remain)
}
......@@ -64,19 +64,21 @@ func TestCalcCommitMsgTxs(t *testing.T) {
Height: 2,
Title: "user.p.para",
}
notify := []*pt.ParacrossNodeStatus{nt1}
commit1 := &pt.ParacrossCommitAction{Status: nt1}
notify := []*pt.ParacrossCommitAction{commit1}
tx, count, err := client.calcCommitMsgTxs(notify, 0)
assert.Nil(t, err)
assert.Equal(t, int64(1), count)
assert.NotNil(t, tx)
notify = append(notify, nt2)
commit1 = &pt.ParacrossCommitAction{Status: nt2}
notify = append(notify, commit1)
tx, count, err = client.calcCommitMsgTxs(notify, 0)
assert.Nil(t, err)
assert.Equal(t, int64(2), count)
assert.NotNil(t, tx)
tx, err = client.singleCalcTx(nt2, 0)
tx, err = client.singleCalcTx(commit1, 0)
assert.Nil(t, err)
assert.NotNil(t, tx)
......
......@@ -496,7 +496,8 @@ function para_cross_transfer_withdraw_for_token() {
function para_create_nodegroup_gamechain() {
echo "=========== # game para chain create node group test ============="
##apply
txhash=$(${CLI} --paraName user.p.game. send para nodegroup apply -a "1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4" -c 5 -k 0xd165c84ed37c2a427fea487470ee671b7a0495d68d82607cafbc6348bf23bec5)
local KS="0x8293f1e8eab2919910c2d347348d1d344a86e0dd10610ff06211f85c8cd3dfc99d81c36ef0f6ad6ba1db931d1ffbe7321411d80ce76269463301af5cce4128b196e48abced00c536f7be557fd5940ef5a0740c85a871fe81fe940aca9ed329e7"
txhash=$(${CLI} --paraName user.p.game. send para nodegroup apply -a "1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4" -p "$KS" -c 5 -k 0xd165c84ed37c2a427fea487470ee671b7a0495d68d82607cafbc6348bf23bec5)
echo "tx=$txhash"
query_tx "${PARA_CLI5}" "${txhash}"
id=$txhash
......@@ -653,7 +654,13 @@ function para_create_nodegroup() {
echo "=========== # para chain create node group again ============="
##apply
txhash=$(${PARA_CLI} send para nodegroup apply -a "1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY,1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4,1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR,1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k,1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs" -c 6 -k 0xd165c84ed37c2a427fea487470ee671b7a0495d68d82607cafbc6348bf23bec5)
local E5="0x9293f1e8eab2919910c2d347348d1d344a86e0dd10610ff06211f85c8cd3dfc99d81c36ef0f6ad6ba1db931d1ffbe7321411d80ce76269463301af5cce4128b196e48abced00c536f7be557fd5940ef5a0740c85a871fe81fe940aca9ed329e7"
local KS="0x8293f1e8eab2919910c2d347348d1d344a86e0dd10610ff06211f85c8cd3dfc99d81c36ef0f6ad6ba1db931d1ffbe7321411d80ce76269463301af5cce4128b196e48abced00c536f7be557fd5940ef5a0740c85a871fe81fe940aca9ed329e7"
local JR="0x8ed5ba075c27015e2c6da399b42da4cd272d4082b55f05c85d84b1308ec87bdb4aeea70dbef3e754eae99a6be0c0e49512d7e9197712f8538ce3d57c1b2d88e17b37f0e419f55333f6e841261a8d3151552fd7d4fd8e19f4f38a413395aab26e"
local NL="0x872e3ac07998deb12045ee48c52a8ba5d2538dc85123866fb330112eb0b805ce23f31bfde3a485cd89fac48eab48560005d12f714ca3786c7f47fe3b5edb1dc7838677c041c89cee4caf9225c1d68346bfcde3365ada0a627fbd77bc72e9b356"
local MC="0x87c58bb6cce41842462a0030335bb95948dcfba77e47e2d8ee893c0b2c34ac20d08c9e98a883ef2a6492d0ad808ace9a1730e8bae5d3b0861aaf743449df5de510073e2991c7274cab47f327e48d7eacf300e4b24174dae2e8603d1904b8a015"
local blspubs=$E5","$KS","$JR","$NL","$MC
txhash=$(${PARA_CLI} send para nodegroup apply -a "1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY,1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4,1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR,1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k,1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs" -p "$blspubs" -c 6 -k 0xd165c84ed37c2a427fea487470ee671b7a0495d68d82607cafbc6348bf23bec5)
echo "tx=$txhash"
query_tx "${PARA_CLI}" "${txhash}"
id=$txhash
......
......@@ -327,6 +327,16 @@ func superNodeCmd() *cobra.Command {
return cmd
}
func nodeJoinCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "join",
Short: "super node apply for join nodegroup cmd",
Run: createNodeJoinTx,
}
addNodeJoinFlags(cmd)
return cmd
}
func addNodeJoinFlags(cmd *cobra.Command) {
cmd.Flags().StringP("addr", "a", "", "target join addr")
cmd.MarkFlagRequired("addr")
......@@ -356,13 +366,13 @@ func createNodeJoinTx(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal()
}
func nodeJoinCmd() *cobra.Command {
func nodeVoteCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "join",
Short: "super node apply for join nodegroup cmd",
Run: createNodeJoinTx,
Use: "vote",
Short: "nodegroup nodes vote for new join node cmd",
Run: createNodeVoteTx,
}
addNodeJoinFlags(cmd)
addNodeVoteFlags(cmd)
return cmd
}
......@@ -395,13 +405,13 @@ func createNodeVoteTx(cmd *cobra.Command, args []string) {
}
func nodeVoteCmd() *cobra.Command {
func nodeQuitCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "vote",
Short: "nodegroup nodes vote for new join node cmd",
Run: createNodeVoteTx,
Use: "quit",
Short: "super node apply for quit nodegroup cmd",
Run: createNodeQuitTx,
}
addNodeVoteFlags(cmd)
addNodeQuitFlags(cmd)
return cmd
}
......@@ -431,13 +441,13 @@ func createNodeQuitTx(cmd *cobra.Command, args []string) {
}
func nodeQuitCmd() *cobra.Command {
func nodeCancelCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "quit",
Short: "super node apply for quit nodegroup cmd",
Run: createNodeQuitTx,
Use: "cancel",
Short: "super node cancel join or quit action by id cmd",
Run: createNodeCancelTx,
}
addNodeQuitFlags(cmd)
addNodeCancelFlags(cmd)
return cmd
}
......@@ -467,16 +477,45 @@ func createNodeCancelTx(cmd *cobra.Command, args []string) {
}
func nodeCancelCmd() *cobra.Command {
func nodeModifyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "cancel",
Short: "super node cancel join or quit action by id cmd",
Run: createNodeCancelTx,
Use: "modify",
Short: "super node modify parameters",
Run: createNodeModifyTx,
}
addNodeCancelFlags(cmd)
return cmd
}
func addNodeModifyFlags(cmd *cobra.Command) {
cmd.Flags().StringP("addr", "a", "", "operating target apply id")
cmd.MarkFlagRequired("addr")
cmd.Flags().StringP("pubkey", "p", "", "operating target apply id")
cmd.MarkFlagRequired("pubkey")
}
func createNodeModifyTx(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName")
addr, _ := cmd.Flags().GetString("addr")
pubkey, _ := cmd.Flags().GetString("pubkey")
if !strings.HasPrefix(paraName, "user.p") {
fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
payload := &pt.ParaNodeAddrConfig{Title: paraName, Op: pt.ParaOpModify, Addr: addr, BlsPubKey: pubkey}
params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "NodeConfig",
Payload: types.MustPBToJSON(payload),
}
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, nil)
ctx.RunWithoutMarshal()
}
// getNodeInfoCmd get node current status
func getNodeInfoCmd() *cobra.Command {
cmd := &cobra.Command{
......@@ -739,10 +778,22 @@ func nodeGroupCmd() *cobra.Command {
return cmd
}
func nodeGroupApplyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "apply",
Short: "apply for para chain's super node group",
Run: nodeGroupApply,
}
addNodeGroupApplyCmdFlags(cmd)
return cmd
}
func addNodeGroupApplyCmdFlags(cmd *cobra.Command) {
cmd.Flags().StringP("addrs", "a", "", "addrs apply for super node,split by ',' ")
cmd.MarkFlagRequired("addrs")
cmd.Flags().StringP("blspubs", "p", "", "bls sign pub key for addr's private key,split by ',' (optional)")
cmd.Flags().Float64P("coins", "c", 0, "coins amount to frozen, not less config")
cmd.MarkFlagRequired("coins")
......@@ -751,6 +802,7 @@ func addNodeGroupApplyCmdFlags(cmd *cobra.Command) {
func nodeGroupApply(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName")
addrs, _ := cmd.Flags().GetString("addrs")
blspubs, _ := cmd.Flags().GetString("blspubs")
coins, _ := cmd.Flags().GetFloat64("coins")
if !strings.HasPrefix(paraName, "user.p") {
......@@ -758,7 +810,7 @@ func nodeGroupApply(cmd *cobra.Command, args []string) {
return
}
payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 1, Addrs: addrs, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 1, Addrs: addrs, BlsPubKeys: blspubs, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "NodeGroupConfig",
......@@ -770,16 +822,6 @@ func nodeGroupApply(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal()
}
func nodeGroupApplyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "apply",
Short: "apply for para chain's super node group",
Run: nodeGroupApply,
}
addNodeGroupApplyCmdFlags(cmd)
return cmd
}
func addNodeGroupApproveCmdFlags(cmd *cobra.Command) {
cmd.Flags().StringP("id", "i", "", "apply id for nodegroup ")
cmd.MarkFlagRequired("id")
......
This diff is collapsed.
This diff is collapsed.
......@@ -6,7 +6,6 @@ package executor
import (
"encoding/hex"
"fmt"
"github.com/33cn/chain33/common"
dbm "github.com/33cn/chain33/common/db"
......@@ -78,17 +77,21 @@ func (p *Paracross) Query_GetNodeGroupAddrs(in *pt.ReqParacrossNodeInfo) (types.
return nil, errors.Wrap(types.ErrInvalidParam, "title is null")
}
ret, key, err := getConfigNodes(p.GetStateDB(), in.GetTitle())
_, nodesArry, key, err := getConfigNodes(p.GetStateDB(), in.GetTitle())
if err != nil {
return nil, err
}
var nodes []string
for k := range ret {
nodes = append(nodes, k)
var nodes string
for _, k := range nodesArry {
if len(nodes) == 0 {
nodes = k
continue
}
nodes = nodes + "," + k
}
var reply types.ReplyConfig
reply.Key = string(key)
reply.Value = fmt.Sprint(nodes)
reply.Value = nodes
return &reply, nil
}
......
......@@ -9,6 +9,8 @@ import (
"strconv"
"math/big"
"github.com/33cn/chain33/common"
dbm "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/system/dapp"
......@@ -208,6 +210,28 @@ func makeParaNodeGroupReceipt(title string, prev, current *types.ConfigItem) *ty
}
}
//获取nodes范围内的bitmap,如果bitmap超出了nodes范围,也不处理,防止越界
func getAddrsByBitMap(nodes []string, bitmap []byte) []string {
rst := big.NewInt(0).SetBytes(bitmap)
addrs := make([]string, 0)
for i, a := range nodes {
if rst.Bit(i) == uint(0x1) {
addrs = append(addrs, a)
}
}
return addrs
}
//get secp256 addr's bls pubkey
func getAddrBlsPubKey(db dbm.KV, title, addr string) (string, error) {
addrStat, err := getNodeAddr(db, title, addr)
if err != nil {
return "", errors.Wrapf(err, "nodeAddr:%s-%s get error", title, addr)
}
return addrStat.BlsPubKey, nil
}
func (a *action) checkValidNode(config *pt.ParaNodeAddrConfig) (bool, error) {
nodes, _, err := getParacrossNodes(a.db, config.Title)
if err != nil {
......@@ -262,6 +286,7 @@ func (a *action) nodeJoin(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
Status: pt.ParaApplyJoining,
Title: config.Title,
TargetAddr: config.Addr,
BlsPubKey: config.BlsPubKey,
FromAddr: a.fromaddr,
Votes: &pt.ParaNodeVoteDetail{},
CoinsFrozen: config.CoinsFrozen,
......@@ -350,6 +375,23 @@ func (a *action) nodeCancel(config *pt.ParaNodeAddrConfig) (*types.Receipt, erro
}
func (a *action) nodeModify(config *pt.ParaNodeAddrConfig) (*types.Receipt, error) {
addrStat, err := getNodeAddr(a.db, config.Title, config.Addr)
if err != nil {
return nil, errors.Wrapf(err, "nodeAddr:%s get error", config.Addr)
}
//只能提案发起人撤销
if a.fromaddr != config.Addr {
return nil, errors.Wrapf(types.ErrNotAllow, "addr create by:%s,not by:%s", config.Addr, a.fromaddr)
}
preStat := *addrStat
addrStat.BlsPubKey = config.BlsPubKey
return makeParaNodeStatusReceipt(a.fromaddr, &preStat, addrStat), nil
}
// IsSuperManager is supper manager or not
func isSuperManager(cfg *types.Chain33Config, addr string) bool {
confManager := types.ConfSub(cfg, manager.ManageX)
......@@ -439,6 +481,7 @@ func (a *action) updateNodeAddrStatus(stat *pt.ParaNodeIdStatus) (*types.Receipt
addrStat = &pt.ParaNodeAddrIdStatus{}
addrStat.Title = stat.Title
addrStat.Addr = stat.TargetAddr
addrStat.BlsPubKey = stat.BlsPubKey
addrStat.Status = pt.ParaApplyJoined
addrStat.ProposalId = stat.Id
addrStat.QuitId = ""
......@@ -769,6 +812,15 @@ func (a *action) nodeGroupApply(config *pt.ParaNodeGroupConfig) (*types.Receipt,
return nil, errors.Wrapf(types.ErrInvalidParam, "node group apply addrs null:%s", config.Addrs)
}
var blsPubKeys []string
if len(config.BlsPubKeys) > 0 {
blsPubKeys = getConfigAddrs(config.BlsPubKeys)
if len(blsPubKeys) != len(addrs) {
return nil, errors.Wrapf(types.ErrInvalidParam, "nodegroup apply blsPubkeys length=%d not match addrs=%d",
len(blsPubKeys), len(addrs))
}
}
receipt := &types.Receipt{Ty: types.ExecOk}
//main chain
cfg := a.api.GetConfig()
......@@ -787,9 +839,12 @@ func (a *action) nodeGroupApply(config *pt.ParaNodeGroupConfig) (*types.Receipt,
Status: pt.ParacrossNodeGroupApply,
Title: config.Title,
TargetAddrs: strings.Join(addrs, ","),
BlsPubKeys: strings.Join(blsPubKeys, ","),
CoinsFrozen: config.CoinsFrozen,
FromAddr: a.fromaddr,
Height: a.height}
Height: a.height,
}
r := makeNodeGroupIDReceipt(a.fromaddr, nil, stat)
receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
......@@ -977,6 +1032,11 @@ func (a *action) nodeGroupCreate(status *pt.ParaNodeGroupStatus) (*types.Receipt
receipt := makeParaNodeGroupReceipt(status.Title, nil, &item)
var blsPubKeys []string
if len(status.BlsPubKeys) > 0 {
blsPubKeys = strings.Split(status.BlsPubKeys, ",")
}
//update addr status
for i, addr := range nodes {
stat := &pt.ParaNodeIdStatus{
......@@ -988,7 +1048,9 @@ func (a *action) nodeGroupCreate(status *pt.ParaNodeGroupStatus) (*types.Receipt
CoinsFrozen: status.CoinsFrozen,
FromAddr: status.FromAddr,
Height: a.height}
if len(blsPubKeys) > 0 {
stat.BlsPubKey = blsPubKeys[i]
}
r := makeNodeConfigReceipt(a.fromaddr, nil, nil, stat)
receipt = mergeReceipt(receipt, r)
......@@ -1052,25 +1114,28 @@ func (a *action) NodeConfig(config *pt.ParaNodeAddrConfig) (*types.Receipt, erro
return nil, errors.Wrapf(types.ErrInvalidParam, "exec=%s,should prefix with user.p.", string(a.tx.Execer))
}
if config.Op == pt.ParaOpNewApply {
switch config.Op {
case pt.ParaOpNewApply:
return a.nodeJoin(config)
} else if config.Op == pt.ParaOpQuit {
case pt.ParaOpQuit:
//退出nodegroup
return a.nodeQuit(config)
} else if config.Op == pt.ParaOpCancel {
case pt.ParaOpCancel:
//撤销未批准的申请
if config.Id == "" {
return nil, types.ErrInvalidParam
}
return a.nodeCancel(config)
} else if config.Op == pt.ParaOpVote {
case pt.ParaOpVote:
if config.Id == "" || config.Value >= pt.ParaVoteEnd {
return nil, types.ErrInvalidParam
}
return a.nodeVote(config)
case pt.ParaOpModify:
//修改addr相关联的参数,只能原创地址修改
return a.nodeModify(config)
default:
return nil, pt.ErrParaUnSupportNodeOper
}
return nil, pt.ErrParaUnSupportNodeOper
}
......@@ -61,6 +61,7 @@ message ParaNodeAddrConfig {
string addr = 4;
uint32 value = 5;
int64 coinsFrozen = 6;
string blsPubKey = 7; //本地址私钥对应的bls聚合签名的公钥
}
message ParaNodeVoteDetail {
......@@ -74,6 +75,7 @@ message ParaNodeAddrIdStatus {
string quitId = 3;
int32 status = 4;
string title = 5;
string blsPubKey = 6;
}
message ParaNodeIdStatus {
......@@ -85,6 +87,7 @@ message ParaNodeIdStatus {
ParaNodeVoteDetail votes = 6;
string fromAddr = 7;
int64 height = 8;
string blsPubKey = 9;
}
message ReceiptParaNodeConfig {
......@@ -117,6 +120,7 @@ message ParaNodeGroupConfig {
string id = 3;
string addrs = 4;
int64 coinsFrozen = 5;
string blsPubKeys = 6;
}
message ParaNodeGroupStatus {
......@@ -127,6 +131,7 @@ message ParaNodeGroupStatus {
int64 coinsFrozen = 5;
string fromAddr = 6;
int64 height = 7;
string blsPubKeys = 8;
}
message ReceiptParaNodeGroupConfig {
......@@ -142,6 +147,7 @@ message ReqParacrossNodeInfo {
string id = 2;
string addr = 3;
int32 status = 4;
string blsPubKey = 5;
}
message RespParacrossNodeAddrs {
......@@ -259,8 +265,14 @@ message ReplyQuerySelfStages {
repeated SelfConsensStageInfo stageInfo = 1;
}
message ParacrossCommitBlsInfo {
bytes sign = 1;
bytes addrs = 2; //addrs' bitmap
}
message ParacrossCommitAction {
ParacrossNodeStatus status = 1;
ParacrossCommitBlsInfo bls = 2;
}
message ParacrossMinerAction {
......
......@@ -57,4 +57,6 @@ var (
ErrKeyNotExist = errors.New("ErrKeyNotExist")
// ErrConsensClosed consensus closed
ErrConsensClosed = errors.New("ErrConsensClosed")
//ErrConsBlsSignVerify bls12-381 aggregate sign verify
ErrBlsSignVerify = errors.New("ErrBlsSignVerify")
)
......@@ -105,6 +105,7 @@ const (
ParaOpVote
ParaOpQuit
ParaOpCancel
ParaOpModify
)
// node vote op
......@@ -180,17 +181,14 @@ func CalcMinerHeightKey(title string, height int64) []byte {
}
// CreateRawCommitTx4MainChain create commit tx to main chain
func CreateRawCommitTx4MainChain(cfg *types.Chain33Config, status *ParacrossNodeStatus, name string, fee int64) (*types.Transaction, error) {
func CreateRawCommitTx4MainChain(cfg *types.Chain33Config, status *ParacrossCommitAction, name string, fee int64) (*types.Transaction, error) {
return createRawCommitTx(cfg, status, name, fee)
}
func createRawCommitTx(cfg *types.Chain33Config, status *ParacrossNodeStatus, name string, feeRate int64) (*types.Transaction, error) {
v := &ParacrossCommitAction{
Status: status,
}
func createRawCommitTx(cfg *types.Chain33Config, commit *ParacrossCommitAction, name string, feeRate int64) (*types.Transaction, error) {
action := &ParacrossAction{
Ty: ParacrossActionCommit,
Value: &ParacrossAction_Commit{v},
Value: &ParacrossAction_Commit{commit},
}
tx := &types.Transaction{
Execer: []byte(name),
......
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