Unverified Commit a2907e13 authored by trouble's avatar trouble Committed by GitHub

Merge branch 'master' into feature_exchange

parents b424df05 808969f4
......@@ -114,7 +114,6 @@ function base_init() {
# wallet
sed -i $sedfix 's/^minerdisable=.*/minerdisable=false/g' chain33.toml
sed -i $sedfix 's/^nodeGroupFrozenCoins=.*/nodeGroupFrozenCoins=20/g' chain33.toml
sed -i $sedfix 's/^paraConsensusStopBlocks=.*/paraConsensusStopBlocks=100/g' chain33.toml
# blockchain
......@@ -132,6 +131,10 @@ function base_init() {
sed -i $sedfix 's/^enableReduceLocaldb=.*/enableReduceLocaldb=false/g' chain33.toml
sed -i $sedfix 's/^enablePushSubscribe=.*/enablePushSubscribe=true/g' chain33.toml
fi
#autonomy config
sed -i $sedfix 's/^autonomyExec=.*/autonomyExec=""/g' chain33.toml
}
function start() {
......
......@@ -107,27 +107,24 @@ halvePeriod=1000
[consensus.sub.para]
#主链节点的grpc服务器ip,当前可以支持多ip负载均衡,如“118.31.177.1:8802,39.97.2.127:8802”
#ParaRemoteGrpcClient="118.31.177.1:8802,39.97.2.127:8802,120.77.111.44:8802,jiedian2.bityuan.com,cloud.bityuan.com"
#ParaRemoteGrpcClient="jiedian2.bityuan.com,cloud.bityuan.com"
ParaRemoteGrpcClient="localhost:8802"
#主链指定高度的区块开始同步
startHeight=345850
#主链指定高度后等待块数,防止主链回滚,联盟链最小为1,小于1则采用缺省高度100
#waitMainBlockNum=100
#打包时间间隔,单位
writeBlockSeconds=2
#等待打包主链区块时间间隔,单位毫
writeBlockMsec=2000
#共识节点账户,共识节点需要配置自己的账户,并且钱包导入对应种子,非共识节点留空
authAccount=""
#创世地址额度
genesisAmount=100000000
#主链计算blockhash forkheight,需要和主链保持严格一致,不可修改,1是bityuan主链对应高度, ycc或其他按实际修改
mainBlockHashForkHeight=1
#主链支持平行链共识tx分叉高度,需要和主链保持严格一致,不可修改,2270000是bityuan主链对应高度, ycc或其他按实际修改
#不可为0,主链Local时候需特殊配置
mainForkParacrossCommitTx=2270000
#主链开启循环检查共识交易done的fork高度,需要和主链保持严格一致,不可修改,4320000是bityuan主链对应高度, ycc或其他按实际修改
#不可为0,主链Local时候需特殊配置
mainLoopCheckCommitTxDoneForkHeight=4320000
#mainForkParaSupervision=10400000
#无平行链交易的主链区块间隔,平行链产生一个空块,从高度0开始,配置[blockHeight:interval],比如["0:50","1000:100"]
emptyBlockInterval=["0:50"]
......@@ -190,6 +187,8 @@ genesis="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
[exec.sub.manage]
superManager=["12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"]
#autonomy执行器名字,空则不开启,使用superManager list
autonomyExec=""
[exec.sub.token]
saveTokenTxList=true
......@@ -218,6 +217,8 @@ pointHX="19172955941344617222923168298456110557655645809646772800021167670156933
pointHY="21116962883761739586121793871108889864627195706475546685847911817475098399811"
#电路最大支持1024个叶子hash,10 level, 配置可以小于1024,但不能大于
maxTreeLeaves=1024
#管理员列表
mixApprs=[]
#系统中所有的fork,默认用chain33的测试网络的
#但是我们可以替换
......@@ -270,6 +271,8 @@ ForkBadRepeatSecret=0
[fork.sub.manage]
Enable=0
ForkManageExec=0
#manage增加配置需要经过autonomy board成员审批,平行链不开启
ForkManageAutonomyEnable=-1
[fork.sub.token]
Enable=0
......@@ -300,6 +303,8 @@ ForkParaSupervision=0
ForkParaFullMinerHeight=0
#仅平行链适用,在旧的版本中计算blockTxHash输入高度为0,需要在此高度后统一采用新的主链高度值,旧的版本需要设置此分叉高度,新版本缺省为0即可
ForkParaRootHash=0
#nodegroup approve需要经过autonomy board成员审批,平行链不开启
ForkParaAutonomySuperGroup=-1
[fork.sub.evm]
Enable=0
......@@ -393,6 +398,7 @@ ForkUnfreezeIDX= 0
[fork.sub.autonomy]
Enable=0
ForkAutonomyDelRule=0
ForkAutonomyEnableItem=0
[fork.sub.jsvm]
Enable=0
......
......@@ -118,13 +118,13 @@ ParaRemoteGrpcClient="localhost:8802"
startHeight=345850
#主链指定高度后等待块数,防止主链回滚,联盟链最小为1,小于1则采用缺省高度100
#waitMainBlockNum=100
#检索主链最新区块时间间隔,单位
writeBlockSeconds=2
#等待打包主链区块时间间隔,单位毫
writeBlockMsec=2000
#共识节点账户,共识节点需要配置自己的账户,并且钱包导入对应种子,非共识节点留空
authAccount=""
#创世地址额度
genesisAmount=100000000
#主链计算blockhash forkheight,需要和主链保持严格一致,不可修改,1是bityuan主链对应高度, ycc或其他按实际修改
#主链计算blockhash forkheight,需要和主链保持严格一致,不可修改,1是bityuan主链对应高度, ycc或其他按实际修改 --此参数弃用
mainBlockHashForkHeight=1
#主链支持平行链共识tx分叉高度,需要和主链保持严格一致,不可修改,2270000是bityuan主链对应高度, ycc或其他按实际修改
#不可为0,主链Local时候需特殊配置
......@@ -275,6 +275,8 @@ ForkBadRepeatSecret=0
[fork.sub.manage]
Enable=0
ForkManageExec=0
#manage增加配置需要autonomy审批
ForkManageAutonomyEnable=0
[fork.sub.token]
Enable=0
......@@ -305,6 +307,8 @@ ForkParaSupervision=0
ForkParaFullMinerHeight=0
#仅平行链适用,在旧的版本中计算blockTxHash输入高度为0,需要在此高度后统一采用新的主链高度值,旧的版本需要设置此分叉高度,新版本缺省为0即可
ForkParaRootHash=0
#nodegroup approve需要经过autonomy board成员审批
ForkParaAutonomySuperGroup=0
[fork.sub.evm]
Enable=0
......@@ -398,6 +402,7 @@ ForkUnfreezeIDX= 0
[fork.sub.autonomy]
Enable=0
ForkAutonomyDelRule=0
ForkAutonomyEnableItem=0
[fork.sub.jsvm]
Enable=0
......
......@@ -277,6 +277,9 @@ superManager=[
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv",
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"
]
#autonomy执行器名字
autonomyExec="autonomy"
[exec.sub.paracross]
nodeGroupFrozenCoins=0
#平行链共识停止后主链等待的高度
......@@ -307,7 +310,7 @@ pointHX="19172955941344617222923168298456110557655645809646772800021167670156933
pointHY="21116962883761739586121793871108889864627195706475546685847911817475098399811"
#电路最大支持1024个叶子hash,10 level, 配置可以小于1024,但不能大于
maxTreeLeaves=1024
mixApprs=["12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"]
[metrics]
#是否使能发送metrics数据的发送
......
......@@ -3,7 +3,7 @@ module github.com/33cn/plugin
go 1.15
require (
github.com/33cn/chain33 v1.65.6-0.20211025083411-82c4406c6701
github.com/33cn/chain33 v1.65.6-0.20211118074307-04e724cee41c
github.com/BurntSushi/toml v0.3.1
github.com/NebulousLabs/Sia v1.3.7
github.com/NebulousLabs/errors v0.0.0-20181203160057-9f787ce8f69e // indirect
......
......@@ -35,7 +35,7 @@ const (
//current miner tx take any privatekey for unify all nodes sign purpose, and para chain is free
minerPrivateKey = "6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
defaultGenesisAmount int64 = 1e8
poolMainBlockSec int64 = 5
poolMainBlockMsec int64 = 5000
defaultEmptyBlockInterval int64 = 50 //write empty block every interval blocks in mainchain
defaultSearchMatchedBlockDepth int32 = 10000
)
......@@ -70,7 +70,7 @@ type client struct {
}
type subConfig struct {
WriteBlockSeconds int64 `json:"writeBlockSeconds,omitempty"`
WriteBlockMsec int64 `json:"writeBlockMsec,omitempty"`
ParaRemoteGrpcClient string `json:"paraRemoteGrpcClient,omitempty"`
StartHeight int64 `json:"startHeight,omitempty"`
WaitMainBlockNum int64 `json:"waitMainBlockNum,omitempty"`
......@@ -105,8 +105,8 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
subcfg.GenesisAmount = defaultGenesisAmount
}
if subcfg.WriteBlockSeconds <= 0 {
subcfg.WriteBlockSeconds = poolMainBlockSec
if subcfg.WriteBlockMsec <= 0 {
subcfg.WriteBlockMsec = poolMainBlockMsec
}
//WaitMainBlockNum 配置最小为1,因为genesis块是startHeight-1, wait=1和startHeight相等
......@@ -291,7 +291,7 @@ func (client *client) GetStartMainHash(height int64) []byte {
}
if height > 0 {
hint := time.NewTicker(time.Second * time.Duration(client.subCfg.WriteBlockSeconds))
hint := time.NewTicker(time.Second)
for lastHeight < height+client.subCfg.WaitMainBlockNum {
select {
case <-hint.C:
......
......@@ -537,7 +537,7 @@ out:
if err == nil {
continue
}
time.Sleep(time.Second * time.Duration(client.subCfg.WriteBlockSeconds))
time.Sleep(time.Millisecond * time.Duration(client.subCfg.WriteBlockMsec))
continue
}
......
......@@ -63,6 +63,7 @@ func (j *jumpDldClient) getParaHeightList(startHeight, endHeight int64) ([]*type
return heightList, nil
}
//分页查找,只获取范围内的高度
plog.Info("jumpDld.getParaTxHeightList", "start", heights.Items[0].GetHeight(), "end", heights.Items[len(heights.Items)-1].GetHeight())
for _, h := range heights.Items {
if h.Height >= startHeight && h.Height <= endHeight {
heightList = append(heightList, h)
......@@ -280,17 +281,20 @@ func (j *jumpDldClient) getParaTxs(startHeight, endHeight int64, heights []*type
//获取每一排1000个paraTxBlocks
paraBlocks, err := j.getParaTxsBlocks(row, title)
if err != nil {
plog.Error("jumpDld.getParaTxsBlocks", "err", err)
return err
}
//根据1000个paraTxBlocks的头尾高度获取header的头尾高度,header的高度要包含paraTxBlocks高度
headerStart, headerEnd := getHeaderStartEndRange(startHeight, endHeight, heightsRows, i)
plog.Debug("jumpDld.getParaTxs", "headerStart", headerStart, "headerEnd", headerEnd, "i", i)
plog.Info("jumpDld.getParaTxs", "headerStart", headerStart, "headerEnd", headerEnd, "i", i)
err = j.procParaTxHeaders(headerStart, headerEnd, paraBlocks, jobCh)
if err != nil {
plog.Error("jumpDld.procParaTxHeaders", "err", err)
return err
}
if atomic.LoadInt32(&j.downFail) != 0 || j.paraClient.isCancel() {
plog.Error("jumpDld.downFail", "downfail", atomic.LoadInt32(&j.downFail))
return errors.New("verify fail or main thread cancel")
}
}
......
......@@ -69,6 +69,15 @@ func AutonomyCmd() *cobra.Command {
ShowProposalChangeCmd(),
)
// item
cmd.AddCommand(
ProposalItemCmd(),
RevokeProposalItemCmd(),
VoteProposalItemCmd(),
TerminateProposalItemCmd(),
ShowProposalItemCmd(),
)
return cmd
}
......
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package commands
import (
"encoding/json"
jsonrpc "github.com/33cn/chain33/rpc/jsonclient"
rpctypes "github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
auty "github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/spf13/cobra"
)
// ProposalItemCmd 创建提案命令
func ProposalItemCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "proposalItem",
Short: "create proposal Item",
Run: proposalItem,
}
addProposalItemFlags(cmd)
return cmd
}
func addProposalItemFlags(cmd *cobra.Command) {
cmd.Flags().Int32P("year", "y", 0, "year")
cmd.Flags().Int32P("month", "m", 0, "month")
cmd.Flags().Int32P("day", "d", 0, "day")
cmd.Flags().StringP("itemTxHash", "i", "", "the tx to apply check")
cmd.MarkFlagRequired("itemTxHash")
cmd.Flags().StringP("exec", "x", "", "last stage proposal ID")
cmd.Flags().StringP("description", "p", "", "description item")
cmd.Flags().Int64P("startBlock", "s", 0, "start block height")
cmd.MarkFlagRequired("startBlock")
cmd.Flags().Int64P("endBlock", "e", 0, "end block height")
cmd.MarkFlagRequired("endBlock")
}
func proposalItem(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
paraName, _ := cmd.Flags().GetString("paraName")
year, _ := cmd.Flags().GetInt32("year")
month, _ := cmd.Flags().GetInt32("month")
day, _ := cmd.Flags().GetInt32("day")
txHash, _ := cmd.Flags().GetString("itemTxHash")
exec, _ := cmd.Flags().GetString("exec")
description, _ := cmd.Flags().GetString("description")
startBlock, _ := cmd.Flags().GetInt64("startBlock")
endBlock, _ := cmd.Flags().GetInt64("endBlock")
params := &auty.ProposalItem{
Year: year,
Month: month,
Day: day,
ItemTxHash: txHash,
Exec: exec,
Description: description,
StartBlockHeight: startBlock,
EndBlockHeight: endBlock,
}
payLoad, err := json.Marshal(params)
if err != nil {
return
}
pm := &rpctypes.CreateTxIn{
Execer: types.GetExecName(auty.AutonomyX, paraName),
ActionName: "PropItem",
Payload: payLoad,
}
var res string
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", pm, &res)
ctx.RunWithoutMarshal()
}
// RevokeProposalItemCmd 撤销提案
func RevokeProposalItemCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "revokeItem",
Short: "revoke proposal Item",
Run: revokeProposalItem,
}
addRevokeProposalItemFlags(cmd)
return cmd
}
func addRevokeProposalItemFlags(cmd *cobra.Command) {
cmd.Flags().StringP("proposalID", "p", "", "proposal ID")
cmd.MarkFlagRequired("proposalID")
}
func revokeProposalItem(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName")
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ID, _ := cmd.Flags().GetString("proposalID")
params := &auty.RevokeProposalItem{
ProposalID: ID,
}
payLoad, err := json.Marshal(params)
if err != nil {
return
}
pm := &rpctypes.CreateTxIn{
Execer: types.GetExecName(auty.AutonomyX, paraName),
ActionName: "RvkPropItem",
Payload: payLoad,
}
var res string
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", pm, &res)
ctx.RunWithoutMarshal()
}
// VoteProposalItemCmd 投票提案
func VoteProposalItemCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "voteItem",
Short: "vote proposal Item",
Run: voteProposalItem,
}
addVoteProposalItemFlags(cmd)
return cmd
}
func addVoteProposalItemFlags(cmd *cobra.Command) {
cmd.Flags().StringP("proposalID", "p", "", "proposal ID")
cmd.MarkFlagRequired("proposalID")
cmd.Flags().Int32P("approve", "r", 1, "1:approve, 2:oppose, 3:quit, default 1")
}
func voteProposalItem(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName")
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ID, _ := cmd.Flags().GetString("proposalID")
approve, _ := cmd.Flags().GetInt32("approve")
params := &auty.VoteProposalItem{
ProposalID: ID,
Vote: auty.AutonomyVoteOption(approve),
}
payLoad, err := json.Marshal(params)
if err != nil {
return
}
pm := &rpctypes.CreateTxIn{
Execer: types.GetExecName(auty.AutonomyX, paraName),
ActionName: "VotePropItem",
Payload: payLoad,
}
var res string
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", pm, &res)
ctx.RunWithoutMarshal()
}
// TerminateProposalItemCmd 终止提案
func TerminateProposalItemCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "terminateItem",
Short: "terminate proposal Item",
Run: terminateProposalItem,
}
addTerminateProposalItemFlags(cmd)
return cmd
}
func addTerminateProposalItemFlags(cmd *cobra.Command) {
cmd.Flags().StringP("proposalID", "p", "", "proposal ID")
cmd.MarkFlagRequired("proposalID")
}
func terminateProposalItem(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName")
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ID, _ := cmd.Flags().GetString("proposalID")
params := &auty.RevokeProposalItem{
ProposalID: ID,
}
payLoad, err := json.Marshal(params)
if err != nil {
return
}
pm := &rpctypes.CreateTxIn{
Execer: types.GetExecName(auty.AutonomyX, paraName),
ActionName: "TmintPropItem",
Payload: payLoad,
}
var res string
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", pm, &res)
ctx.RunWithoutMarshal()
}
// ShowProposalItemCmd 显示提案查询信息
func ShowProposalItemCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "showItem",
Short: "show proposal Item info",
Run: showProposalItem,
}
addShowProposalItemflags(cmd)
return cmd
}
func addShowProposalItemflags(cmd *cobra.Command) {
cmd.Flags().Uint32P("type", "y", 0, "type(0:query by hash; 1:list)")
cmd.MarkFlagRequired("type")
cmd.Flags().StringP("proposalID", "p", "", "proposal ID")
cmd.Flags().Uint32P("status", "s", 0, "status")
cmd.Flags().StringP("addr", "a", "", "address")
cmd.Flags().Int32P("count", "c", 1, "count, default is 1")
cmd.Flags().Int32P("direction", "d", 0, "direction, default is reserve")
cmd.Flags().Int64P("height", "t", -1, "height, default is -1")
cmd.Flags().Int32P("index", "i", -1, "index, default is -1")
}
func showProposalItem(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
typ, _ := cmd.Flags().GetUint32("type")
propID, _ := cmd.Flags().GetString("proposalID")
status, _ := cmd.Flags().GetUint32("status")
addr, _ := cmd.Flags().GetString("addr")
count, _ := cmd.Flags().GetInt32("count")
direction, _ := cmd.Flags().GetInt32("direction")
height, _ := cmd.Flags().GetInt64("height")
index, _ := cmd.Flags().GetInt32("index")
var params rpctypes.Query4Jrpc
var rep interface{}
params.Execer = auty.AutonomyX
if 0 == typ {
req := types.ReqString{
Data: propID,
}
params.FuncName = auty.GetProposalItem
params.Payload = types.MustPBToJSON(&req)
rep = &auty.ReplyQueryProposalItem{}
} else if 1 == typ {
req := auty.ReqQueryProposalItem{
Status: int32(status),
Addr: addr,
Count: count,
Direction: direction,
Height: height,
Index: index,
}
params.FuncName = auty.ListProposalItem
params.Payload = types.MustPBToJSON(&req)
rep = &auty.ReplyQueryProposalItem{}
}
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, rep)
ctx.Run()
}
......@@ -7,6 +7,7 @@ package executor
import (
"github.com/33cn/chain33/types"
auty "github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/pkg/errors"
)
// 提案董事会相关
......@@ -130,3 +131,39 @@ func (a *Autonomy) Exec_TmintPropChange(payload *auty.TerminateProposalChange, t
action := newAction(a, tx, int32(index))
return action.tmintPropChange(payload)
}
// Exec_PropChange 创建事项规则
func (a *Autonomy) Exec_PropItem(payload *auty.ProposalItem, tx *types.Transaction, index int) (*types.Receipt, error) {
if !a.GetAPI().GetConfig().IsDappFork(a.GetHeight(), auty.AutonomyX, auty.ForkAutonomyEnableItem) {
return nil, errors.Wrapf(types.ErrActionNotSupport, "not after fork")
}
action := newAction(a, tx, int32(index))
return action.propItem(payload)
}
// Exec_RvkPropItem 撤销事项规则
func (a *Autonomy) Exec_RvkPropItem(payload *auty.RevokeProposalItem, tx *types.Transaction, index int) (*types.Receipt, error) {
if !a.GetAPI().GetConfig().IsDappFork(a.GetHeight(), auty.AutonomyX, auty.ForkAutonomyEnableItem) {
return nil, errors.Wrapf(types.ErrActionNotSupport, "not after fork")
}
action := newAction(a, tx, int32(index))
return action.rvkPropItem(payload)
}
// Exec_VotePropItem 投票事项规则
func (a *Autonomy) Exec_VotePropItem(payload *auty.VoteProposalItem, tx *types.Transaction, index int) (*types.Receipt, error) {
if !a.GetAPI().GetConfig().IsDappFork(a.GetHeight(), auty.AutonomyX, auty.ForkAutonomyEnableItem) {
return nil, errors.Wrapf(types.ErrActionNotSupport, "not after fork")
}
action := newAction(a, tx, int32(index))
return action.votePropItem(payload)
}
// Exec_TmintPropItem 终止事项规则
func (a *Autonomy) Exec_TmintPropItem(payload *auty.TerminateProposalItem, tx *types.Transaction, index int) (*types.Receipt, error) {
if !a.GetAPI().GetConfig().IsDappFork(a.GetHeight(), auty.AutonomyX, auty.ForkAutonomyEnableItem) {
return nil, errors.Wrapf(types.ErrActionNotSupport, "not after fork")
}
action := newAction(a, tx, int32(index))
return action.tmintPropItem(payload)
}
......@@ -106,3 +106,23 @@ func (a *Autonomy) ExecLocal_VotePropChange(payload *auty.VoteProposalChange, tx
func (a *Autonomy) ExecLocal_TmintPropChange(payload *auty.TerminateProposalChange, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return a.execAutoLocalChange(tx, receiptData)
}
// ExecLocal_PropItem 创建事项规则
func (a *Autonomy) ExecLocal_PropItem(payload *auty.ProposalItem, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return a.execAutoLocalItem(tx, receiptData)
}
// ExecLocal_RvkPropItem 撤销事项规则
func (a *Autonomy) ExecLocal_RvkPropItem(payload *auty.RevokeProposalItem, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return a.execAutoLocalItem(tx, receiptData)
}
// ExecLocal_VotePropItem 投票事项规则
func (a *Autonomy) ExecLocal_VotePropItem(payload *auty.VoteProposalItem, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return a.execAutoLocalItem(tx, receiptData)
}
// ExecLocal_TmintPropItem 终止事项规则
func (a *Autonomy) ExecLocal_TmintPropItem(payload *auty.TerminateProposalItem, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return a.execAutoLocalItem(tx, receiptData)
}
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package executor
import (
dbm "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
auty "github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/pkg/errors"
)
func (a *Autonomy) execAutoLocalItem(tx *types.Transaction, receiptData *types.ReceiptData) (*types.LocalDBSet, error) {
set, err := a.execLocalItem(receiptData)
if err != nil {
return set, err
}
dbSet := &types.LocalDBSet{}
dbSet.KV = a.AddRollbackKV(tx, tx.Execer, set.KV)
return dbSet, nil
}
func (a *Autonomy) execLocalItem(receiptData *types.ReceiptData) (*types.LocalDBSet, error) {
table := NewItemTable(a.GetLocalDB())
for _, log := range receiptData.Logs {
switch log.Ty {
case auty.TyLogPropItem,
auty.TyLogRvkPropItem,
auty.TyLogVotePropItem,
auty.TyLogTmintPropItem:
{
var receipt auty.ReceiptProposalItem
err := types.Decode(log.Log, &receipt)
if err != nil {
return nil, err
}
err = table.Replace(receipt.Current)
if err != nil {
return nil, err
}
}
default:
break
}
}
kvs, err := table.Save()
if err != nil {
return nil, err
}
dbSet := &types.LocalDBSet{}
dbSet.KV = append(dbSet.KV, kvs...)
return dbSet, nil
}
func (a *Autonomy) listProposalItem(req *auty.ReqQueryProposalItem) (types.Message, error) {
if req == nil {
return nil, types.ErrInvalidParam
}
localDb := a.GetLocalDB()
query := NewItemTable(localDb).GetQuery(localDb)
var primary []byte
if req.Height > 0 {
primary = []byte(dapp.HeightIndexStr(req.Height, int64(req.Index)))
}
indexName := ""
if req.Status > 0 && req.Addr != "" {
indexName = "addr_status"
} else if req.Status > 0 {
indexName = "status"
} else if req.Addr != "" {
indexName = "addr"
}
cur := &ItemRow{
AutonomyProposalItem: &auty.AutonomyProposalItem{},
}
cur.Address = req.Addr
cur.Status = req.Status
cur.Height = req.Height
cur.Index = req.Index
prefix, err := cur.Get(indexName)
if err != nil {
alog.Error("Get", "indexName", indexName, "err", err)
return nil, err
}
rows, err := query.ListIndex(indexName, prefix, primary, req.Count, req.Direction)
if err != nil {
alog.Error("query List failed", "indexName", indexName, "prefix", "prefix", "key", string(primary), "err", err)
return nil, err
}
if len(rows) == 0 {
return nil, types.ErrNotFound
}
var rep auty.ReplyQueryProposalItem
for _, row := range rows {
r, ok := row.Data.(*auty.AutonomyProposalItem)
if !ok {
alog.Error("listProposalItem", "err", "bad row type")
return nil, types.ErrDecode
}
rep.PropItems = append(rep.PropItems, r)
}
return &rep, nil
}
func getProposalItem(db dbm.KV, req *types.ReqString) (*auty.ReplyQueryProposalItem, error) {
if req == nil || len(req.Data) <= 0 {
return nil, errors.Wrapf(types.ErrInvalidParam, "invalid parameter")
}
value, err := db.Get(propItemID(req.Data))
if err != nil {
return nil, errors.Wrapf(err, "fail,db.get item id=%s", req.Data)
}
prop := &auty.AutonomyProposalItem{}
err = types.Decode(value, prop)
if err != nil {
return nil, errors.Wrapf(err, "decode item fail")
}
rep := &auty.ReplyQueryProposalItem{}
rep.PropItems = append(rep.PropItems, prop)
return rep, nil
}
// IsAutonomyApprovedItem get 2 parameters: autonomyItemID, applyTxHash
func IsAutonomyApprovedItem(db dbm.KV, req *types.ReqMultiStrings) (types.Message, error) {
if req == nil {
return nil, errors.Wrapf(types.ErrInvalidParam, "req is nil")
}
if len(req.Datas) < 2 {
return nil, errors.Wrapf(types.ErrInvalidParam, "req datas less 2 parameters")
}
autonomyItemID := req.Datas[0]
applyTxHash := req.Datas[1]
res, err := getProposalItem(db, &types.ReqString{Data: autonomyItemID})
if err != nil {
return nil, err
}
if len(res.GetPropItems()) <= 0 {
return nil, errors.Wrapf(types.ErrNotFound, "not get item")
}
if res.PropItems[0].ProposalID != autonomyItemID {
return nil, errors.Wrapf(types.ErrInvalidParam, "get prop id=%s not equal req=%s", res.PropItems[0].ProposalID, autonomyItemID)
}
if res.PropItems[0].PropItem.ItemTxHash != applyTxHash {
return nil, errors.Wrapf(types.ErrInvalidParam, "get item id=%s != req=%s", res.PropItems[0].PropItem.ItemTxHash, applyTxHash)
}
if res.PropItems[0].Status == auty.AutonomyStatusTmintPropItem && res.PropItems[0].BoardVoteRes.Pass {
return &types.Reply{IsOk: true}, nil
}
if res.PropItems[0].Status != auty.AutonomyStatusTmintPropItem {
return nil, errors.Wrapf(types.ErrNotAllow, "item status =%d not terminate", res.PropItems[0].Status)
}
return nil, errors.Wrapf(types.ErrNotAllow, "item vote status not pass = %v", res.PropItems[0].BoardVoteRes.Pass)
}
This diff is collapsed.
package executor
import (
"fmt"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
auty "github.com/33cn/plugin/plugin/dapp/autonomy/types"
)
/*
table struct
data: autonomy item
index: status, addr
*/
var itemOpt = &table.Option{
Prefix: "LODB-autonomy",
Name: "item",
Primary: "heightindex",
Index: []string{"addr", "status", "addr_status"},
}
//NewItemTable 新建表
func NewItemTable(kvdb db.KV) *table.Table {
rowmeta := NewItemRow()
newTable, err := table.NewTable(rowmeta, kvdb, itemOpt)
if err != nil {
panic(err)
}
return newTable
}
//ItemRow table meta 结构
type ItemRow struct {
*auty.AutonomyProposalItem
}
//NewItemRow 新建一个meta 结构
func NewItemRow() *ItemRow {
return &ItemRow{AutonomyProposalItem: &auty.AutonomyProposalItem{}}
}
//CreateRow 新建数据行(注意index 数据一定也要保存到数据中,不能就保存heightindex)
func (r *ItemRow) CreateRow() *table.Row {
return &table.Row{Data: &auty.AutonomyProposalItem{}}
}
//SetPayload 设置数据
func (r *ItemRow) SetPayload(data types.Message) error {
if d, ok := data.(*auty.AutonomyProposalItem); ok {
r.AutonomyProposalItem = d
return nil
}
return types.ErrTypeAsset
}
//Get 按照indexName 查询 indexValue
func (r *ItemRow) Get(key string) ([]byte, error) {
if key == "heightindex" {
return []byte(dapp.HeightIndexStr(r.Height, int64(r.Index))), nil
} else if key == "status" {
return []byte(fmt.Sprintf("%2d", r.Status)), nil
} else if key == "addr" {
return []byte(r.Address), nil
} else if key == "addr_status" {
return []byte(fmt.Sprintf("%s:%2d", r.Address, r.Status)), nil
}
return nil, types.ErrNotFound
}
......@@ -79,3 +79,12 @@ var (
func propChangeID(txHash string) []byte {
return []byte(fmt.Sprintf("%s%s", changePrefix, txHash))
}
var (
//item
itemPrefix = idPrefix + "item-"
)
func propItemID(txHash string) []byte {
return []byte(fmt.Sprintf("%s%s", itemPrefix, txHash))
}
......@@ -261,7 +261,7 @@ func (a *action) votePropProject(voteProb *auty.VoteProposalProject) (*types.Rec
}
if a.api.GetConfig().IsDappFork(a.height, auty.AutonomyX, auty.ForkAutonomyDelRule) {
if cur.BoardVoteRes.TotalVotes != 0 &&
if cur.BoardVoteRes.TotalVotes != 0 && cur.BoardVoteRes.TotalVotes > cur.BoardVoteRes.QuitVotes &&
float32(cur.BoardVoteRes.ApproveVotes)/float32(cur.BoardVoteRes.TotalVotes-cur.BoardVoteRes.QuitVotes) >= float32(cur.CurRule.BoardApproveRatio)/100.0 {
cur.BoardVoteRes.Pass = true
cur.PropProject.RealEndBlockHeight = a.height
......@@ -463,7 +463,7 @@ func (a *action) tmintPropProject(tmintProb *auty.TerminateProposalProject) (*ty
return nil, err
}
if a.api.GetConfig().IsDappFork(a.height, auty.AutonomyX, auty.ForkAutonomyDelRule) {
if cur.BoardVoteRes.TotalVotes != 0 &&
if cur.BoardVoteRes.TotalVotes != 0 && cur.BoardVoteRes.TotalVotes > cur.BoardVoteRes.QuitVotes &&
float32(cur.BoardVoteRes.ApproveVotes)/float32(cur.BoardVoteRes.TotalVotes-cur.BoardVoteRes.QuitVotes) >= float32(cur.CurRule.BoardApproveRatio)/100.0 {
cur.BoardVoteRes.Pass = true
} else {
......
......@@ -63,3 +63,18 @@ func (a *Autonomy) Query_GetProposalChange(in *types.ReqString) (types.Message,
func (a *Autonomy) Query_ListProposalChange(in *auty.ReqQueryProposalChange) (types.Message, error) {
return a.listProposalChange(in)
}
// Query_GetProposalItem 查询提案
func (a *Autonomy) Query_GetProposalItem(in *types.ReqString) (types.Message, error) {
return getProposalItem(a.GetStateDB(), in)
}
// Query_ListProposalItem 批量查询
func (a *Autonomy) Query_ListProposalItem(in *auty.ReqQueryProposalItem) (types.Message, error) {
return a.listProposalItem(in)
}
// Query_GetProposalChange 查询提案修改董事会成员
func (a *Autonomy) Query_IsAutonomyApprovedItem(in *types.ReqMultiStrings) (types.Message, error) {
return IsAutonomyApprovedItem(a.GetStateDB(), in)
}
......@@ -9,6 +9,7 @@ import "board.proto";
import "project.proto";
import "rule.proto";
import "change.proto";
import "item.proto";
package types;
option go_package = "../types";
......@@ -40,6 +41,13 @@ message AutonomyAction {
RevokeProposalChange rvkPropChange = 17;
VoteProposalChange votePropChange = 18;
TerminateProposalChange tmintPropChange = 19;
//提案事项审核相关
ProposalItem propItem = 21;
RevokeProposalItem rvkPropItem = 22;
VoteProposalItem votePropItem = 23;
TerminateProposalItem tmintPropItem = 24;
}
int32 ty = 20;
}
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
syntax = "proto3";
import "lcommon.proto";
package types;
option go_package = "../types";
message AutonomyProposalItem {
ProposalItem propItem = 1;
// 投票该提案的规则
RuleConfig curRule = 2;
// 投票该提案的董事会成员
repeated string boards = 3;
// 董事会投票结果
VoteResult boardVoteRes = 4;
// 状态
int32 status = 6;
string address = 7;
int64 height = 8;
int32 index = 9;
string proposalID = 10;
}
message ProposalItem {
// 提案时间
int32 year = 1;
int32 month = 2;
int32 day = 3;
// 项目相关
string itemTxHash = 4; // item tx hash
string exec = 5; // 合约执行器
string description = 7; // 简述
// 投票相关
int64 startBlockHeight = 12; // 提案开始投票高度
int64 endBlockHeight = 13; // 提案结束投票高度
int64 realEndBlockHeight = 14; // 实际提案结束投票高度
int32 projectNeedBlockNum = 15; // 以提案结束投票高度为准,需要项目需要消耗的区块数目所对应的时间
}
message RevokeProposalItem {
string proposalID = 1;
}
message VoteProposalItem {
string proposalID = 1;
bool approve = 2;
AutonomyVoteOption vote = 3;
}
message TerminateProposalItem {
string proposalID = 1;
}
// receipt
message ReceiptProposalItem {
AutonomyProposalItem prev = 1;
AutonomyProposalItem current = 2;
}
message LocalProposalItem {
AutonomyProposalItem propItem = 1;
repeated string comments = 2;
}
// query
message ReqQueryProposalItem {
int32 status = 1;
string addr = 2;
int32 count = 3;
int32 direction = 4;
int64 height = 5;
int32 index = 6;
}
message ReplyQueryProposalItem {
repeated AutonomyProposalItem propItems = 1;
}
This diff is collapsed.
......@@ -30,6 +30,11 @@ const (
AutonomyActionVotePropChange
AutonomyActionTmintPropChange
AutonomyActionPropItem
AutonomyActionRvkPropItem
AutonomyActionVotePropItem
AutonomyActionTmintPropItem
//log for autonomy
TyLogPropBoard = 2101
TyLogRvkPropBoard = 2102
......@@ -53,6 +58,11 @@ const (
TyLogRvkPropChange = 2142
TyLogVotePropChange = 2143
TyLogTmintPropChange = 2144
TyLogPropItem = 2161
TyLogRvkPropItem = 2162
TyLogVotePropItem = 2163
TyLogTmintPropItem = 2164
)
// Board status
......@@ -88,6 +98,14 @@ const (
AutonomyStatusTmintPropChange
)
// Item status
const (
AutonomyStatusProposalItem = iota + 1
AutonomyStatusRvkPropItem
AutonomyStatusVotePropItem
AutonomyStatusTmintPropItem
)
const (
// GetProposalBoard 用于在cmd里面的区分不同的查询
GetProposalBoard = "GetProposalBoard"
......@@ -111,6 +129,11 @@ const (
GetProposalChange = "GetProposalChange"
// ListProposalChange 查询多个
ListProposalChange = "ListProposalChange"
// GetProposalItem 用于在cmd里面的区分不同的查询
GetProposalItem = "GetProposalItem"
// ListProposalItem 查询多个
ListProposalItem = "ListProposalItem"
)
//包的名字可以通过配置文件来配置
......
This diff is collapsed.
......@@ -15,6 +15,8 @@ var name string
var (
//ForkAutonomyDelRule fork for delete boards member rules
ForkAutonomyDelRule = "ForkAutonomyDelRule"
//ForkAutonomyEnableItem fork for add autonomy item support
ForkAutonomyEnableItem = "ForkAutonomyEnableItem"
)
func init() {
......@@ -28,6 +30,7 @@ func init() {
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(AutonomyX, "Enable", 0)
cfg.RegisterDappFork(AutonomyX, ForkAutonomyDelRule, 9500000)
cfg.RegisterDappFork(AutonomyX, ForkAutonomyEnableItem, 10000000)
}
//InitExecutor ...
......@@ -78,6 +81,11 @@ func (a *AutonomyType) GetLogMap() map[int64]*types.LogInfo {
TyLogRvkPropChange: {Ty: reflect.TypeOf(ReceiptProposalChange{}), Name: "LogRvkPropChange"},
TyLogVotePropChange: {Ty: reflect.TypeOf(ReceiptProposalChange{}), Name: "LogVotePropChange"},
TyLogTmintPropChange: {Ty: reflect.TypeOf(ReceiptProposalChange{}), Name: "LogTmintPropChange"},
TyLogPropItem: {Ty: reflect.TypeOf(ReceiptProposalItem{}), Name: "LogPropItem"},
TyLogRvkPropItem: {Ty: reflect.TypeOf(ReceiptProposalItem{}), Name: "LogRvkPropItem"},
TyLogVotePropItem: {Ty: reflect.TypeOf(ReceiptProposalItem{}), Name: "LogVotePropItem"},
TyLogTmintPropItem: {Ty: reflect.TypeOf(ReceiptProposalItem{}), Name: "LogTmintPropItem"},
}
}
......@@ -112,5 +120,10 @@ func (a *AutonomyType) GetTypeMap() map[string]int32 {
"RvkPropChange": AutonomyActionRvkPropChange,
"VotePropChange": AutonomyActionVotePropChange,
"TmintPropChange": AutonomyActionTmintPropChange,
"PropItem": AutonomyActionPropItem,
"RvkPropItem": AutonomyActionRvkPropItem,
"VotePropItem": AutonomyActionVotePropItem,
"TmintPropItem": AutonomyActionTmintPropItem,
}
}
......@@ -426,7 +426,7 @@ function para_create_nodegroup() {
echo "=========== # para chain approve node group ============="
##approve
txhash=$(${PARA_CLI} send para nodegroup approve -i "$id" -c 6 -k 0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc)
txhash=$(${PARA_CLI} send para nodegroup approve -i "$id" -a "" -c 6 -k 0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc)
echo "tx=$txhash"
query_tx "${PARA_CLI}" "${txhash}"
......
......@@ -6,7 +6,6 @@ package executor
import (
dbm "github.com/33cn/chain33/common/db"
manager "github.com/33cn/chain33/system/dapp/manage/types"
"github.com/33cn/chain33/types"
mixTy "github.com/33cn/plugin/plugin/dapp/mix/types"
"github.com/pkg/errors"
......@@ -14,8 +13,8 @@ import (
// IsSuperManager is supper manager or not
func isSuperManager(cfg *types.Chain33Config, addr string) bool {
confManager := types.ConfSub(cfg, manager.ManageX)
for _, m := range confManager.GStrList("superManager") {
confMix := types.ConfSub(cfg, mixTy.MixX)
for _, m := range confMix.GStrList("mixApprs") {
if addr == m {
return true
}
......
......@@ -544,7 +544,7 @@ function para_create_nodegroup_gamechain() {
echo "=========== # game para chain approve node group ============="
##approve
txhash=$(${CLI} --paraName user.p.game. send para nodegroup approve -i "$id" -c 5 -k "${SUPER_KEY}")
txhash=$(${CLI} --paraName user.p.game. send para nodegroup approve -i "$id" -a "" -c 5 -k "${SUPER_KEY}")
echo "tx=$txhash"
query_tx "${PARA_CLI5}" "${txhash}"
......@@ -718,7 +718,7 @@ function para_create_nodegroup() {
echo "=========== # para chain approve node group ============="
##approve
txhash=$(${PARA_CLI} send para nodegroup approve -i "$id" -c 6 -k "${SUPER_KEY}")
txhash=$(${PARA_CLI} send para nodegroup approve -i "$id" -a "" -c 6 -k "${SUPER_KEY}")
echo "tx=$txhash"
query_tx "${PARA_CLI}" "${txhash}"
......@@ -758,7 +758,7 @@ function para_create_nodegroup() {
fi
##approve
txhash=$(${PARA_CLI} send para nodegroup approve -i "$modifyid" -c 5 -k "${SUPER_KEY}")
txhash=$(${PARA_CLI} send para nodegroup approve -i "$modifyid" -a "" -c 5 -k "${SUPER_KEY}")
echo "tx=$txhash"
query_tx "${PARA_CLI}" "${txhash}"
......@@ -850,7 +850,7 @@ function para_create_supervision_nodegroup_quit() {
echo "=========== # para chain approve supervision node group 28 ============="
##approve
txhash=$(${PARA_CLI} send para supervision_node approve -i "$id" -c 6 -k "${SUPER_KEY}")
txhash=$(${PARA_CLI} send para supervision_node approve -i "$id" -a "" -c 6 -k "${SUPER_KEY}")
echo "tx=$txhash"
query_tx "${PARA_CLI}" "${txhash}"
......@@ -865,7 +865,7 @@ function para_create_supervision_nodegroup_quit() {
query_tx "${PARA_CLI}" "${txhash}"
check_balance_1ka "$balancePre" -6
check_supervision_node_group_list 3 "$id"
check_supervision_node_group_list 3 "$txhash"
check_supervision_node_addr_status 3 "$ADDR_28"
check_supervision_node_addrs null
echo "=========== # ${FUNCNAME} end ============="
......@@ -885,7 +885,7 @@ function para_create_supervision_nodegroup_approve() {
echo "=========== # para chain approve supervision node group 28 ============="
##approve
txhash=$(${PARA_CLI} send para supervision_node approve -i "$id" -c 6 -k "${SUPER_KEY}")
txhash=$(${PARA_CLI} send para supervision_node approve -i "$id" -a "" -c 6 -k "${SUPER_KEY}")
echo "tx=$txhash"
query_tx "${PARA_CLI}" "${txhash}"
......
......@@ -363,7 +363,6 @@ func addNodeJoinFlags(cmd *cobra.Command) {
_ = cmd.MarkFlagRequired("addr")
cmd.Flags().Float64P("coins", "c", 0, "frozen coins amount, should not less nodegroup's setting")
_ = cmd.MarkFlagRequired("coins")
}
......@@ -908,7 +907,6 @@ func addNodeGroupApplyCmdFlags(cmd *cobra.Command) {
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")
}
......@@ -946,12 +944,24 @@ func nodeGroupApply(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal()
}
func nodeGroupApproveCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "approve",
Short: "approve for para chain's super node group application",
Run: nodeGroupApprove,
}
addNodeGroupApproveCmdFlags(cmd)
return cmd
}
func addNodeGroupApproveCmdFlags(cmd *cobra.Command) {
cmd.Flags().StringP("id", "i", "", "apply id for nodegroup ")
_ = cmd.MarkFlagRequired("id")
cmd.Flags().StringP("autonomyId", "a", "", "autonomy approved id ")
_ = cmd.MarkFlagRequired("autonomyId")
cmd.Flags().Float64P("coins", "c", 0, "coins amount to frozen, not less config")
_ = cmd.MarkFlagRequired("coins")
}
......@@ -959,6 +969,7 @@ func nodeGroupApprove(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName")
id, _ := cmd.Flags().GetString("id")
coins, _ := cmd.Flags().GetFloat64("coins")
autonomyId, _ := cmd.Flags().GetString("autonomyId")
if !strings.HasPrefix(paraName, "user.p") {
_, _ = fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
......@@ -975,7 +986,7 @@ func nodeGroupApprove(cmd *cobra.Command, args []string) {
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "FormatFloatDisplay2Value.coins"))
return
}
payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 2, Id: id, CoinsFrozen: coinsInt64}
payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 2, Id: id, CoinsFrozen: coinsInt64, AutonomyItemID: autonomyId}
params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "NodeGroupConfig",
......@@ -986,13 +997,13 @@ func nodeGroupApprove(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal()
}
func nodeGroupApproveCmd() *cobra.Command {
func nodeGroupQuitCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "approve",
Short: "approve for para chain's super node group application",
Run: nodeGroupApprove,
Use: "quit",
Short: "quit for para chain's super node group application",
Run: nodeGroupQuit,
}
addNodeGroupApproveCmdFlags(cmd)
addNodeGroupQuitCmdFlags(cmd)
return cmd
}
......@@ -1005,6 +1016,7 @@ func addNodeGroupQuitCmdFlags(cmd *cobra.Command) {
func nodeGroupQuit(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName")
id, _ := cmd.Flags().GetString("id")
if !strings.HasPrefix(paraName, "user.p") {
_, _ = fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
......@@ -1021,13 +1033,13 @@ func nodeGroupQuit(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal()
}
func nodeGroupQuitCmd() *cobra.Command {
func nodeGroupModifyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "quit",
Short: "quit for para chain's super node group application",
Run: nodeGroupQuit,
Use: "modify",
Short: "modify for para chain's super node group parameters",
Run: nodeGroupModify,
}
addNodeGroupQuitCmdFlags(cmd)
addNodeGroupModifyCmdFlags(cmd)
return cmd
}
......@@ -1066,16 +1078,6 @@ func nodeGroupModify(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal()
}
func nodeGroupModifyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "modify",
Short: "modify for para chain's super node group parameters",
Run: nodeGroupModify,
}
addNodeGroupModifyCmdFlags(cmd)
return cmd
}
// IsSyncCmd query parachain is sync
func IsSyncCmd() *cobra.Command {
cmd := &cobra.Command{
......@@ -1645,7 +1647,6 @@ func addSupervisionNodeApplyCmdFlags(cmd *cobra.Command) {
cmd.Flags().StringP("blspub", "p", "", "bls sign pub key for addr's private key")
cmd.Flags().Float64P("coins", "c", 0, "coins amount to frozen, not less config")
_ = cmd.MarkFlagRequired("coins")
}
func supervisionNodeApply(cmd *cobra.Command, args []string) {
......@@ -1658,7 +1659,7 @@ func supervisionNodeApply(cmd *cobra.Command, args []string) {
_, _ = fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
payload := &pt.ParaNodeAddrConfig{Title: paraName, Op: 1, Addr: addr, BlsPubKey: blspub, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 1, Addrs: addr, BlsPubKeys: blspub, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "SupervisionNodeConfig",
......@@ -1684,13 +1685,16 @@ func addSupervisionNodeApproveCmdFlags(cmd *cobra.Command) {
cmd.Flags().StringP("id", "i", "", "apply id for supervision node ")
_ = cmd.MarkFlagRequired("id")
cmd.Flags().StringP("autonomyId", "a", "", "autonomy approved id ")
_ = cmd.MarkFlagRequired("autonomyId")
cmd.Flags().Float64P("coins", "c", 0, "coins amount to frozen, not less config")
_ = cmd.MarkFlagRequired("coins")
}
func supervisionNodeApprove(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName")
id, _ := cmd.Flags().GetString("id")
autonomyId, _ := cmd.Flags().GetString("autonomyId")
coins, _ := cmd.Flags().GetFloat64("coins")
if !strings.HasPrefix(paraName, "user.p") {
......@@ -1698,7 +1702,7 @@ func supervisionNodeApprove(cmd *cobra.Command, args []string) {
return
}
payload := &pt.ParaNodeAddrConfig{Title: paraName, Op: 2, Id: id, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 2, Id: id, AutonomyItemID: autonomyId, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "SupervisionNodeConfig",
......@@ -1732,7 +1736,7 @@ func supervisionNodeQuit(cmd *cobra.Command, args []string) {
_, _ = fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
payload := &pt.ParaNodeAddrConfig{Title: paraName, Op: 3, Addr: opAddr}
payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 3, Addrs: opAddr}
params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "SupervisionNodeConfig",
......@@ -1766,7 +1770,7 @@ func supervisionNodeCancel(cmd *cobra.Command, args []string) {
_, _ = fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
payload := &pt.ParaNodeAddrConfig{Title: paraName, Op: 4, Id: id}
payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 4, Id: id}
params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "SupervisionNodeConfig",
......@@ -1833,7 +1837,7 @@ func supervisionNodeListInfo(cmd *cobra.Command, args []string) {
}
params.Payload = types.MustPBToJSON(&req)
var res pt.RespParacrossNodeAddrs
var res pt.RespParacrossNodeGroups
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run()
}
......
......@@ -127,7 +127,7 @@ func (e *Paracross) Exec_ParaBindMiner(payload *pt.ParaBindMinerCmd, tx *types.T
}
//Exec_SupervisionNodeConfig exec Supervision node config
func (e *Paracross) Exec_SupervisionNodeConfig(payload *pt.ParaNodeAddrConfig, tx *types.Transaction, index int) (*types.Receipt, error) {
func (e *Paracross) Exec_SupervisionNodeConfig(payload *pt.ParaNodeGroupConfig, tx *types.Transaction, index int) (*types.Receipt, error) {
a := newAction(e, tx)
return a.SupervisionNodeConfig(payload)
}
......@@ -137,22 +137,22 @@ func (e *Paracross) ExecDelLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig
return &set, nil
}
func (e *Paracross) ExecDelLocal_SupervisionNodeConfig(payload *pt.ParaNodeAddrConfig, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
func (e *Paracross) ExecDelLocal_SupervisionNodeConfig(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.TyLogParaSupervisionNodeConfig {
var g pt.ReceiptParaNodeConfig
var g pt.ReceiptParaNodeGroupConfig
err := types.Decode(log.Log, &g)
if err != nil {
return nil, err
}
if g.Prev != nil {
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalSupervisionNodeStatusTitle(g.Current.Title, g.Prev.Status, g.Current.TargetAddr, g.Current.Id), Value: types.Encode(g.Prev)})
Key: calcLocalSupervisionNodeStatusTitle(g.Current.Title, g.Prev.Status, g.Current.TargetAddrs, g.Current.Id), Value: types.Encode(g.Prev)})
}
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalSupervisionNodeStatusTitle(g.Current.Title, g.Current.Status, g.Current.TargetAddr, g.Current.Id), Value: nil})
Key: calcLocalSupervisionNodeStatusTitle(g.Current.Title, g.Current.Status, g.Current.TargetAddrs, g.Current.Id), Value: nil})
}
}
return &set, nil
......
......@@ -141,22 +141,22 @@ func (e *Paracross) ExecLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig, t
return &set, nil
}
func (e *Paracross) ExecLocal_SupervisionNodeConfig(payload *pt.ParaNodeAddrConfig, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
func (e *Paracross) ExecLocal_SupervisionNodeConfig(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.TyLogParaSupervisionNodeConfig {
var g pt.ReceiptParaNodeConfig
var g pt.ReceiptParaNodeGroupConfig
err := types.Decode(log.Log, &g)
if err != nil {
return nil, err
}
if g.Prev != nil {
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalSupervisionNodeStatusTitle(g.Current.Title, g.Prev.Status, g.Current.TargetAddr, g.Current.Id), Value: nil})
Key: calcLocalSupervisionNodeStatusTitle(g.Current.Title, g.Prev.Status, g.Current.TargetAddrs, g.Current.Id), Value: nil})
}
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalSupervisionNodeStatusTitle(g.Current.Title, g.Current.Status, g.Current.TargetAddr, g.Current.Id), Value: types.Encode(g.Current)})
Key: calcLocalSupervisionNodeStatusTitle(g.Current.Title, g.Current.Status, g.Current.TargetAddrs, g.Current.Id), Value: types.Encode(g.Current)})
}
}
return &set, nil
......
......@@ -281,12 +281,12 @@ func (p *Paracross) Query_ListSupervisionNodeStatusInfo(in *pt.ReqParacrossNodeI
prefix = calcLocalSupervisionNodeStatusTitlePrefix(in.Title, in.Status)
}
resp, err := listNodeStatus(p.GetLocalDB(), prefix)
resp, err := listNodeGroupStatus(p.GetLocalDB(), prefix)
if err != nil {
return resp, err
}
addrs := resp.(*pt.RespParacrossNodeAddrs)
addrs := resp.(*pt.RespParacrossNodeGroups)
for _, id := range addrs.Ids {
id.Id = getParaNodeIDSuffix(id.Id)
}
......
......@@ -957,12 +957,42 @@ func (a *action) nodeGroupApproveApply(config *pt.ParaNodeGroupConfig, apply *pt
return receipt, nil
}
func (a *action) checkApproveOp(config *pt.ParaNodeGroupConfig) error {
cfg := a.api.GetConfig()
//fork之后采用 autonomy 检查模式
confManager := types.ConfSub(cfg, manager.ManageX)
autonomyExec := confManager.GStr(types.AutonomyCfgKey)
if cfg.IsDappFork(a.height, pt.ParaX, pt.ForkParaAutonomySuperGroup) && len(autonomyExec) > 0 {
//去autonomy 合约检验是否id approved, 成功 err返回nil
_, err := a.api.QueryChain(&types.ChainExecutor{
Driver: autonomyExec,
FuncName: "IsAutonomyApprovedItem",
Param: types.Encode(&types.ReqMultiStrings{Datas: []string{config.AutonomyItemID, config.Id}}),
})
if err != nil {
return errors.Wrapf(err, "query autonomy,approveid=%s,hashId=%s", config.AutonomyItemID, config.Id)
}
return nil
}
//fork之前检查是否from superManager
if !isSuperManager(cfg, a.fromaddr) {
return errors.Wrapf(types.ErrNotAllow, "node group approve not super manager:%s", a.fromaddr)
}
return nil
}
// NodeGroupApprove super addr approve the node group apply
func (a *action) nodeGroupApprove(config *pt.ParaNodeGroupConfig) (*types.Receipt, error) {
cfg := a.api.GetConfig()
//只在主链检查
if !cfg.IsPara() && !isSuperManager(cfg, a.fromaddr) {
return nil, errors.Wrapf(types.ErrNotAllow, "node group approve not super manager:%s", a.fromaddr)
//只在主链检查, 主链检查失败不会同步到平行链,主链成功,平行链默认成功
if !cfg.IsPara() {
err := a.checkApproveOp(config)
if err != nil {
return nil, err
}
}
id, err := getNodeGroupID(cfg, a.db, config.Title, a.exec.GetMainHeight(), config.Id)
......
......@@ -7,7 +7,7 @@ import (
)
// createRawSupervisionNodeConfigTx create raw tx for node config
func createRawSupervisionNodeConfigTx(config *pt.ParaNodeAddrConfig) *types.Transaction {
func createRawSupervisionNodeConfigTx(config *pt.ParaNodeGroupConfig) *types.Transaction {
action := &pt.ParacrossAction{
Ty: pt.ParacrossActionSupervisionNodeConfig,
Value: &pt.ParacrossAction_SupervisionNodeConfig{SupervisionNodeConfig: config},
......@@ -32,10 +32,10 @@ func (suite *NodeManageTestSuite) testSupervisionExec() {
func (suite *NodeManageTestSuite) testSupervisionNodeConfigCancel(addr, privKey string) {
// Apply
config := &pt.ParaNodeAddrConfig{
config := &pt.ParaNodeGroupConfig{
Title: chain33TestCfg.GetTitle(),
Op: pt.ParacrossSupervisionNodeApply,
Addr: addr,
Addrs: addr,
}
tx := createRawSupervisionNodeConfigTx(config)
receipt := nodeCommit(suite, privKey, tx)
......@@ -46,7 +46,7 @@ func (suite *NodeManageTestSuite) testSupervisionNodeConfigCancel(addr, privKey
suite.Nil(err)
// cancel
config = &pt.ParaNodeAddrConfig{
config = &pt.ParaNodeGroupConfig{
Title: chain33TestCfg.GetTitle(),
Op: pt.ParacrossSupervisionNodeCancel,
Id: getParaNodeIDSuffix(g.Current.Id),
......@@ -57,10 +57,10 @@ func (suite *NodeManageTestSuite) testSupervisionNodeConfigCancel(addr, privKey
}
func (suite *NodeManageTestSuite) testSupervisionNodeConfigApprove(addr, privKey string) {
config := &pt.ParaNodeAddrConfig{
config := &pt.ParaNodeGroupConfig{
Title: chain33TestCfg.GetTitle(),
Op: pt.ParacrossSupervisionNodeApply,
Addr: addr,
Addrs: addr,
}
tx := createRawSupervisionNodeConfigTx(config)
receipt := nodeCommit(suite, privKey, tx)
......@@ -70,7 +70,7 @@ func (suite *NodeManageTestSuite) testSupervisionNodeConfigApprove(addr, privKey
err := types.Decode(receipt.Logs[0].Log, &g)
suite.Nil(err)
config = &pt.ParaNodeAddrConfig{
config = &pt.ParaNodeGroupConfig{
Title: chain33TestCfg.GetTitle(),
Id: getParaNodeIDSuffix(g.Current.Id),
Op: pt.ParacrossSupervisionNodeApprove,
......@@ -81,20 +81,20 @@ func (suite *NodeManageTestSuite) testSupervisionNodeConfigApprove(addr, privKey
}
func (suite *NodeManageTestSuite) testSupervisionNodeError() {
config := &pt.ParaNodeAddrConfig{
config := &pt.ParaNodeGroupConfig{
Title: chain33TestCfg.GetTitle(),
Op: pt.ParacrossSupervisionNodeApply,
Addr: Account1M3,
Addrs: Account1M3,
}
tx := createRawSupervisionNodeConfigTx(config)
tx, _ = signTx(suite.Suite, tx, PrivKey1M3)
_, err := suite.exec.Exec(tx, 0)
suite.NotNil(err)
config = &pt.ParaNodeAddrConfig{
config = &pt.ParaNodeGroupConfig{
Title: chain33TestCfg.GetTitle(),
Op: pt.ParacrossSupervisionNodeApply,
Addr: "1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4",
Addrs: "1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4",
}
tx = createRawSupervisionNodeConfigTx(config)
tx, _ = signTx(suite.Suite, tx, PrivKey1KS)
......@@ -103,10 +103,10 @@ func (suite *NodeManageTestSuite) testSupervisionNodeError() {
}
func (suite *NodeManageTestSuite) testSupervisionNodeQuit() {
config := &pt.ParaNodeAddrConfig{
config := &pt.ParaNodeGroupConfig{
Title: chain33TestCfg.GetTitle(),
Op: pt.ParacrossSupervisionNodeQuit,
Addr: Account1Ku,
Addrs: Account1Ku,
}
tx := createRawSupervisionNodeConfigTx(config)
receipt := nodeCommit(suite, PrivKey1Ku, tx)
......@@ -123,11 +123,11 @@ func (suite *NodeManageTestSuite) testSupervisionNodeQuit() {
}
func (suite *NodeManageTestSuite) testSupervisionNodeModify() {
config := &pt.ParaNodeAddrConfig{
Title: chain33TestCfg.GetTitle(),
Op: pt.ParacrossSupervisionNodeModify,
Addr: Account14K,
BlsPubKey: Bls14K,
config := &pt.ParaNodeGroupConfig{
Title: chain33TestCfg.GetTitle(),
Op: pt.ParacrossSupervisionNodeModify,
Addrs: Account14K,
BlsPubKeys: Bls14K,
}
tx := createRawSupervisionNodeConfigTx(config)
receipt := nodeCommit(suite, PrivKey14K, tx)
......
......@@ -125,6 +125,7 @@ message ParaNodeGroupConfig {
string addrs = 4;
int64 coinsFrozen = 5;
string blsPubKeys = 6;
string autonomyItemID = 7;
}
message ParaNodeGroupStatus {
......@@ -356,7 +357,7 @@ message ParacrossAction {
ParaStageConfig selfStageConfig = 11;
CrossAssetTransfer crossAssetTransfer = 12;
ParaBindMinerCmd paraBindMiner = 13;
ParaNodeAddrConfig supervisionNodeConfig = 14;
ParaNodeGroupConfig supervisionNodeConfig = 14;
}
int32 ty = 2;
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -19,19 +19,23 @@ var (
// ForkCommitTx main chain support paracross commit tx
ForkCommitTx = "ForkParacrossCommitTx"
// MainForkParacrossCommitTx 平行链配置项对应主链的ForkCommitTx 高度
// 同一个fork,同一份代码在主链和平行链需要执行高度一致,需要平行链配置主链fork高度
MainForkParacrossCommitTx = "mainForkParacrossCommitTx"
// ForkLoopCheckCommitTxDone 循环检查共识交易done的fork
ForkLoopCheckCommitTxDone = "ForkLoopCheckCommitTxDone"
// MainLoopCheckCommitTxDoneForkHeight 平行链的配置项,对应主链的ForkLoopCheckCommitTxDone高度
MainLoopCheckCommitTxDoneForkHeight = "mainLoopCheckCommitTxDoneForkHeight"
//MainForkParaSupervision = "mainForkParaSupervision"
// ForkParaSelfConsStages 平行链自共识分阶段共识
ForkParaSelfConsStages = "ForkParaSelfConsStages"
// ForkParaAssetTransferRbk 平行链资产转移平行链失败主链回滚
ForkParaAssetTransferRbk = "ForkParaAssetTransferRbk"
// ForkParaSupervision 平行链新增监督节点
ForkParaSupervision = "ForkParaSupervision"
//ForkParaAutonomySuperGroup 分叉之后autonomy授权共识账户组,之前是配置超级管理员授权
ForkParaAutonomySuperGroup = "ForkParaAutonomySuperGroup"
//只在平行链开启的分叉
// ForkParaSelfConsStages 平行链自共识分阶段共识
ForkParaSelfConsStages = "ForkParaSelfConsStages"
// ForkParaFullMinerHeight 平行链全挖矿开启高度
ForkParaFullMinerHeight = "ForkParaFullMinerHeight"
// ForkParaRootHash 平行链按照ForkRootHash计算rootHash高度,在之前版本中平行链侧计算txRootHash没有提供正确的主链高度计算,需要分叉
......@@ -65,6 +69,7 @@ func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(ParaX, ForkLoopCheckCommitTxDone, 3230000)
cfg.RegisterDappFork(ParaX, ForkParaAssetTransferRbk, 4500000)
cfg.RegisterDappFork(ParaX, ForkParaSupervision, 6000000)
cfg.RegisterDappFork(ParaX, ForkParaAutonomySuperGroup, 10200000)
//只在平行链启用
cfg.RegisterDappFork(ParaX, ForkParaSelfConsStages, types.MaxHeight)
......@@ -122,7 +127,7 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
TyLogParaStageGroupUpdate: {Ty: reflect.TypeOf(ReceiptSelfConsStagesUpdate{}), Name: "LogParaSelfConfStagesUpdate"},
TyLogParaBindMinerAddr: {Ty: reflect.TypeOf(ReceiptParaBindMinerInfo{}), Name: "TyLogParaBindMinerAddrUpdate"},
TyLogParaBindMinerNode: {Ty: reflect.TypeOf(ReceiptParaNodeBindListUpdate{}), Name: "TyLogParaBindNodeListUpdate"},
TyLogParaSupervisionNodeConfig: {Ty: reflect.TypeOf(ReceiptParaNodeConfig{}), Name: "LogParaSupervisionNodeConfig"},
TyLogParaSupervisionNodeConfig: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaSupervisionNodeConfig"},
TyLogParaSupervisionNodeGroupAddrsUpdate: {Ty: reflect.TypeOf(types.ReceiptConfig{}), Name: "LogParaSupervisionNodeGroupAddrsUpdate"},
TyLogParaSupervisionNodeStatusUpdate: {Ty: reflect.TypeOf(ReceiptParaNodeAddrStatUpdate{}), Name: "LogParaSupervisionNodeStatusUpdate"},
}
......
......@@ -236,6 +236,7 @@ ForkTokenCheck= 0
[fork.sub.manage]
Enable=0
ForkManageExec=0
ForkManageAutonomyEnable=-1
[fork.sub.valnode]
Enable=0
......@@ -255,6 +256,7 @@ ForkParaAssetTransferRbk=0
ForkParaFullMinerHeight=0
ForkParaSupervision=0
ForkParaRootHash=0
#nodegroup approve需要经过autonomy board成员审批,平行链不开启
ForkParaAutonomySuperGroup=-1
[fork.sub.qbftNode]
Enable=0
......@@ -295,6 +295,7 @@ ForkBadRepeatSecret=0
[fork.sub.manage]
Enable=0
ForkManageExec=100000
ForkManageAutonomyEnable=-1
[fork.sub.token]
Enable=0
......@@ -324,6 +325,7 @@ ForkParaAssetTransferRbk=0
ForkParaFullMinerHeight=0
ForkParaSupervision=0
ForkParaRootHash=0
ForkParaAutonomySuperGroup=-1
[fork.sub.evm]
Enable=0
......@@ -402,6 +404,7 @@ ForkUnfreezeIDX= 0
[fork.sub.autonomy]
Enable=0
ForkAutonomyDelRule=0
ForkAutonomyEnableItem=0
[fork.sub.jsvm]
Enable=0
......
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