Commit 586a3ff1 authored by mdj33's avatar mdj33 Committed by vipwzw

add ci rpc test

parent 3bd22644
......@@ -755,7 +755,7 @@ func (client *commitMsgClient) getSelfConsensus() (*pt.ParacrossStatus, error) {
return nil, err
}
//开启自共识后也要等到自共识真正切换之后再使用,如果本地区块已经过了自共识高度,但自共识的高度还没达成,就会导致共识机制出错
if resp.Height > stage.BlockHeight {
if resp.Height > stage.StartHeight {
return resp, nil
}
}
......
This diff is collapsed.
......@@ -498,13 +498,15 @@ func addSelfConsStageCmdFlags(cmd *cobra.Command) {
func selfConsStage(cmd *cobra.Command, args []string) {
height, _ := cmd.Flags().GetInt64("height")
enable, _ := cmd.Flags().GetUint32("enable")
paraName, _ := cmd.Flags().GetString("paraName")
var config pt.ParaStageConfig
config.OpTy = pt.ParaOpNewApply
config.Op = &pt.ParaStageConfig_Stage{Stage: &pt.SelfConsensStage{BlockHeight: height, Enable: enable}}
config.Title = paraName
config.Op = pt.ParaOpNewApply
config.Value = &pt.ParaStageConfig_Stage{Stage: &pt.SelfConsensStage{StartHeight: height, Enable: enable}}
params := &rpctypes.CreateTxIn{
Execer: pt.ParaX,
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "selfConsStageConfig",
Payload: types.MustPBToJSON(&config),
}
......@@ -535,13 +537,15 @@ func addVoteFlags(cmd *cobra.Command) {
func createVoteTx(cmd *cobra.Command, args []string) {
id, _ := cmd.Flags().GetString("id")
val, _ := cmd.Flags().GetUint32("value")
paraName, _ := cmd.Flags().GetString("paraName")
var config pt.ParaStageConfig
config.OpTy = pt.ParaOpVote
config.Op = &pt.ParaStageConfig_Vote{Vote: &pt.ConfigVoteInfo{Id: id, Value: val}}
config.Title = paraName
config.Op = pt.ParaOpVote
config.Value = &pt.ParaStageConfig_Vote{Vote: &pt.ConfigVoteInfo{Id: id, Value: val}}
params := &rpctypes.CreateTxIn{
Execer: pt.ParaX,
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "selfConsStageConfig",
Payload: types.MustPBToJSON(&config),
}
......@@ -564,13 +568,15 @@ func configVoteCmd() *cobra.Command {
func stageCancelTx(cmd *cobra.Command, args []string) {
id, _ := cmd.Flags().GetString("id")
paraName, _ := cmd.Flags().GetString("paraName")
var config pt.ParaStageConfig
config.OpTy = pt.ParaOpCancel
config.Op = &pt.ParaStageConfig_Cancel{Cancel: &pt.ConfigCancelInfo{Id: id}}
config.Title = paraName
config.Op = pt.ParaOpCancel
config.Value = &pt.ParaStageConfig_Cancel{Cancel: &pt.ConfigCancelInfo{Id: id}}
params := &rpctypes.CreateTxIn{
Execer: pt.ParaX,
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "selfConsStageConfig",
Payload: types.MustPBToJSON(&config),
}
......
......@@ -732,7 +732,7 @@ func (a *action) isAllowParaConsensJump(commit *pt.ParacrossCommitAction, titleS
if stage == nil {
return false, nil
}
return stage.BlockHeight == commit.Status.Height, nil
return stage.StartHeight == commit.Status.Height, nil
}
//兼容分叉之前从1跳跃场景
......
......@@ -127,7 +127,7 @@ func (suite *CommitTestSuite) SetupSuite() {
assert.Equal(suite.T(), value, types.Encode(nodeValue))
stageKey := calcParaSelfConsStagesKey()
stage := &pt.SelfConsensStage{BlockHeight: 0, Enable: pt.ParaConfigYes}
stage := &pt.SelfConsensStage{StartHeight: 0, Enable: pt.ParaConfigYes}
stages := &pt.SelfConsensStages{Items: []*pt.SelfConsensStage{stage}}
suite.stateDB.Set(stageKey, types.Encode(stages))
value, err = suite.stateDB.Get(stageKey)
......@@ -486,7 +486,7 @@ func (s *VoteTestSuite) SetupSuite() {
s.exec.SetEnv(0, 0, 0)
stageKey := calcParaSelfConsStagesKey()
stage := &pt.SelfConsensStage{BlockHeight: 0, Enable: pt.ParaConfigYes}
stage := &pt.SelfConsensStage{StartHeight: 0, Enable: pt.ParaConfigYes}
stages := &pt.SelfConsensStages{Items: []*pt.SelfConsensStage{stage}}
s.stateDB.Set(stageKey, types.Encode(stages))
value, err := s.stateDB.Get(stageKey)
......
......@@ -104,14 +104,14 @@ func getSelfConsensStages(db dbm.KV) (*pt.SelfConsensStages, error) {
func getSelfConsStagesMap(stages []*pt.SelfConsensStage) map[int64]uint32 {
stagesMap := make(map[int64]uint32)
for _, v := range stages {
stagesMap[v.BlockHeight] = v.Enable
stagesMap[v.StartHeight] = v.Enable
}
return stagesMap
}
func sortStages(stages *pt.SelfConsensStages, new *pt.SelfConsensStage) {
stages.Items = append(stages.Items, new)
sort.Slice(stages.Items, func(i, j int) bool { return stages.Items[i].BlockHeight < stages.Items[j].BlockHeight })
sort.Slice(stages.Items, func(i, j int) bool { return stages.Items[i].StartHeight < stages.Items[j].StartHeight })
}
func updateStages(db dbm.KV, stage *pt.SelfConsensStage) (*types.Receipt, error) {
......@@ -138,7 +138,7 @@ func updateStages(db dbm.KV, stage *pt.SelfConsensStage) (*types.Receipt, error)
func selfConsensInitStage(cfg *types.Chain33Config) *types.Receipt {
close := cfg.IsEnable(pt.ParaConsSubConf + "." + pt.ParaSelfConsInitConf)
stage := &pt.SelfConsensStage{BlockHeight: 0, Enable: pt.ParaConfigYes}
stage := &pt.SelfConsensStage{StartHeight: 0, Enable: pt.ParaConfigYes}
if close {
stage.Enable = pt.ParaConfigNo
}
......@@ -153,7 +153,7 @@ func getSelfConsOneStage(db dbm.KV, height int64) (*pt.SelfConsensStage, error)
}
for i := len(stages.Items) - 1; i >= 0; i-- {
if height >= stages.Items[i].BlockHeight {
if height >= stages.Items[i].StartHeight {
return stages.Items[i], nil
}
}
......@@ -172,13 +172,13 @@ func isSelfConsOn(db dbm.KV, height int64) (bool, error) {
func (a *action) checkValidStage(config *pt.SelfConsensStage) error {
cfg := a.api.GetConfig()
//0. 设置高度必须大于fork高度
if !cfg.IsDappFork(config.BlockHeight, pt.ParaX, pt.ForkParaSelfConsStages) {
return errors.Wrapf(types.ErrNotAllow, "checkValidStage config height:%d less than fork height", config.BlockHeight)
if !cfg.IsDappFork(config.StartHeight, pt.ParaX, pt.ForkParaSelfConsStages) {
return errors.Wrapf(types.ErrNotAllow, "checkValidStage config height:%d less than fork height", config.StartHeight)
}
//1. 设置高度必须大于当前区块高度
if config.BlockHeight <= a.height {
return errors.Wrapf(pt.ErrHeightHasPast, "checkValidStage config height:%d less than block height:%d", config.BlockHeight, a.height)
if config.StartHeight <= a.height {
return errors.Wrapf(pt.ErrHeightHasPast, "checkValidStage config height:%d less than block height:%d", config.StartHeight, a.height)
}
//2. 如果已经设置到stages中,简单起见,就不能更改了,应该也不会有很大影响
......@@ -188,8 +188,8 @@ func (a *action) checkValidStage(config *pt.SelfConsensStage) error {
}
if stages != nil {
stageMap := getSelfConsStagesMap(stages.Items)
if _, exist := stageMap[config.BlockHeight]; exist {
return errors.Wrapf(err, "checkValidStage config height:%d existed", config.BlockHeight)
if _, exist := stageMap[config.StartHeight]; exist {
return errors.Wrapf(err, "checkValidStage config height:%d existed", config.StartHeight)
}
}
......@@ -314,13 +314,13 @@ func (a *action) stageVote(config *pt.ConfigVoteInfo) (*types.Receipt, error) {
//SelfConsensStageConfig support self consens stage config
func (a *action) SelfStageConfig(config *pt.ParaStageConfig) (*types.Receipt, error) {
if config.OpTy == pt.ParaOpNewApply {
if config.Op == pt.ParaOpNewApply {
return a.stageApply(config.GetStage())
} else if config.OpTy == pt.ParaOpCancel {
} else if config.Op == pt.ParaOpCancel {
return a.stageCancel(config.GetCancel())
} else if config.OpTy == pt.ParaOpVote {
} else if config.Op == pt.ParaOpVote {
return a.stageVote(config.GetVote())
}
......
......@@ -13,16 +13,16 @@ import (
func TestSortStages(t *testing.T) {
stages := &pt.SelfConsensStages{}
n1 := &pt.SelfConsensStage{BlockHeight: 200, Enable: pt.ParaConfigYes}
n1 := &pt.SelfConsensStage{StartHeight: 200, Enable: pt.ParaConfigYes}
e1 := &pt.SelfConsensStages{Items: []*pt.SelfConsensStage{n1}}
n2 := &pt.SelfConsensStage{BlockHeight: 100, Enable: pt.ParaConfigNo}
n2 := &pt.SelfConsensStage{StartHeight: 100, Enable: pt.ParaConfigNo}
e2 := &pt.SelfConsensStages{Items: []*pt.SelfConsensStage{n2, n1}}
n3 := &pt.SelfConsensStage{BlockHeight: 700, Enable: pt.ParaConfigYes}
n3 := &pt.SelfConsensStage{StartHeight: 700, Enable: pt.ParaConfigYes}
e3 := &pt.SelfConsensStages{Items: []*pt.SelfConsensStage{n2, n1, n3}}
n4 := &pt.SelfConsensStage{BlockHeight: 500, Enable: pt.ParaConfigNo}
n4 := &pt.SelfConsensStage{StartHeight: 500, Enable: pt.ParaConfigNo}
e4 := &pt.SelfConsensStages{Items: []*pt.SelfConsensStage{n2, n1, n4, n3}}
sortStages(stages, n1)
......
......@@ -196,7 +196,7 @@ message SelfConsensStages {
message SelfConsensStage {
int64 blockHeight = 1;
int64 startHeight = 1;
uint32 enable = 2;
}
......@@ -229,10 +229,10 @@ message ConfigCancelInfo {
//广义配置类型
message ParaStageConfig {
string title = 1;
string title = 1;
// 配置类型
uint32 opTy = 2;
oneof op {
uint32 op = 2;
oneof value {
SelfConsensStage stage = 10;
ConfigVoteInfo vote = 11;
ConfigCancelInfo cancel= 12;
......
......@@ -171,9 +171,6 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
}
return CreateRawNodeGroupApplyTx(&param)
} else if action == "selfConsStageConfig" {
if !cfg.IsPara() {
return nil, types.ErrNotSupport
}
var param ParaStageConfig
err := types.JSONToPB(message, &param)
//err := json.Unmarshal(message, &param)
......
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