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

add hit key and ignore key

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