Commit 66b5c4f9 authored by mdj33's avatar mdj33 Committed by vipwzw

rebase master for new chain33 cfg

parent 91b38090
...@@ -253,6 +253,7 @@ Enable=0 ...@@ -253,6 +253,7 @@ Enable=0
ForkParacrossWithdrawFromParachain=0 ForkParacrossWithdrawFromParachain=0
ForkParacrossCommitTx=0 ForkParacrossCommitTx=0
ForkLoopCheckCommitTxDone=0 ForkLoopCheckCommitTxDone=0
#平行链分阶段自共识支持合约配置,缺省是0
ForkParaSelfConsStages=0 ForkParaSelfConsStages=0
[fork.sub.evm] [fork.sub.evm]
......
...@@ -168,10 +168,6 @@ func New(cfg *types.Consensus, sub []byte) queue.Module { ...@@ -168,10 +168,6 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
if subcfg.ParaConsensStartHeight > 0 { if subcfg.ParaConsensStartHeight > 0 {
para.commitMsgClient.consensDoneHeight = subcfg.ParaConsensStartHeight - 1 para.commitMsgClient.consensDoneHeight = subcfg.ParaConsensStartHeight - 1
} }
err = para.commitMsgClient.setSelfConsEnable()
if err != nil {
panic(err)
}
para.blockSyncClient = &blockSyncClient{ para.blockSyncClient = &blockSyncClient{
paraClient: para, paraClient: para,
...@@ -254,7 +250,7 @@ func (client *client) SetQueueClient(c queue.Client) { ...@@ -254,7 +250,7 @@ func (client *client) SetQueueClient(c queue.Client) {
}) })
go client.EventLoop() go client.EventLoop()
client.wg.Add(1) client.wg.Add(1)
go client.commitMsgClient.handler() go client.commitMsgClient.process()
client.wg.Add(1) client.wg.Add(1)
go client.CreateBlock() go client.CreateBlock()
client.wg.Add(1) client.wg.Add(1)
......
...@@ -409,7 +409,7 @@ func (client *commitMsgClient) getTxsGroup(txsArr *types.Transactions) (*types.T ...@@ -409,7 +409,7 @@ func (client *commitMsgClient) getTxsGroup(txsArr *types.Transactions) (*types.T
func (client *commitMsgClient) getExecName(commitHeight int64) string { func (client *commitMsgClient) getExecName(commitHeight int64) string {
cfg := client.paraClient.GetAPI().GetConfig() cfg := client.paraClient.GetAPI().GetConfig()
if cfg.IsDappFork(commitHeight, pt.ParaX, pt.ForkParaSelfConsStages) { if cfg.IsDappFork(commitHeight, pt.ParaX, pt.ForkParaSelfConsStages) {
return paracross.GetExecName() return paracross.GetExecName(cfg)
} }
execName := pt.ParaX execName := pt.ParaX
...@@ -441,7 +441,6 @@ func (client *commitMsgClient) batchCalcTxGroup(notifications []*pt.ParacrossNod ...@@ -441,7 +441,6 @@ func (client *commitMsgClient) batchCalcTxGroup(notifications []*pt.ParacrossNod
} }
func (client *commitMsgClient) singleCalcTx(status *pt.ParacrossNodeStatus, feeRate int64) (*types.Transaction, error) { func (client *commitMsgClient) singleCalcTx(status *pt.ParacrossNodeStatus, feeRate int64) (*types.Transaction, error) {
execName := pt.ParaX
cfg := client.paraClient.GetAPI().GetConfig() cfg := client.paraClient.GetAPI().GetConfig()
execName := client.getExecName(status.Height) execName := client.getExecName(status.Height)
tx, err := paracross.CreateRawCommitTx4MainChain(cfg, status, execName, feeRate) tx, err := paracross.CreateRawCommitTx4MainChain(cfg, status, execName, feeRate)
...@@ -903,7 +902,8 @@ func (client *commitMsgClient) fetchPriKey() error { ...@@ -903,7 +902,8 @@ func (client *commitMsgClient) fetchPriKey() error {
func (client *commitMsgClient) setSelfConsEnable() error { func (client *commitMsgClient) setSelfConsEnable() error {
var err error var err error
selfEnables := types.Conf("config.consensus.sub.para").GStrList("selfConsensEnablePreContract") cfg := client.paraClient.GetAPI().GetConfig()
selfEnables := types.Conf(cfg, "config.consensus.sub.para").GStrList("selfConsensEnablePreContract")
for _, v := range selfEnables { for _, v := range selfEnables {
hs := strings.Split(v, "-") hs := strings.Split(v, "-")
enable := &paraSelfConsEnable{} enable := &paraSelfConsEnable{}
...@@ -931,3 +931,15 @@ func (client *commitMsgClient) isSelfConsEnable(height int64) bool { ...@@ -931,3 +931,15 @@ func (client *commitMsgClient) isSelfConsEnable(height int64) bool {
} }
return false return false
} }
func (client *commitMsgClient) initConfig(){
err := client.setSelfConsEnable()
if err != nil{
panic(err)
}
}
func (client *commitMsgClient) process(){
client.initConfig()
client.handler()
}
\ No newline at end of file
...@@ -366,7 +366,7 @@ func (client *blockSyncClient) addMinerTx(preStateHash []byte, block *types.Bloc ...@@ -366,7 +366,7 @@ func (client *blockSyncClient) addMinerTx(preStateHash []byte, block *types.Bloc
MainBlockHeight: localBlock.MainHeight, MainBlockHeight: localBlock.MainHeight,
} }
maxHeight := pt.GetDappForkHeight(cfg,pt.ForkLoopCheckCommitTxDone) maxHeight := pt.GetDappForkHeight(cfg, pt.ForkLoopCheckCommitTxDone)
if maxHeight < client.paraClient.subCfg.RmCommitParamMainHeight { if maxHeight < client.paraClient.subCfg.RmCommitParamMainHeight {
maxHeight = client.paraClient.subCfg.RmCommitParamMainHeight maxHeight = client.paraClient.subCfg.RmCommitParamMainHeight
} }
......
...@@ -504,7 +504,7 @@ func selfConsStage(cmd *cobra.Command, args []string) { ...@@ -504,7 +504,7 @@ func selfConsStage(cmd *cobra.Command, args []string) {
config.Op = &pt.ParaStageConfig_Stage{Stage: &pt.SelfConsensStage{BlockHeight: height, Enable: enable}} config.Op = &pt.ParaStageConfig_Stage{Stage: &pt.SelfConsensStage{BlockHeight: height, Enable: enable}}
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pt.ParaX), Execer: pt.ParaX,
ActionName: "selfConsStageConfig", ActionName: "selfConsStageConfig",
Payload: types.MustPBToJSON(&config), Payload: types.MustPBToJSON(&config),
} }
...@@ -541,7 +541,7 @@ func createVoteTx(cmd *cobra.Command, args []string) { ...@@ -541,7 +541,7 @@ func createVoteTx(cmd *cobra.Command, args []string) {
config.Op = &pt.ParaStageConfig_Vote{Vote: &pt.ConfigVoteInfo{Id: id, Value: val}} config.Op = &pt.ParaStageConfig_Vote{Vote: &pt.ConfigVoteInfo{Id: id, Value: val}}
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pt.ParaX), Execer: pt.ParaX,
ActionName: "selfConsStageConfig", ActionName: "selfConsStageConfig",
Payload: types.MustPBToJSON(&config), Payload: types.MustPBToJSON(&config),
} }
...@@ -570,7 +570,7 @@ func stageCancelTx(cmd *cobra.Command, args []string) { ...@@ -570,7 +570,7 @@ func stageCancelTx(cmd *cobra.Command, args []string) {
config.Op = &pt.ParaStageConfig_Cancel{Cancel: &pt.ConfigCancelInfo{Id: id}} config.Op = &pt.ParaStageConfig_Cancel{Cancel: &pt.ConfigCancelInfo{Id: id}}
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pt.ParaX), Execer: pt.ParaX,
ActionName: "selfConsStageConfig", ActionName: "selfConsStageConfig",
Payload: types.MustPBToJSON(&config), Payload: types.MustPBToJSON(&config),
} }
......
...@@ -318,7 +318,7 @@ func updateCommitAddrs(stat *pt.ParacrossHeightStatus, nodes map[string]struct{} ...@@ -318,7 +318,7 @@ func updateCommitAddrs(stat *pt.ParacrossHeightStatus, nodes map[string]struct{}
func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error) { func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error) {
cfg := a.api.GetConfig() cfg := a.api.GetConfig()
if types.IsPara() && cfg.IsDappFork(a.height, pt.ParaX, pt.ForkParaSelfConsStages) { if cfg.IsPara() && cfg.IsDappFork(a.height, pt.ParaX, pt.ForkParaSelfConsStages) {
//分叉之后,key不存在,自共识没配置也认为不支持自共识 //分叉之后,key不存在,自共识没配置也认为不支持自共识
isSelfConsOn, err := isSelfConsOn(a.db, commit.Status.Height) isSelfConsOn, err := isSelfConsOn(a.db, commit.Status.Height)
if err != nil { if err != nil {
...@@ -467,7 +467,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error ...@@ -467,7 +467,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
if commit.Status.Height > titleStatus.Height+1 { if commit.Status.Height > titleStatus.Height+1 {
saveTitleHeight(a.db, calcTitleHeightKey(commit.Status.Title, commit.Status.Height), stat) saveTitleHeight(a.db, calcTitleHeightKey(commit.Status.Title, commit.Status.Height), stat)
//平行链由主链共识无缝切换,即接收第一个收到的高度,可以不从0开始 //平行链由主链共识无缝切换,即接收第一个收到的高度,可以不从0开始
allow, err := a.isAllowConsensJump(stat, titleStatus) allow, err := a.isAllowConsensJump(commit, titleStatus)
if err != nil { if err != nil {
clog.Error("paracross.Commit allowJump", "err", err) clog.Error("paracross.Commit allowJump", "err", err)
return nil, err return nil, err
...@@ -708,7 +708,7 @@ func (a *action) commitTxDoneByStat(stat *pt.ParacrossHeightStatus, titleStatus ...@@ -708,7 +708,7 @@ func (a *action) commitTxDoneByStat(stat *pt.ParacrossHeightStatus, titleStatus
} }
//主链共识跳跃条件: 仅支持主链共识初始高度为-1,也就是没有共识过,共识过不允许再跳跃 //主链共识跳跃条件: 仅支持主链共识初始高度为-1,也就是没有共识过,共识过不允许再跳跃
func (a *action) isAllowMainConsensJump(commit *pt.ParacrossHeightStatus, titleStatus *pt.ParacrossStatus) bool { func (a *action) isAllowMainConsensJump(commit *pt.ParacrossCommitAction, titleStatus *pt.ParacrossStatus) bool {
cfg := a.api.GetConfig() cfg := a.api.GetConfig()
if cfg.IsDappFork(a.exec.GetMainHeight(), pt.ParaX, pt.ForkLoopCheckCommitTxDone) { if cfg.IsDappFork(a.exec.GetMainHeight(), pt.ParaX, pt.ForkLoopCheckCommitTxDone) {
if titleStatus.Height == -1 { if titleStatus.Height == -1 {
...@@ -722,17 +722,17 @@ func (a *action) isAllowMainConsensJump(commit *pt.ParacrossHeightStatus, titleS ...@@ -722,17 +722,17 @@ func (a *action) isAllowMainConsensJump(commit *pt.ParacrossHeightStatus, titleS
//平行链自共识无缝切换条件:1,平行链没有共识过,2:commit高度是大于自共识分叉高度且上一次共识的主链高度小于自共识分叉高度,保证只运行一次, //平行链自共识无缝切换条件:1,平行链没有共识过,2:commit高度是大于自共识分叉高度且上一次共识的主链高度小于自共识分叉高度,保证只运行一次,
// 1. 分叉之前,开启过共识的平行链需要从1跳跃,没开启过的将使用新版本,从0开始发送,不用考虑从1跳跃的问题 // 1. 分叉之前,开启过共识的平行链需要从1跳跃,没开启过的将使用新版本,从0开始发送,不用考虑从1跳跃的问题
// 2. 分叉之后,只有stage.blockHeight== commit.height,也就是stage起始高度时候允许跳跃 // 2. 分叉之后,只有stage.blockHeight== commit.height,也就是stage起始高度时候允许跳跃
func (a *action) isAllowParaConsensJump(commit *pt.ParacrossHeightStatus, titleStatus *pt.ParacrossStatus) (bool, error) { func (a *action) isAllowParaConsensJump(commit *pt.ParacrossCommitAction, titleStatus *pt.ParacrossStatus) (bool, error) {
cfg := a.api.GetConfig() cfg := a.api.GetConfig()
if cfg.IsDappFork(a.height, pt.ParaX, pt.ForkParaSelfConsStages) { if cfg.IsDappFork(a.height, pt.ParaX, pt.ForkParaSelfConsStages) {
stage, err := getSelfConsOneStage(a.db, commit.Height) stage, err := getSelfConsOneStage(a.db, commit.Status.Height)
if err != nil && errors.Cause(err) != pt.ErrKeyNotExist { if err != nil && errors.Cause(err) != pt.ErrKeyNotExist {
return false, err return false, err
} }
if stage == nil { if stage == nil {
return false, nil return false, nil
} }
return stage.BlockHeight == commit.Height, nil return stage.BlockHeight == commit.Status.Height, nil
} }
//兼容分叉之前从1跳跃场景 //兼容分叉之前从1跳跃场景
...@@ -959,7 +959,7 @@ func (a *action) Miner(miner *pt.ParacrossMinerAction) (*types.Receipt, error) { ...@@ -959,7 +959,7 @@ func (a *action) Miner(miner *pt.ParacrossMinerAction) (*types.Receipt, error) {
minerReceipt := &types.Receipt{Ty: types.ExecOk, KV: nil, Logs: logs} minerReceipt := &types.Receipt{Ty: types.ExecOk, KV: nil, Logs: logs}
isSelfConsensOn := miner.IsSelfConsensus isSelfConsensOn := miner.IsSelfConsensus
if types.IsDappFork(a.height, pt.ParaX, pt.ForkParaSelfConsStages) { if cfg.IsDappFork(a.height, pt.ParaX, pt.ForkParaSelfConsStages) {
var err error var err error
isSelfConsensOn, err = isSelfConsOn(a.db, miner.Status.Height) isSelfConsensOn, err = isSelfConsOn(a.db, miner.Status.Height)
if err != nil && errors.Cause(err) != pt.ErrKeyNotExist { if err != nil && errors.Cause(err) != pt.ErrKeyNotExist {
......
...@@ -136,8 +136,8 @@ func updateStages(db dbm.KV, stage *pt.SelfConsensStage) (*types.Receipt, error) ...@@ -136,8 +136,8 @@ func updateStages(db dbm.KV, stage *pt.SelfConsensStage) (*types.Receipt, error)
} }
func selfConsensInitStage() *types.Receipt { func selfConsensInitStage(cfg *types.Chain33Config) *types.Receipt {
close := types.IsEnable("consensus.sub.para.paraSelfConsInitDisable") close := cfg.IsEnable("consensus.sub.para.paraSelfConsInitDisable")
stage := &pt.SelfConsensStage{BlockHeight: 0, Enable: pt.ParaConfigYes} stage := &pt.SelfConsensStage{BlockHeight: 0, Enable: pt.ParaConfigYes}
if close { if close {
stage.Enable = pt.ParaConfigNo stage.Enable = pt.ParaConfigNo
...@@ -170,8 +170,9 @@ func isSelfConsOn(db dbm.KV, height int64) (bool, error) { ...@@ -170,8 +170,9 @@ func isSelfConsOn(db dbm.KV, height int64) (bool, error) {
} }
func (a *action) checkValidStage(config *pt.SelfConsensStage) error { func (a *action) checkValidStage(config *pt.SelfConsensStage) error {
cfg := a.api.GetConfig()
//0. 设置高度必须大于fork高度 //0. 设置高度必须大于fork高度
if !types.IsDappFork(config.BlockHeight, pt.ParaX, pt.ForkParaSelfConsStages) { if !cfg.IsDappFork(config.BlockHeight, pt.ParaX, pt.ForkParaSelfConsStages) {
return errors.Wrapf(types.ErrNotAllow, "checkValidStage config height:%d less than fork height", config.BlockHeight) return errors.Wrapf(types.ErrNotAllow, "checkValidStage config height:%d less than fork height", config.BlockHeight)
} }
...@@ -242,9 +243,10 @@ func (a *action) stageCancel(config *pt.ConfigCancelInfo) (*types.Receipt, error ...@@ -242,9 +243,10 @@ func (a *action) stageCancel(config *pt.ConfigCancelInfo) (*types.Receipt, error
} }
func (a *action) stageVote(config *pt.ConfigVoteInfo) (*types.Receipt, error) { func (a *action) stageVote(config *pt.ConfigVoteInfo) (*types.Receipt, error) {
nodes, _, err := getParacrossNodes(a.db, types.GetTitle()) cfg := a.api.GetConfig()
nodes, _, err := getParacrossNodes(a.db, cfg.GetTitle())
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "getNodes for title:%s", types.GetTitle()) return nil, errors.Wrapf(err, "getNodes for title:%s", cfg.GetTitle())
} }
if !validNode(a.fromaddr, nodes) { if !validNode(a.fromaddr, nodes) {
return nil, errors.Wrapf(pt.ErrNodeNotForTheTitle, "not validNode:%s", a.fromaddr) return nil, errors.Wrapf(pt.ErrNodeNotForTheTitle, "not validNode:%s", a.fromaddr)
......
...@@ -927,10 +927,10 @@ func (a *action) nodeGroupApproveApply(config *pt.ParaNodeGroupConfig, apply *pt ...@@ -927,10 +927,10 @@ func (a *action) nodeGroupApproveApply(config *pt.ParaNodeGroupConfig, apply *pt
r = makeParaNodeGroupStatusReceipt(config.Title, a.fromaddr, nil, apply) r = makeParaNodeGroupStatusReceipt(config.Title, a.fromaddr, nil, apply)
receipt.KV = append(receipt.KV, r.KV...) receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...) receipt.Logs = append(receipt.Logs, r.Logs...)
cfg := a.api.GetConfig()
if types.IsPara() && types.IsDappFork(a.height, pt.ParaX, pt.ForkParaSelfConsStages) { if cfg.IsPara() && cfg.IsDappFork(a.height, pt.ParaX, pt.ForkParaSelfConsStages) {
//不允许主链成功平行链失败导致不一致的情况,这里如果失败则手工设置init stage //不允许主链成功平行链失败导致不一致的情况,这里如果失败则手工设置init stage
r = selfConsensInitStage() r = selfConsensInitStage(cfg)
receipt.KV = append(receipt.KV, r.KV...) receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...) receipt.Logs = append(receipt.Logs, r.Logs...)
} }
......
...@@ -373,8 +373,9 @@ func (c *Jrpc) ListNodeGroupStatus(req *pt.ReqParacrossNodeInfo, result *interfa ...@@ -373,8 +373,9 @@ func (c *Jrpc) ListNodeGroupStatus(req *pt.ReqParacrossNodeInfo, result *interfa
// GetNodeGroupAddrs get super node group addrs // GetNodeGroupAddrs get super node group addrs
func (c *channelClient) GetSelfConsStages(ctx context.Context, req *types.ReqNil) (*pt.SelfConsensStages, error) { func (c *channelClient) GetSelfConsStages(ctx context.Context, req *types.ReqNil) (*pt.SelfConsensStages, error) {
cfg := c.GetConfig()
r := *req r := *req
data, err := c.Query(pt.GetExecName(), "GetSelfConsStages", &r) data, err := c.Query(pt.GetExecName(cfg), "GetSelfConsStages", &r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -396,8 +397,9 @@ func (c *Jrpc) GetSelfConsStages(req *types.ReqNil, result *interface{}) error { ...@@ -396,8 +397,9 @@ func (c *Jrpc) GetSelfConsStages(req *types.ReqNil, result *interface{}) error {
// GetNodeGroupAddrs get super node group addrs // GetNodeGroupAddrs get super node group addrs
func (c *channelClient) GetSelfConsOneStage(ctx context.Context, req *types.Int64) (*pt.SelfConsensStage, error) { func (c *channelClient) GetSelfConsOneStage(ctx context.Context, req *types.Int64) (*pt.SelfConsensStage, error) {
cfg := c.GetConfig()
r := *req r := *req
data, err := c.Query(pt.GetExecName(), "GetSelfConsOneStage", &r) data, err := c.Query(pt.GetExecName(cfg), "GetSelfConsOneStage", &r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -418,8 +420,9 @@ func (c *Jrpc) GetSelfConsOneStage(req *types.Int64, result *interface{}) error ...@@ -418,8 +420,9 @@ func (c *Jrpc) GetSelfConsOneStage(req *types.Int64, result *interface{}) error
} }
func (c *channelClient) ListSelfStages(ctx context.Context, req *pt.ReqQuerySelfStages) (*pt.ReplyQuerySelfStages, error) { func (c *channelClient) ListSelfStages(ctx context.Context, req *pt.ReqQuerySelfStages) (*pt.ReplyQuerySelfStages, error) {
cfg := c.GetConfig()
r := *req r := *req
data, err := c.Query(pt.GetExecName(), "ListSelfStages", &r) data, err := c.Query(pt.GetExecName(cfg), "ListSelfStages", &r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -248,7 +248,6 @@ func CreateRawNodeGroupApplyTx(apply *ParaNodeGroupConfig) (*types.Transaction, ...@@ -248,7 +248,6 @@ func CreateRawNodeGroupApplyTx(apply *ParaNodeGroupConfig) (*types.Transaction,
//CreateRawSelfConsStageApplyTx create raw tx for self consens stage //CreateRawSelfConsStageApplyTx create raw tx for self consens stage
func CreateRawSelfConsStageApplyTx(apply *ParaStageConfig) (*types.Transaction, error) { func CreateRawSelfConsStageApplyTx(apply *ParaStageConfig) (*types.Transaction, error) {
action := &ParacrossAction{ action := &ParacrossAction{
Ty: ParacrossActionSelfStageConfig, Ty: ParacrossActionSelfStageConfig,
Value: &ParacrossAction_SelfStageConfig{apply}, Value: &ParacrossAction_SelfStageConfig{apply},
......
...@@ -172,7 +172,7 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types. ...@@ -172,7 +172,7 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
glog.Error("CreateTx.selfConsStageConfig", "Error", err) glog.Error("CreateTx.selfConsStageConfig", "Error", err)
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
return CreateRawSelfConsStageApplyTx(cfg, &param) return CreateRawSelfConsStageApplyTx(&param)
} }
return nil, types.ErrNotSupport return nil, types.ErrNotSupport
} }
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