Commit 0409f6d5 authored by mdj33's avatar mdj33 Committed by vipwzw

add para chain exec check

parent 83a7a649
......@@ -39,7 +39,7 @@ function para_set_toml() {
cp chain33.para.toml "${1}"
local paraname="$2"
sed -i $xsedfix 's/^Title.*/Title="user.p.'''$paraname'''."/g' "${1}"
sed -i $xsedfix 's/^Title.*/Title="user.p.'''"$paraname"'''."/g' "${1}"
sed -i $xsedfix 's/^# TestNet=.*/TestNet=true/g' "${1}"
sed -i $xsedfix 's/^startHeight=.*/startHeight=1/g' "${1}"
sed -i $xsedfix 's/^interval=.*/interval=4/g' "${1}"
......@@ -101,9 +101,7 @@ function para_set_wallet() {
para_import_key "${PARA_CLI}" "0x794443611e7369a57b078881445b93b754cbc9b9b8f526535ab9c6d21d29203d" "othernode2"
#cross_transfer
#14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
# para_import_key "${PARA_CLI5}" "0xCC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944" "genesis"
#1KS
#1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4
para_import_wallet "${PARA_CLI5}" "0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b" "paraAuthAccount"
#1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu
para_import_key "${PARA_CLI5}" "0x128de4afa7c061c00d854a1bca51b58e80a2c292583739e5aebf4c0f778959e1" "cross_transfer"
......@@ -910,7 +908,7 @@ function para_nodemanage_node_behalf_join() {
node1_id=$hash
balance=$(${CLI} account balance -a 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj -e paracross | jq -r ".frozen")
if [ "$balance" != "32.0000" ]; then
if [ "$balance" != "37.0000" ]; then
echo "1Ka frozen coinfrozen error balance=$balance"
exit 1
fi
......@@ -928,7 +926,7 @@ function para_nodemanage_node_behalf_join() {
id=$hash
balance=$(${CLI} account balance -a 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj -e paracross | jq -r ".frozen")
if [ "$balance" != "41.0000" ]; then
if [ "$balance" != "46.0000" ]; then
echo "frozen coinfrozen error balance=$balance"
exit 1
fi
......@@ -979,7 +977,7 @@ function para_nodemanage_node_behalf_join() {
query_tx "${PARA_CLI}" "${hash}"
balance=$(${CLI} account balance -a 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj -e paracross | jq -r ".frozen")
if [ "$balance" != "33.0000" ]; then
if [ "$balance" != "38.0000" ]; then
echo "unfrozen coinfrozen error balance=$balance"
exit 1
fi
......@@ -1005,7 +1003,7 @@ function para_nodemanage_node_behalf_join() {
query_tx "${PARA_CLI}" "${hash}"
balance=$(${CLI} account balance -a 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj -e paracross | jq -r ".frozen")
if [ "$balance" != "24.0000" ]; then
if [ "$balance" != "29.0000" ]; then
echo "unfrozen coinfrozen error balance=$balance"
exit 1
fi
......@@ -1084,7 +1082,6 @@ function privacy_transfer_test() {
function para_test() {
echo "=========== # para chain test ============="
# block_wait2height "${PARA_CLI}" $MainLoopCheckForkHeight "1"
para_create_nodegroup
para_nodegroup_behalf_quit_test
para_create_nodegroup_gamechain
......
......@@ -382,7 +382,7 @@ paracross_testSelfConsensStages() {
chainheight=$(jq '(.result.chainHeight)' <<<"$resp")
newHeight=$((chainheight + 2000))
echo "apply stage startHeight=$newHeight"
req='"method":"Chain33.CreateTransaction","params":[{"execer" : "user.p.para.paracross","actionName" : "selfConsStageConfig","payload" : {"title":"user.p.para.","op" : "1", "stage" : {"startHeight":'"$newHeight"',"enable":2} }}]'
req='"method":"Chain33.CreateTransaction","params":[{"execer" : "user.p.para.paracross","actionName" : "SelfStageConfig","payload" : {"title":"user.p.para.","op" : "1", "stage" : {"startHeight":'"$newHeight"',"enable":2} }}]'
resp=$(curl -ksd "{$req}" "${para_ip}")
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignAndSendTx "$rawtx" "$para_test_prikey" "${para_ip}"
......@@ -402,7 +402,7 @@ paracross_testSelfConsensStages() {
JR_PRI="0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4"
NL_PRI="0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115"
req='"method":"Chain33.CreateTransaction","params":[{"execer" : "user.p.para.paracross","actionName" : "selfConsStageConfig","payload":{"title":"user.p.para.","op":"2","vote":{"id":"'"$id"'","value":1} }}]'
req='"method":"Chain33.CreateTransaction","params":[{"execer" : "user.p.para.paracross","actionName" : "SelfStageConfig","payload":{"title":"user.p.para.","op":"2","vote":{"id":"'"$id"'","value":1} }}]'
resp=$(curl -ksd "{$req}" "${para_ip}")
rawtx=$(jq -r ".result" <<<"$resp")
echo "send vote 1"
......
......@@ -596,12 +596,12 @@ func selfConsStage(cmd *cobra.Command, args []string) {
var config pt.ParaStageConfig
config.Title = paraName
config.Op = pt.ParaOpNewApply
config.Ty = pt.ParaOpNewApply
config.Value = &pt.ParaStageConfig_Stage{Stage: &pt.SelfConsensStage{StartHeight: height, Enable: enable}}
params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "selfConsStageConfig",
ActionName: "SelfStageConfig",
Payload: types.MustPBToJSON(&config),
}
......@@ -635,12 +635,12 @@ func createVoteTx(cmd *cobra.Command, args []string) {
var config pt.ParaStageConfig
config.Title = paraName
config.Op = pt.ParaOpVote
config.Ty = pt.ParaOpVote
config.Value = &pt.ParaStageConfig_Vote{Vote: &pt.ConfigVoteInfo{Id: id, Value: val}}
params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "selfConsStageConfig",
ActionName: "SelfStageConfig",
Payload: types.MustPBToJSON(&config),
}
......@@ -666,12 +666,12 @@ func stageCancelTx(cmd *cobra.Command, args []string) {
var config pt.ParaStageConfig
config.Title = paraName
config.Op = pt.ParaOpCancel
config.Ty = pt.ParaOpCancel
config.Value = &pt.ParaStageConfig_Cancel{Cancel: &pt.ConfigCancelInfo{Id: id}}
params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "selfConsStageConfig",
ActionName: "SelfStageConfig",
Payload: types.MustPBToJSON(&config),
}
......
......@@ -1149,6 +1149,7 @@ func getTitleFrom(exec []byte) ([]byte, error) {
}
func (a *action) isAllowTransfer() error {
//1. 没有配置nodegroup 不允许
tit, err := getTitleFrom(a.tx.Execer)
if err != nil {
return errors.Wrapf(types.ErrInvalidParam, "CrossAssetTransfer, not para chain exec=%s", string(a.tx.Execer))
......@@ -1160,6 +1161,11 @@ func (a *action) isAllowTransfer() error {
if len(nodes) == 0 {
return errors.Wrapf(err, "CrossAssetTransfer nodegroup not create,title=%s", tit)
}
//2. 非跨链执行器不允许
if !types.IsParaExecName(string(a.tx.Execer)) {
return errors.Wrapf(types.ErrInvalidParam,"exec=%s,should prefix with user.p.",string(a.tx.Execer))
}
return nil
}
......
......@@ -822,3 +822,13 @@ func TestUpdateCommitBlockHashs(t *testing.T) {
assert.Equal(t, commit2.BlockHash, stat.BlockDetails.BlockHashs[1])
}
func TestValidParaCrossExec(t *testing.T){
exec := []byte("paracross")
valid := types.IsParaExecName(string(exec))
assert.Equal(t,false,valid)
exec = []byte("user.p.para.paracross")
valid = types.IsParaExecName(string(exec))
assert.Equal(t,true,valid)
}
\ No newline at end of file
......@@ -300,16 +300,15 @@ 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.Op == pt.ParaOpNewApply {
if config.Ty == pt.ParaOpNewApply {
return a.stageApply(config.GetStage())
} else if config.Op == pt.ParaOpCancel {
} else if config.Ty == pt.ParaOpCancel {
return a.stageCancel(config.GetCancel())
} else if config.Op == pt.ParaOpVote {
} else if config.Ty == pt.ParaOpVote {
return a.stageVote(config.GetVote())
}
return nil, pt.ErrParaUnSupportNodeOper
}
......@@ -990,6 +990,9 @@ func (a *action) NodeGroupConfig(config *pt.ParaNodeGroupConfig) (*types.Receipt
if !validTitle(cfg, config.Title) {
return nil, pt.ErrInvalidTitle
}
if !types.IsParaExecName(string(a.tx.Execer)) && cfg.IsDappFork(a.exec.GetMainHeight(), pt.ParaX, pt.ForkParaAssetTransferRbk) {
return nil,errors.Wrapf(types.ErrInvalidParam,"exec=%s,should prefix with user.p.",string(a.tx.Execer))
}
if config.Op == pt.ParacrossNodeGroupApply {
s := strings.Trim(config.Addrs, " ")
......@@ -1028,6 +1031,9 @@ func (a *action) NodeConfig(config *pt.ParaNodeAddrConfig) (*types.Receipt, erro
if !validTitle(cfg, config.Title) {
return nil, pt.ErrInvalidTitle
}
if !types.IsParaExecName(string(a.tx.Execer)) && cfg.IsDappFork(a.exec.GetMainHeight(), pt.ParaX, pt.ForkParaAssetTransferRbk) {
return nil,errors.Wrapf(types.ErrInvalidParam,"exec=%s,should prefix with user.p.",string(a.tx.Execer))
}
if config.Op == pt.ParaOpNewApply {
return a.nodeJoin(config)
......
......@@ -218,7 +218,7 @@ message ConfigCancelInfo {
message ParaStageConfig {
string title = 1;
// 配置类型
uint32 op = 2;
uint32 ty = 2;
oneof value {
SelfConsensStage stage = 10;
ConfigVoteInfo vote = 11;
......
......@@ -190,14 +190,6 @@ func CreateRawCommitTx4MainChain(cfg *types.Chain33Config, status *ParacrossNode
return createRawCommitTx(cfg, status, name, fee)
}
func createRawParacrossCommitTx(cfg *types.Chain33Config, parm *paracrossCommitTx) (*types.Transaction, error) {
if parm == nil {
tlog.Error("createRawParacrossCommitTx", "parm", parm)
return nil, types.ErrInvalidParam
}
return createRawCommitTx(cfg, &parm.Status, cfg.ExecName(ParaX), parm.Fee)
}
func createRawCommitTx(cfg *types.Chain33Config, status *ParacrossNodeStatus, name string, feeRate int64) (*types.Transaction, error) {
v := &ParacrossCommitAction{
Status: status,
......@@ -258,21 +250,6 @@ func CreateRawNodeGroupApplyTx(apply *ParaNodeGroupConfig) (*types.Transaction,
}
//CreateRawSelfConsStageApplyTx create raw tx for self consens stage
func CreateRawSelfConsStageApplyTx(apply *ParaStageConfig) (*types.Transaction, error) {
action := &ParacrossAction{
Ty: ParacrossActionSelfStageConfig,
Value: &ParacrossAction_SelfStageConfig{apply},
}
tx := &types.Transaction{
Payload: types.Encode(action),
}
return tx, nil
}
// CreateRawAssetTransferTx create asset transfer tx
func CreateRawAssetTransferTx(cfg *types.Chain33Config, param *types.CreateTx) (*types.Transaction, error) {
// 跨链交易需要在主链和平行链上执行, 所以应该可以在主链和平行链上构建
......@@ -354,20 +331,7 @@ func (p ParacrossType) CreateRawTransferTx(action string, param json.RawMessage)
return tx, nil
}
//CreateRawCrossAssetTransferTx create raw cross asset transfer tx
func CreateRawCrossAssetTransferTx(apply *CrossAssetTransfer) (*types.Transaction, error) {
action := &ParacrossAction{
Ty: ParacrossActionCrossAssetTransfer,
Value: &ParacrossAction_CrossAssetTransfer{apply},
}
tx := &types.Transaction{
Payload: types.Encode(action),
}
return tx, nil
}
//GetDappForkHeight get paracross dapp fork height
func GetDappForkHeight(cfg *types.Chain33Config, forkKey string) int64 {
......
......@@ -135,16 +135,8 @@ func (p *ParacrossType) GetPayload() types.Message {
// CreateTx paracross create tx by different action
func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) {
cfg := p.GetConfig()
if action == "ParacrossCommit" {
var param paracrossCommitTx
err := json.Unmarshal(message, &param)
if err != nil {
glog.Error("CreateTx", "Error", err)
return nil, types.ErrInvalidParam
}
return createRawParacrossCommitTx(cfg, &param)
} else if action == "ParacrossAssetTransfer" || action == "ParacrossAssetWithdraw" {
//保留老的ParacrossAssetTransfer接口,默认的AssetTransfer 也可以
if action == "ParacrossAssetTransfer" || action == "ParacrossAssetWithdraw" {
var param types.CreateTx
err := json.Unmarshal(message, &param)
if err != nil {
......@@ -152,46 +144,9 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
return nil, types.ErrInvalidParam
}
return CreateRawAssetTransferTx(cfg, &param)
} else if action == "ParacrossTransfer" || action == "Transfer" ||
action == "ParacrossWithdraw" || action == "Withdraw" ||
action == "ParacrossTransferToExec" || action == "TransferToExec" {
} else if action == "Transfer" || action == "Withdraw" || action == "TransferToExec" {
//transfer/withdraw/toExec 需要特殊处理主链上的tx.to场景
return p.CreateRawTransferTx(action, message)
} else if action == "CrossAssetTransfer" {
var param CrossAssetTransfer
err := types.JSONToPB(message, &param)
if err != nil {
glog.Error("CreateTx.CrossAssetTransfer", "Error", err)
return nil, types.ErrInvalidParam
}
return CreateRawCrossAssetTransferTx(&param)
} else if action == "NodeConfig" {
var param ParaNodeAddrConfig
err := types.JSONToPB(message, &param)
if err != nil {
glog.Error("CreateTx.NodeConfig", "Error", err)
return nil, types.ErrInvalidParam
}
return CreateRawNodeConfigTx(&param)
} else if action == "NodeGroupConfig" {
var param ParaNodeGroupConfig
err := types.JSONToPB(message, &param)
//err := json.Unmarshal(message, &param)
if err != nil {
glog.Error("CreateTx.NodeGroupApply", "Error", err)
return nil, types.ErrInvalidParam
}
return CreateRawNodeGroupApplyTx(&param)
} else if action == "selfConsStageConfig" {
var param ParaStageConfig
err := types.JSONToPB(message, &param)
//err := json.Unmarshal(message, &param)
if err != nil {
glog.Error("CreateTx.selfConsStageConfig", "Error", err)
return nil, types.ErrInvalidParam
}
return CreateRawSelfConsStageApplyTx(&param)
}
return nil, types.ErrNotSupport
return p.ExecTypeBase.CreateTx(action, message)
}
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