Commit c6e251dc authored by mdj33's avatar mdj33 Committed by vipwzw

parachain improve

parent 404beadc
...@@ -211,7 +211,7 @@ ForkEnableParaRegExec=0 ...@@ -211,7 +211,7 @@ ForkEnableParaRegExec=0
ForkCacheDriver=0 ForkCacheDriver=0
ForkTicketFundAddrV1=-1 #fork6.3 ForkTicketFundAddrV1=-1 #fork6.3
#主链和平行链都使用同一个fork高度 #主链和平行链都使用同一个fork高度
ForkRootHash= 4500000 ForkRootHash=7000000
[fork.sub.coins] [fork.sub.coins]
Enable=0 Enable=0
...@@ -254,7 +254,7 @@ Enable=0 ...@@ -254,7 +254,7 @@ Enable=0
ForkParacrossWithdrawFromParachain=0 ForkParacrossWithdrawFromParachain=0
ForkParacrossCommitTx=0 ForkParacrossCommitTx=0
ForkLoopCheckCommitTxDone=0 ForkLoopCheckCommitTxDone=0
#平行链分阶段自共识支持合约配置,缺省是0 #仅平行链适用,自共识分阶段开启,缺省是0,若对应主链高度7000000之前开启过自共识,需要重新配置此分叉,并为之前自共识设置selfConsensEnablePreContract配置项
ForkParaSelfConsStages=0 ForkParaSelfConsStages=0
ForkParaAssetTransferRbk=0 ForkParaAssetTransferRbk=0
......
...@@ -91,7 +91,7 @@ type subConfig struct { ...@@ -91,7 +91,7 @@ type subConfig struct {
MultiDownJobBuffNum uint32 `json:"multiDownJobBuffNum,omitempty"` MultiDownJobBuffNum uint32 `json:"multiDownJobBuffNum,omitempty"`
MultiDownServerRspTime uint32 `json:"multiDownServerRspTime,omitempty"` MultiDownServerRspTime uint32 `json:"multiDownServerRspTime,omitempty"`
RmCommitParamMainHeight int64 `json:"rmCommitParamMainHeight,omitempty"` RmCommitParamMainHeight int64 `json:"rmCommitParamMainHeight,omitempty"`
JumpDownloadOpen bool `json:"jumpDownloadOpen,omitempty"` JumpDownloadClose bool `json:"jumpDownloadClose,omitempty"`
} }
// New function to init paracross env // New function to init paracross env
......
...@@ -497,7 +497,7 @@ func (client *client) procLocalAddBlocks(mainBlocks *types.ParaTxDetails) error ...@@ -497,7 +497,7 @@ func (client *client) procLocalAddBlocks(mainBlocks *types.ParaTxDetails) error
func (client *client) CreateBlock() { func (client *client) CreateBlock() {
defer client.wg.Done() defer client.wg.Done()
if client.subCfg.JumpDownloadOpen { if client.subCfg.JumpDownloadClose {
client.jumpDldCli.tryJumpDownload() client.jumpDldCli.tryJumpDownload()
} }
......
...@@ -256,7 +256,6 @@ func addCreateCrossAssetTransferFlags(cmd *cobra.Command) { ...@@ -256,7 +256,6 @@ func addCreateCrossAssetTransferFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("symbol") cmd.MarkFlagRequired("symbol")
cmd.Flags().StringP("to", "t", "", "transfer to account") cmd.Flags().StringP("to", "t", "", "transfer to account")
cmd.MarkFlagRequired("to")
cmd.Flags().Float64P("amount", "a", 0, "transaction amount") cmd.Flags().Float64P("amount", "a", 0, "transaction amount")
cmd.MarkFlagRequired("amount") cmd.MarkFlagRequired("amount")
......
...@@ -1007,30 +1007,38 @@ func (a *action) execCrossTxs(status *pt.ParacrossNodeStatus) (*types.Receipt, e ...@@ -1007,30 +1007,38 @@ func (a *action) execCrossTxs(status *pt.ParacrossNodeStatus) (*types.Receipt, e
return &receipt, nil return &receipt, nil
} }
func (a *action) assetTransferMainCheck(cfg *types.Chain33Config) error {
//主链如果没有nodegroup配置,也不允许跨链,直接返回错误,平行链也不会执行
if cfg.IsDappFork(a.height, pt.ParaX, pt.ForkParaAssetTransferRbk) {
return a.isAllowTransfer()
}
return nil
}
func (a *action) AssetTransfer(transfer *types.AssetsTransfer) (*types.Receipt, error) { func (a *action) AssetTransfer(transfer *types.AssetsTransfer) (*types.Receipt, error) {
clog.Debug("Paracross.Exec", "AssetTransfer", transfer.Cointoken, "transfer", "") clog.Debug("Paracross.Exec", "AssetTransfer", transfer.Cointoken, "transfer", "")
cfg := a.api.GetConfig()
isPara := cfg.IsPara()
//rbk fork后 如果没有nodegroup conf,也不允许跨链 //主链如果没有nodegroup配置,也不允许跨链,直接返回错误,平行链也不会执行
if a.api.GetConfig().IsDappFork(a.height, pt.ParaX, pt.ForkParaAssetTransferRbk) { if !isPara {
err := a.isAllowTransfer() err := a.assetTransferMainCheck(cfg)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "AssetTransfer not allow") return nil, errors.Wrap(err, "AssetTransfer check")
} }
} }
receipt, err := a.assetTransfer(transfer) receipt, err := a.assetTransfer(transfer)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "AssetTransfer failed") return nil, errors.Wrap(err, "AssetTransfer")
} }
return receipt, nil return receipt, nil
} }
func (a *action) AssetWithdraw(withdraw *types.AssetsWithdraw) (*types.Receipt, error) { func (a *action) assetWithdrawMainCheck(cfg *types.Chain33Config, withdraw *types.AssetsWithdraw) error {
//分叉高度之后,支持从平行链提取资产
cfg := a.api.GetConfig()
if !cfg.IsDappFork(a.height, pt.ParaX, "ForkParacrossWithdrawFromParachain") { if !cfg.IsDappFork(a.height, pt.ParaX, "ForkParacrossWithdrawFromParachain") {
if withdraw.Cointoken != "" { if withdraw.Cointoken != "" {
return nil, types.ErrNotSupport return errors.Wrapf(types.ErrNotSupport, "not support,token=%s", withdraw.Cointoken)
} }
} }
...@@ -1038,12 +1046,24 @@ func (a *action) AssetWithdraw(withdraw *types.AssetsWithdraw) (*types.Receipt, ...@@ -1038,12 +1046,24 @@ func (a *action) AssetWithdraw(withdraw *types.AssetsWithdraw) (*types.Receipt,
if cfg.IsDappFork(a.height, pt.ParaX, pt.ForkParaAssetTransferRbk) { if cfg.IsDappFork(a.height, pt.ParaX, pt.ForkParaAssetTransferRbk) {
err := a.isAllowTransfer() err := a.isAllowTransfer()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "AssetTransfer not allow") return errors.Wrap(err, "AssetWithdraw not allow")
} }
} }
return nil
}
func (a *action) AssetWithdraw(withdraw *types.AssetsWithdraw) (*types.Receipt, error) {
//分叉高度之后,支持从平行链提取资产
cfg := a.api.GetConfig()
isPara := cfg.IsPara() isPara := cfg.IsPara()
if !isPara { if !isPara {
err := a.assetWithdrawMainCheck(cfg, withdraw)
if err != nil {
return nil, err
}
}
if !isPara {
// 需要平行链先执行, 达成共识时,继续执行 // 需要平行链先执行, 达成共识时,继续执行
return nil, nil return nil, nil
} }
...@@ -1056,27 +1076,42 @@ func (a *action) AssetWithdraw(withdraw *types.AssetsWithdraw) (*types.Receipt, ...@@ -1056,27 +1076,42 @@ func (a *action) AssetWithdraw(withdraw *types.AssetsWithdraw) (*types.Receipt,
return receipt, nil return receipt, nil
} }
func (a *action) CrossAssetTransfer(transfer *pt.CrossAssetTransfer) (*types.Receipt, error) { func (a *action) crossAssetTransferMainCheck(transfer *pt.CrossAssetTransfer) error {
clog.Debug("Paracross.CrossAssetTransfer", "exec", transfer.AssetExec, "symbol", transfer.AssetSymbol)
cfg := a.api.GetConfig()
isPara := cfg.IsPara()
err := a.isAllowTransfer() err := a.isAllowTransfer()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "CrossAssetTransfer not Allow") return errors.Wrap(err, "not Allow")
} }
if len(transfer.AssetExec) == 0 || len(transfer.AssetSymbol) == 0 || transfer.Amount == 0 { if len(transfer.AssetExec) == 0 || len(transfer.AssetSymbol) == 0 || transfer.Amount == 0 {
return nil, errors.Wrapf(types.ErrInvalidParam, "CrossAssetTransfer exec=%s, symbol=%s, amount=%d should not be null", return errors.Wrapf(types.ErrInvalidParam, "exec=%s, symbol=%s, amount=%d should not be null",
transfer.AssetExec, transfer.AssetSymbol, transfer.Amount) transfer.AssetExec, transfer.AssetSymbol, transfer.Amount)
} }
return nil
}
func (a *action) CrossAssetTransfer(transfer *pt.CrossAssetTransfer) (*types.Receipt, error) {
cfg := a.api.GetConfig()
isPara := cfg.IsPara()
//主链检查参数
if !isPara {
err := a.crossAssetTransferMainCheck(transfer)
if err != nil {
return nil, err
}
}
//平行链在ForkRootHash之前不支持crossAssetTransfer
if isPara && !cfg.IsFork(a.exec.GetMainHeight(), "ForkRootHash") {
return nil, errors.Wrap(types.ErrNotSupport, "not Allow before ForkRootHash")
}
if len(transfer.ToAddr) == 0 { if len(transfer.ToAddr) == 0 {
transfer.ToAddr = a.tx.From() transfer.ToAddr = a.tx.From()
} }
act, err := getCrossAction(transfer, string(a.tx.Execer)) act, err := getCrossAction(transfer, string(a.tx.Execer))
if act == pt.ParacrossNoneTransfer { if act == pt.ParacrossNoneTransfer {
return nil, errors.Wrap(err, "CrossAssetTransfer non action") return nil, errors.Wrap(err, "non action")
} }
// 需要平行链先执行, 达成共识时,继续执行 // 需要平行链先执行, 达成共识时,继续执行
if !isPara && (act == pt.ParacrossMainAssetWithdraw || act == pt.ParacrossParaAssetTransfer) { if !isPara && (act == pt.ParacrossMainAssetWithdraw || act == pt.ParacrossParaAssetTransfer) {
...@@ -1158,16 +1193,16 @@ func getTitleFrom(exec []byte) ([]byte, error) { ...@@ -1158,16 +1193,16 @@ func getTitleFrom(exec []byte) ([]byte, error) {
func (a *action) isAllowTransfer() error { func (a *action) isAllowTransfer() error {
//1. 没有配置nodegroup 不允许 //1. 没有配置nodegroup 不允许
tit, err := getTitleFrom(a.tx.Execer) tempTitle, err := getTitleFrom(a.tx.Execer)
if err != nil { if err != nil {
return errors.Wrapf(types.ErrInvalidParam, "CrossAssetTransfer, not para chain exec=%s", string(a.tx.Execer)) return errors.Wrapf(types.ErrInvalidParam, "not para chain exec=%s", string(a.tx.Execer))
} }
nodes, err := a.getNodesGroup(string(tit)) nodes, err := a.getNodesGroup(string(tempTitle))
if err != nil { if err != nil {
return errors.Wrapf(err, "CrossAssetTransfer get nodegroup err,title=%s", tit) return errors.Wrapf(err, "nodegroup not config,title=%s", tempTitle)
} }
if len(nodes) == 0 { if len(nodes) == 0 {
return errors.Wrapf(err, "CrossAssetTransfer nodegroup not create,title=%s", tit) return errors.Wrapf(types.ErrNotSupport, "nodegroup not create,title=%s", tempTitle)
} }
//2. 非跨链执行器不允许 //2. 非跨链执行器不允许
if !types.IsParaExecName(string(a.tx.Execer)) { if !types.IsParaExecName(string(a.tx.Execer)) {
......
...@@ -35,7 +35,7 @@ func (e *Paracross) Exec_AssetTransfer(payload *types.AssetsTransfer, tx *types. ...@@ -35,7 +35,7 @@ func (e *Paracross) Exec_AssetTransfer(payload *types.AssetsTransfer, tx *types.
receipt, err := a.AssetTransfer(payload) receipt, err := a.AssetTransfer(payload)
if err != nil { if err != nil {
clog.Error("Paracross AssetTransfer failed", "error", err, "hash", hex.EncodeToString(tx.Hash())) clog.Error("Paracross AssetTransfer failed", "error", err, "hash", hex.EncodeToString(tx.Hash()))
return nil, errors.Cause(err) return nil, err
} }
return receipt, nil return receipt, nil
} }
...@@ -51,7 +51,7 @@ func (e *Paracross) Exec_AssetWithdraw(payload *types.AssetsWithdraw, tx *types. ...@@ -51,7 +51,7 @@ func (e *Paracross) Exec_AssetWithdraw(payload *types.AssetsWithdraw, tx *types.
receipt, err := a.AssetWithdraw(payload) receipt, err := a.AssetWithdraw(payload)
if err != nil { if err != nil {
clog.Error("ParacrossActionAssetWithdraw failed", "error", err, "hash", hex.EncodeToString(tx.Hash())) clog.Error("ParacrossActionAssetWithdraw failed", "error", err, "hash", hex.EncodeToString(tx.Hash()))
return nil, errors.Cause(err) return nil, err
} }
return receipt, nil return receipt, nil
} }
......
...@@ -328,6 +328,8 @@ func (c *Paracross) allow(tx *types.Transaction, index int) error { ...@@ -328,6 +328,8 @@ func (c *Paracross) allow(tx *types.Transaction, index int) error {
if payload.Ty == pt.ParacrossActionAssetTransfer || payload.Ty == pt.ParacrossActionAssetWithdraw { if payload.Ty == pt.ParacrossActionAssetTransfer || payload.Ty == pt.ParacrossActionAssetWithdraw {
return nil return nil
} }
//对一些跨链的新feature,主链分叉之前不允许执行,但会走none执行器,因为分叉之前的版本就是走none执行器
//然后会被过滤到平行链,最好在分叉前控制主链不发送相关交易,要么设置系统统一的fork比如ForkRootHash,主链和平行链都可以阻止执行,
if cfg.IsDappFork(c.GetHeight(), pt.ParaX, pt.ForkCommitTx) { if cfg.IsDappFork(c.GetHeight(), pt.ParaX, pt.ForkCommitTx) {
if payload.Ty == pt.ParacrossActionCommit || payload.Ty == pt.ParacrossActionNodeConfig || if payload.Ty == pt.ParacrossActionCommit || payload.Ty == pt.ParacrossActionNodeConfig ||
payload.Ty == pt.ParacrossActionNodeGroupApply { payload.Ty == pt.ParacrossActionNodeGroupApply {
......
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