Commit 38ab5f3a authored by mdj33's avatar mdj33 Committed by vipwzw

add hit key and ignore key

parent cedafbe9
...@@ -273,9 +273,10 @@ superManager=[ ...@@ -273,9 +273,10 @@ superManager=[
nodeGroupFrozenCoins=0 nodeGroupFrozenCoins=0
#平行链共识停止后主链等待的高度 #平行链共识停止后主链等待的高度
paraConsensusStopBlocks=30000 paraConsensusStopBlocks=30000
#配置平行链无资产跨链交易的高度列表,title不用加user.p,不同title使用#分割,不同高度序列使用.分割,高度为平行链自身的高度,不是主链高度 #配置平行链资产跨链交易的高度列表,title省略user.p,不同title使用,分割,不同hit高度使用"."分割,
#mc.10-100.200-300#guodun.50-60.300-400#game.10-50.70-90 #不同ignore范围高度使用"-"分割,hit高度在ignore范围内,为平行链自身的高度,不是主链高度
paraNoCrossAssetHeightList="" #para.hit.10.50.250, para.ignore.1-100.200-300
paraCrossAssetTxHeightList=[]
[exec.sub.autonomy] [exec.sub.autonomy]
total="16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp" total="16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
......
...@@ -7,6 +7,8 @@ package commands ...@@ -7,6 +7,8 @@ package commands
import ( import (
"strings" "strings"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/33cn/chain33/common/address" "github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
) )
...@@ -23,7 +25,7 @@ func GetExecAddr(exec string) (string, error) { ...@@ -23,7 +25,7 @@ func GetExecAddr(exec string) (string, error) {
} }
func getRealExecName(paraName string, name string) string { func getRealExecName(paraName string, name string) string {
if strings.HasPrefix(name, "user.p.") { if strings.HasPrefix(name, pt.ParaPrefix) {
return name return name
} }
return paraName + name return paraName + name
......
...@@ -7,6 +7,8 @@ package commands ...@@ -7,6 +7,8 @@ package commands
import ( import (
"strings" "strings"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/33cn/chain33/common/address" "github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
) )
...@@ -23,7 +25,7 @@ func GetExecAddr(exec string) (string, error) { ...@@ -23,7 +25,7 @@ func GetExecAddr(exec string) (string, error) {
} }
func getRealExecName(paraName string, name string) string { func getRealExecName(paraName string, name string) string {
if strings.HasPrefix(name, "user.p.") { if strings.HasPrefix(name, pt.ParaPrefix) {
return name return name
} }
return paraName + name return paraName + name
......
...@@ -983,32 +983,38 @@ func rollbackCrossTx(a *action, cross *types.TransactionDetail, crossTxHash []by ...@@ -983,32 +983,38 @@ func rollbackCrossTx(a *action, cross *types.TransactionDetail, crossTxHash []by
} }
//无跨链交易高度列表是人为配置的,是确认的历史高度,是一种特殊处理,不会影响区块状态hash //无跨链交易高度列表是人为配置的,是确认的历史高度,是一种特殊处理,不会影响区块状态hash
//mc.10-100.200-300#guodun.50-60.300-400#game.10-50.70-90 //para.ignore.10-100.200-300
func isInNoHeightCrossAsseList(list string, status *pt.ParacrossNodeStatus) (bool, error) { func isInIgnoreHeightList(str string, status *pt.ParacrossNodeStatus) (bool, error) {
paraChains := strings.Split(list, "#") if len(str) <= 0 {
for _, chain := range paraChains { return false, nil
paras := strings.Split(chain, ".") }
//compare title e := strings.Split(str, ".")
if strings.ToLower("user.p."+paras[0]+".") != strings.ToLower(status.Title) { if len(e) <= 2 {
continue return false, errors.Wrapf(types.ErrInvalidParam, "wrong config str=%s,title=%s", str, status.Title)
}
if strings.ToLower("user.p."+e[0]+".") != strings.ToLower(status.Title) {
return false, errors.Wrapf(types.ErrInvalidParam, "wrong title str=%s,title=%s", str, status.Title)
}
if e[1] != pt.ParaCrossAssetTxIgnoreKey {
return false, errors.Wrapf(types.ErrInvalidParam, "wrong ignore str=%s,title=%s", str, status.Title)
} }
//check para height
heights := paras[1:] for _, h := range e[2:] {
for _, h := range heights {
p := strings.Split(h, "-") p := strings.Split(h, "-")
if len(p) != 2 { if len(p) != 2 {
return false, errors.Wrapf(types.ErrInvalidParam, "check NoHeightCrossAsseList title=%s,height=%s", chain, h) return false, errors.Wrapf(types.ErrInvalidParam, "check NoHeightCrossAsseList title=%s,height=%s", status.Title, h)
} }
s, err := strconv.Atoi(p[0]) s, err := strconv.Atoi(p[0])
if err != nil { if err != nil {
return false, errors.Wrapf(err, "check NoHeightCrossAsseList title=%s,height=%s", chain, h) return false, errors.Wrapf(err, "check NoHeightCrossAsseList title=%s,height=%s", status.Title, h)
} }
e, err := strconv.Atoi(p[1]) e, err := strconv.Atoi(p[1])
if err != nil { if err != nil {
return false, errors.Wrapf(err, "check NoHeightCrossAsseList title=%s,height=%s", chain, h) return false, errors.Wrapf(err, "check NoHeightCrossAsseList title=%s,height=%s", status.Title, h)
} }
if s > e { if s > e {
return false, errors.Wrapf(types.ErrInvalidParam, "check NoHeightCrossAsseList title=%s,height=%s", chain, h) return false, errors.Wrapf(types.ErrInvalidParam, "check NoHeightCrossAsseList title=%s,height=%s", status.Title, h)
} }
//共识的平行链高度(不是主链高度)落在范围内,说明此高度没有跨链资产交易,可以忽略 //共识的平行链高度(不是主链高度)落在范围内,说明此高度没有跨链资产交易,可以忽略
...@@ -1016,27 +1022,81 @@ func isInNoHeightCrossAsseList(list string, status *pt.ParacrossNodeStatus) (boo ...@@ -1016,27 +1022,81 @@ func isInNoHeightCrossAsseList(list string, status *pt.ParacrossNodeStatus) (boo
return true, nil return true, nil
} }
} }
return false, nil
}
// "para.hit.10.100.200"
func isInHitHeightList(str string, status *pt.ParacrossNodeStatus) (bool, error) {
if len(str) <= 0 {
return false, nil
}
e := strings.Split(str, ".")
if len(e) <= 2 {
return false, errors.Wrapf(types.ErrInvalidParam, "wrong config str=%s,title=%s", str, status.Title)
}
if strings.ToLower("user.p."+e[0]+".") != strings.ToLower(status.Title) {
return false, errors.Wrapf(types.ErrInvalidParam, "wrong title str=%s,title=%s", str, status.Title)
}
if e[1] != pt.ParaCrossAssetTxHitKey {
return false, errors.Wrapf(types.ErrInvalidParam, "wrong hit str=%s,title=%s", str, status.Title)
}
for _, hStr := range e[2:] {
h, err := strconv.Atoi(hStr)
if err != nil {
return false, errors.Wrapf(types.ErrInvalidParam, "wrong config str=%s in %s,title=%s", str, hStr, status.Title)
}
//高度命中
if status.Height == int64(h) {
return true, nil
}
} }
return false, nil return false, nil
} }
func checkIsInIgnoreHeightList(api client.QueueProtocolAPI, status *pt.ParacrossNodeStatus) (bool, error) { //命中高度
conf := types.ConfSub(api.GetConfig(), pt.ParaX) //s: para.hit.10.100, title=user.p.para.
heightListStr := conf.GStr("paraNoCrossAssetHeightList") func checkIsIgnoreHeight(heightList []string, status *pt.ParacrossNodeStatus) (bool, error) {
if len(heightListStr) > 0 { if len(heightList) <= 0 {
in, err := isInNoHeightCrossAsseList(heightListStr, status) return false, nil
}
var hitStr, ignoreStr string
hitPrefix := strings.ToLower(status.Title + pt.ParaCrossAssetTxHitKey)
ignorePrefix := strings.ToLower(status.Title + pt.ParaCrossAssetTxIgnoreKey)
for _, s := range heightList {
desStr := pt.ParaPrefix + strings.ToLower(s)
if strings.HasPrefix(desStr, hitPrefix) {
if len(hitStr) > 0 {
return false, errors.Wrapf(types.ErrInvalidParam, "checkIsInIgnoreHeightList repeate=%s", hitPrefix)
}
hitStr = s
}
if strings.HasPrefix(desStr, ignorePrefix) {
if len(ignoreStr) > 0 {
return false, errors.Wrapf(types.ErrInvalidParam, "checkIsInIgnoreHeightList repeate=%s", ignorePrefix)
}
ignoreStr = s
}
if len(hitStr) > 0 && len(ignoreStr) > 0 {
break
}
}
in, err := isInHitHeightList(hitStr, status)
if err != nil { if err != nil {
clog.Error("getCrossTxHashs decode NoHeightCrossAsseList", "err", err)
return false, err return false, err
} }
//在配置的无资产跨链高度列表中,则直接退出 //如果在hit 列表中,不忽略
if in { if in {
clog.Debug("getCrossTxHashs NoHeightCrossAsseList", "str", heightListStr, "height", status.Height, "title", status.Title)
return true, nil
}
}
return false, nil return false, nil
}
return isInIgnoreHeightList(ignoreStr, status)
} }
func getCrossTxHashsByRst(api client.QueueProtocolAPI, status *pt.ParacrossNodeStatus) ([][]byte, []byte, error) { func getCrossTxHashsByRst(api client.QueueProtocolAPI, status *pt.ParacrossNodeStatus) ([][]byte, []byte, error) {
...@@ -1059,8 +1119,12 @@ func getCrossTxHashsByRst(api client.QueueProtocolAPI, status *pt.ParacrossNodeS ...@@ -1059,8 +1119,12 @@ func getCrossTxHashsByRst(api client.QueueProtocolAPI, status *pt.ParacrossNodeS
} }
} }
//para.hit.6.8, para.ignore.1-10, 比如高度7, 如果命中则继续处理,如果没命中,检查是否在ignore列表,如果在直接退出,否则继续处理
//零散的命中列表可以减少忽略高度列表的范围
//此平行链高度在忽略检查跨链交易列表中,则直接退出 //此平行链高度在忽略检查跨链交易列表中,则直接退出
ignore, err := checkIsInIgnoreHeightList(api, status) conf := types.ConfSub(api.GetConfig(), pt.ParaX)
heightList := conf.GStrList("paraCrossAssetTxHeightList")
ignore, err := checkIsIgnoreHeight(heightList, status)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
...@@ -1100,8 +1164,12 @@ func getCrossTxHashs(api client.QueueProtocolAPI, status *pt.ParacrossNodeStatus ...@@ -1100,8 +1164,12 @@ func getCrossTxHashs(api client.QueueProtocolAPI, status *pt.ParacrossNodeStatus
return nil, nil, types.ErrCheckTxHash return nil, nil, types.ErrCheckTxHash
} }
//此平行链高度在忽略检查跨链交易列表中,则直接退出 //para.hit.6.8, para.ignore.1-10, 比如高度7, 如果命中则继续处理,如果没命中,检查是否在ignore列表,如果在直接退出,否则继续处理
ignore, err := checkIsInIgnoreHeightList(api, status) //零散的命中列表可以减少忽略高度列表的范围
//比如高度6,命中,则继续处理,高度7,未命中,但是在ignore scope,退出,高度11,未命中,也不在ignore scope,继续处理
conf := types.ConfSub(api.GetConfig(), pt.ParaX)
heightList := conf.GStrList("paraCrossAssetTxHeightList")
ignore, err := checkIsIgnoreHeight(heightList, status)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
......
...@@ -878,69 +878,44 @@ func TestVerifyBlsSign(t *testing.T) { ...@@ -878,69 +878,44 @@ func TestVerifyBlsSign(t *testing.T) {
} }
func TestIsInNoHeightCrossAsseList(t *testing.T) { func TestCheckIsIgnoreHeight(t *testing.T) {
status1 := &pt.ParacrossNodeStatus{ status1 := &pt.ParacrossNodeStatus{
Title: "user.p.mc.", Title: "user.p.mc.",
Height: 1000, Height: 1000,
} }
str := "mc.10-100" strList := []string{"mcc.hit.260", "mc.hit.7.9.250", "mc.ignore.1-100.200-300"}
isIn, err := isInNoHeightCrossAsseList(str, status1) isIn, err := checkIsIgnoreHeight(strList, status1)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, false, isIn) assert.Equal(t, false, isIn)
status1.Height = 100 status1.Height = 9
isIn, err = isInNoHeightCrossAsseList(str, status1) isIn, err = checkIsIgnoreHeight(strList, status1)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, true, isIn) assert.Equal(t, false, isIn)
status1.Height = 250
str = "mc.10-100.200-300#guodun.50-60.300-400" isIn, err = checkIsIgnoreHeight(strList, status1)
status1.Height = 200
isIn, err = isInNoHeightCrossAsseList(str, status1)
assert.Nil(t, err)
assert.Equal(t, true, isIn)
status1.Title = "user.p.guodun."
status1.Height = 61
isIn, err = isInNoHeightCrossAsseList(str, status1)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, false, isIn) assert.Equal(t, false, isIn)
status1.Height = 60 status1.Height = 1
isIn, err = isInNoHeightCrossAsseList(str, status1) isIn, err = checkIsIgnoreHeight(strList, status1)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, true, isIn) assert.Equal(t, true, isIn)
str = "mc.10-100.200-300#guodun.50-60.300-400#guo.80-90.300-400" status1.Height = 10
status1.Title = "user.p.Guo." isIn, err = checkIsIgnoreHeight(strList, status1)
status1.Height = 60
isIn, err = isInNoHeightCrossAsseList(str, status1)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, false, isIn) assert.Equal(t, true, isIn)
status1.Height = 300 status1.Height = 251
isIn, err = isInNoHeightCrossAsseList(str, status1) isIn, err = checkIsIgnoreHeight(strList, status1)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, true, isIn) assert.Equal(t, true, isIn)
//异常情况 //mc和mcc不能混淆
str = "mc.10-100.200-300#guodun.50-60.300-400#guo.80.300-400" status1.Height = 260
status1.Title = "user.p.Guo." isIn, err = checkIsIgnoreHeight(strList, status1)
status1.Height = 300
isIn, err = isInNoHeightCrossAsseList(str, status1)
assert.NotNil(t, err)
assert.Equal(t, false, isIn)
str = "mc.10-100.200-300#guodun.50-60.300-400#guo"
status1.Title = "user.p.Guo."
status1.Height = 300
isIn, err = isInNoHeightCrossAsseList(str, status1)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, false, isIn) assert.Equal(t, true, isIn)
str = "mc.10-100.200-300#guodun.50-60.300-400#"
status1.Title = "user.p.Guo."
status1.Height = 300
isIn, err = isInNoHeightCrossAsseList(str, status1)
assert.Nil(t, err)
assert.Equal(t, false, isIn)
} }
...@@ -99,6 +99,14 @@ const ( ...@@ -99,6 +99,14 @@ const (
ParaCrossStatusBitMapVer1 = "0001" ParaCrossStatusBitMapVer1 = "0001"
) )
const ParaPrefix = "user.p."
//配置跨链交易高度列表的prefix 比如hit.para.100.200,ignore.para.100-300
const (
ParaCrossAssetTxHitKey = "hit"
ParaCrossAssetTxIgnoreKey = "ignore"
)
//paracross asset porcess //paracross asset porcess
const ( const (
ParacrossNoneTransfer = iota ParacrossNoneTransfer = iota
......
...@@ -7,6 +7,8 @@ package commands ...@@ -7,6 +7,8 @@ package commands
import ( import (
"strings" "strings"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/33cn/chain33/common/address" "github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
) )
...@@ -23,7 +25,7 @@ func GetExecAddr(exec string) (string, error) { ...@@ -23,7 +25,7 @@ func GetExecAddr(exec string) (string, error) {
} }
func getRealExecName(paraName string, name string) string { func getRealExecName(paraName string, name string) string {
if strings.HasPrefix(name, "user.p.") { if strings.HasPrefix(name, pt.ParaPrefix) {
return name return name
} }
return paraName + name return paraName + name
......
...@@ -11,6 +11,8 @@ import ( ...@@ -11,6 +11,8 @@ import (
"os" "os"
"strings" "strings"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
cmdtypes "github.com/33cn/chain33/system/dapp/commands/types" cmdtypes "github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors" "github.com/pkg/errors"
...@@ -355,7 +357,7 @@ func show(cmd *cobra.Command, args []string) { ...@@ -355,7 +357,7 @@ func show(cmd *cobra.Command, args []string) {
} }
func getRealExecName(paraName string, name string) string { func getRealExecName(paraName string, name string) string {
if strings.HasPrefix(name, "user.p.") { if strings.HasPrefix(name, pt.ParaPrefix) {
return name return name
} }
return paraName + name return paraName + name
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment