Commit 957a16f0 authored by mdj33's avatar mdj33 Committed by vipwzw

cmd improve

parent 55589cbe
...@@ -58,8 +58,7 @@ type client struct { ...@@ -58,8 +58,7 @@ type client struct {
commitMsgClient *commitMsgClient commitMsgClient *commitMsgClient
blockSyncClient *blockSyncClient blockSyncClient *blockSyncClient
multiDldCli *multiDldClient multiDldCli *multiDldClient
authAccount string minerPrivateKey crypto.PrivKey
privateKey crypto.PrivKey
wg sync.WaitGroup wg sync.WaitGroup
subCfg *subConfig subCfg *subConfig
isClosed int32 isClosed int32
...@@ -139,14 +138,14 @@ func New(cfg *types.Consensus, sub []byte) queue.Module { ...@@ -139,14 +138,14 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
para := &client{ para := &client{
BaseClient: c, BaseClient: c,
authAccount: subcfg.AuthAccount, minerPrivateKey: priKey,
privateKey: priKey,
subCfg: &subcfg, subCfg: &subcfg,
quitCreate: make(chan struct{}), quitCreate: make(chan struct{}),
} }
para.commitMsgClient = &commitMsgClient{ para.commitMsgClient = &commitMsgClient{
paraClient: para, paraClient: para,
authAccount: subcfg.AuthAccount,
waitMainBlocks: waitBlocks4CommitMsg, waitMainBlocks: waitBlocks4CommitMsg,
waitConsensStopTimes: waitConsensStopTimes, waitConsensStopTimes: waitConsensStopTimes,
consensHeight: -2, consensHeight: -2,
......
...@@ -175,7 +175,7 @@ func TestAddMinerTx(t *testing.T) { ...@@ -175,7 +175,7 @@ func TestAddMinerTx(t *testing.T) {
para := &client{BaseClient: &drivers.BaseClient{}} para := &client{BaseClient: &drivers.BaseClient{}}
para.SetAPI(api) para.SetAPI(api)
para.subCfg = new(subConfig) para.subCfg = new(subConfig)
para.privateKey = priKey para.minerPrivateKey = priKey
para.commitMsgClient = new(commitMsgClient) para.commitMsgClient = new(commitMsgClient)
para.commitMsgClient.paraClient = para para.commitMsgClient.paraClient = para
......
...@@ -53,6 +53,7 @@ type commitMsgClient struct { ...@@ -53,6 +53,7 @@ type commitMsgClient struct {
consensHeight int64 consensHeight int64
consensDoneHeight int64 consensDoneHeight int64
selfConsensError int32 //自共识比主链共识更高的异常场景,需要等待自共识<=主链共识再发送 selfConsensError int32 //自共识比主链共识更高的异常场景,需要等待自共识<=主链共识再发送
authAccount string
authAccountIn bool authAccountIn bool
isRollBack int32 isRollBack int32
checkTxCommitTimes int32 checkTxCommitTimes int32
...@@ -76,7 +77,7 @@ func (client *commitMsgClient) handler() { ...@@ -76,7 +77,7 @@ func (client *commitMsgClient) handler() {
client.paraClient.wg.Add(1) client.paraClient.wg.Add(1)
go client.getMainConsensusInfo() go client.getMainConsensusInfo()
if client.paraClient.authAccount != "" { if client.authAccount != "" {
client.paraClient.wg.Add(1) client.paraClient.wg.Add(1)
client.sendMsgCh = make(chan *types.Transaction, 1) client.sendMsgCh = make(chan *types.Transaction, 1)
go client.sendCommitMsg() go client.sendCommitMsg()
...@@ -275,7 +276,7 @@ func (client *commitMsgClient) checkAuthAccountIn() { ...@@ -275,7 +276,7 @@ func (client *commitMsgClient) checkAuthAccountIn() {
if err != nil { if err != nil {
return return
} }
authExist := strings.Contains(nodes, client.paraClient.authAccount) authExist := strings.Contains(nodes, client.authAccount)
//如果授权节点重新加入,需要从当前共识高度重新发送 //如果授权节点重新加入,需要从当前共识高度重新发送
if !client.authAccountIn && authExist { if !client.authAccountIn && authExist {
...@@ -361,7 +362,7 @@ func (client *commitMsgClient) getSendingTx(startHeight, endHeight int64) (*type ...@@ -361,7 +362,7 @@ func (client *commitMsgClient) getSendingTx(startHeight, endHeight int64) (*type
for i, msg := range sendingMsgs { for i, msg := range sendingMsgs {
plog.Debug("paracommitmsg sending", "idx", i, "height", msg.Height, "mainheight", msg.MainBlockHeight, plog.Debug("paracommitmsg sending", "idx", i, "height", msg.Height, "mainheight", msg.MainBlockHeight,
"blockhash", common.HashHex(msg.BlockHash), "mainHash", common.HashHex(msg.MainBlockHash), "blockhash", common.HashHex(msg.BlockHash), "mainHash", common.HashHex(msg.MainBlockHash),
"from", client.paraClient.authAccount) "from", client.authAccount)
} }
return signTx, count return signTx, count
...@@ -678,7 +679,7 @@ out: ...@@ -678,7 +679,7 @@ out:
isSync = true isSync = true
} }
if client.paraClient.authAccount != "" { if client.authAccount != "" {
client.GetProperFeeRate() client.GetProperFeeRate()
} }
...@@ -836,7 +837,7 @@ func (client *commitMsgClient) getNodeGroupAddrs() (string, error) { ...@@ -836,7 +837,7 @@ func (client *commitMsgClient) getNodeGroupAddrs() (string, error) {
} }
func (client *commitMsgClient) onWalletStatus(status *types.WalletStatus) { func (client *commitMsgClient) onWalletStatus(status *types.WalletStatus) {
if status == nil || client.paraClient.authAccount == "" { if status == nil || client.authAccount == "" {
return return
} }
if !status.IsWalletLock && client.privateKey == nil { if !status.IsWalletLock && client.privateKey == nil {
...@@ -858,7 +859,7 @@ func (client *commitMsgClient) onWalletStatus(status *types.WalletStatus) { ...@@ -858,7 +859,7 @@ func (client *commitMsgClient) onWalletStatus(status *types.WalletStatus) {
} }
func (client *commitMsgClient) onWalletAccount(acc *types.Account) { func (client *commitMsgClient) onWalletAccount(acc *types.Account) {
if acc == nil || client.paraClient.authAccount == "" || client.paraClient.authAccount != acc.Addr || client.privateKey != nil { if acc == nil || client.authAccount == "" || client.authAccount != acc.Addr || client.privateKey != nil {
return return
} }
err := client.fetchPriKey() err := client.fetchPriKey()
...@@ -872,7 +873,7 @@ func (client *commitMsgClient) onWalletAccount(acc *types.Account) { ...@@ -872,7 +873,7 @@ func (client *commitMsgClient) onWalletAccount(acc *types.Account) {
} }
func (client *commitMsgClient) fetchPriKey() error { func (client *commitMsgClient) fetchPriKey() error {
req := &types.ReqString{Data: client.paraClient.authAccount} req := &types.ReqString{Data: client.authAccount}
msg := client.paraClient.GetQueueClient().NewMessage("wallet", types.EventDumpPrivkey, req) msg := client.paraClient.GetQueueClient().NewMessage("wallet", types.EventDumpPrivkey, req)
err := client.paraClient.GetQueueClient().Send(msg, true) err := client.paraClient.GetQueueClient().Send(msg, true)
......
...@@ -561,7 +561,7 @@ out: ...@@ -561,7 +561,7 @@ out:
count = int64(len(paraTxs.Items)) count = int64(len(paraTxs.Items))
} }
//如果超过1个block,则认为当前正在追赶,暂不处理 //如果超过1个block,则认为当前正在追赶,暂不处理
if client.authAccount != "" && len(paraTxs.Items) == 1 { if client.commitMsgClient.authAccount != "" && len(paraTxs.Items) == 1 {
client.commitMsgClient.commitTxCheckNotify(paraTxs.Items[0].TxDetails) client.commitMsgClient.commitTxCheckNotify(paraTxs.Items[0].TxDetails)
} }
......
...@@ -231,7 +231,7 @@ func (client *blockSyncClient) syncBlocksIfNeed() (bool, error) { ...@@ -231,7 +231,7 @@ func (client *blockSyncClient) syncBlocksIfNeed() (bool, error) {
if err == nil { if err == nil {
isSyncCaughtUp := lastBlock.Height+1 == lastLocalHeight isSyncCaughtUp := lastBlock.Height+1 == lastLocalHeight
client.setSyncCaughtUp(isSyncCaughtUp) client.setSyncCaughtUp(isSyncCaughtUp)
if client.paraClient.authAccount != "" { if client.paraClient.commitMsgClient.authAccount != "" {
client.printDebugInfo("Para sync - add block commit", "isSyncCaughtUp", isSyncCaughtUp) client.printDebugInfo("Para sync - add block commit", "isSyncCaughtUp", isSyncCaughtUp)
client.paraClient.commitMsgClient.updateChainHeightNotify(lastBlock.Height+1, false) client.paraClient.commitMsgClient.updateChainHeightNotify(lastBlock.Height+1, false)
} }
...@@ -250,7 +250,7 @@ func (client *blockSyncClient) syncBlocksIfNeed() (bool, error) { ...@@ -250,7 +250,7 @@ func (client *blockSyncClient) syncBlocksIfNeed() (bool, error) {
//通知发送层 //通知发送层
if err == nil { if err == nil {
client.setSyncCaughtUp(false) client.setSyncCaughtUp(false)
if client.paraClient.authAccount != "" { if client.paraClient.commitMsgClient.authAccount != "" {
client.printDebugInfo("Para sync - rollback block commit", "isSyncCaughtUp", false) client.printDebugInfo("Para sync - rollback block commit", "isSyncCaughtUp", false)
client.paraClient.commitMsgClient.updateChainHeightNotify(lastBlock.Height-1, true) client.paraClient.commitMsgClient.updateChainHeightNotify(lastBlock.Height-1, true)
} }
...@@ -384,7 +384,7 @@ func (client *blockSyncClient) addMinerTx(preStateHash []byte, block *types.Bloc ...@@ -384,7 +384,7 @@ func (client *blockSyncClient) addMinerTx(preStateHash []byte, block *types.Bloc
return err return err
} }
tx.Sign(types.SECP256K1, client.paraClient.privateKey) tx.Sign(types.SECP256K1, client.paraClient.minerPrivateKey)
block.Txs = append([]*types.Transaction{tx}, block.Txs...) block.Txs = append([]*types.Transaction{tx}, block.Txs...)
return nil return nil
......
...@@ -66,7 +66,7 @@ func createParaTestInstance(t *testing.T, q queue.Queue) *client { ...@@ -66,7 +66,7 @@ func createParaTestInstance(t *testing.T, q queue.Queue) *client {
assert.Nil(t, err) assert.Nil(t, err)
priKey, err := secp.PrivKeyFromBytes(pk) priKey, err := secp.PrivKeyFromBytes(pk)
assert.Nil(t, err) assert.Nil(t, err)
para.privateKey = priKey para.minerPrivateKey = priKey
//实例化BlockSyncClient //实例化BlockSyncClient
para.blockSyncClient = &blockSyncClient{ para.blockSyncClient = &blockSyncClient{
......
...@@ -336,11 +336,11 @@ function para_cross_transfer_withdraw() { ...@@ -336,11 +336,11 @@ function para_cross_transfer_withdraw() {
echo "${hash}" echo "${hash}"
query_tx "${CLI}" "${hash}" query_tx "${CLI}" "${hash}"
hash=$(${CLI} send para asset_transfer --ptitle user.p.para. -a 1.4 -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01) hash=$(${CLI} send para asset_transfer --paraName user.p.para. -a 1.4 -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01)
echo "${hash}" echo "${hash}"
query_tx "${PARA_CLI}" "${hash}" query_tx "${PARA_CLI}" "${hash}"
hash2=$(${CLI} send para asset_withdraw --ptitle user.p.para. -a 0.7 -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01) hash2=$(${CLI} send para asset_withdraw --paraName user.p.para. -a 0.7 -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01)
local times=200 local times=200
while true; do while true; do
...@@ -426,12 +426,12 @@ function para_cross_transfer_withdraw_for_token() { ...@@ -426,12 +426,12 @@ function para_cross_transfer_withdraw_for_token() {
query_tx "${MAIN_CLI}" "${hash}" query_tx "${MAIN_CLI}" "${hash}"
echo "=========== # 2.transfer asset to para chain =============" echo "=========== # 2.transfer asset to para chain ============="
hash=$(${CLI} send para asset_transfer --ptitle user.p.para. -s FZM -a 220 -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv) hash=$(${CLI} send para asset_transfer --paraName user.p.para. -s FZM -a 220 -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
echo "${hash}" echo "${hash}"
query_tx "${MAIN_CLI}" "${hash}" query_tx "${MAIN_CLI}" "${hash}"
echo "=========== # 3.asset_withdraw from parachain =============" echo "=========== # 3.asset_withdraw from parachain ============="
${CLI} send para asset_withdraw --ptitle user.p.para. -a 111 -s FZM -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv ${CLI} send para asset_withdraw --paraName user.p.para. -a 111 -s FZM -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
local times=100 local times=100
while true; do while true; do
......
...@@ -14,3 +14,4 @@ help: ## Display this help screen ...@@ -14,3 +14,4 @@ help: ## Display this help screen
@printf "[command]\n" @printf "[command]\n"
@printf "[nodegroup]: create super node group if not create \n" @printf "[nodegroup]: create super node group if not create \n"
@printf "[wallet]: set node wallet private key if not set \n" @printf "[wallet]: set node wallet private key if not set \n"
@printf "[miner]: unlock wallet to miner \n"
\ No newline at end of file
# 平行链授权节点一键式部署
## 需求
平行链申请超级节点步骤比较多,需要设置的地方也比较多,容易遗漏
## 使用
1. 把编译好的chain33,chain33-cli,chain33.toml,和chain33.para.toml和本脚本目录放到一起
1. 修改config文件配置项,每个配置项都有说明
1. make docker-compose 缺省启动
1. make docker-compose op=nodegroup 配置超级账户组
1. make docker-compose op=wallet 配置钱包开启共识
1. 系统缺省会把区块链数据从docker重映射到本地storage目录,以后默认启动历史数据不会丢失
1. make docker-compose down 停止当前平行链
## 系统重启
1. 系统重启使用 make docker-compose即可, 起来后 make docker-compose op=miner开启挖矿
\ No newline at end of file
paraName="test"
#genesisAccount=""
#genesisAmount=100000000
#mainStartHeight=4800000
#authAccount=()
#authPrikey=()
##docker8901端口暴露到宿主机的端口
#authPort=("18901" "18902" "18903" "18904")
#
##需要和chain33 主链保持一致
#superManager="['1JmFaA6unrCFYEWPGRi7uuXY1KthTJxJEP']"
#
##nodegroup create
##申请超级账户需要在主链冻结币数量
#authFrozenCoins=0
#nodeGroupApplier=""
#applierPrikey=""
#superManagerPrikey=""
#平行链名字,这里不需要加user.p.前缀
paraName="test"
#### 测试链配置,主链配置需要把如下测试链配置屏蔽 ########## #### 测试链配置四个节点例子,主链配置需要把如下测试链配置屏蔽 ##########
#创世账户
genesisAccount="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt" genesisAccount="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
#创世数量
genesisAmount=100000000 genesisAmount=100000000
#从主链哪个高度开始同步区块
mainStartHeight=4000000 mainStartHeight=4000000
#平行链授权账户,这里的数量要和下面的authPrikey和authPort保持一致
authAccount=( "1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4" "1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR" "1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k" "1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs") authAccount=( "1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4" "1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR" "1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k" "1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs")
#授权账户的私钥,为了导入钱包,自动开启共识挖矿
authPrikey=("0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b" "0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4" "0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115" "0xcacb1f5d51700aea07fca2246ab43b0917d70405c65edea9b5063d72eb5c6b71") authPrikey=("0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b" "0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4" "0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115" "0xcacb1f5d51700aea07fca2246ab43b0917d70405c65edea9b5063d72eb5c6b71")
#授权节点的宿主机端口
authPort=("18901" "18902" "18903" "18904") authPort=("18901" "18902" "18903" "18904")
#需要和chain33 主链保持一致 #需要和chain33 主链保持一致
...@@ -32,8 +22,12 @@ superManager="['12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv']" ...@@ -32,8 +22,12 @@ superManager="['12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv']"
tokenApprs="['12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv']" tokenApprs="['12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv']"
#nodegroup create #超级账户创建
#授权账户申请需要在主链上冻结的BTY数量,申请之前需要chain33项目方沟通,需要chain33超级管理员审批通过
authFrozenCoins=0 authFrozenCoins=0
#超级账户组申请者,需要事先在paracross合约转移必须的BTY,数量=申请的授权账户数量*authFrozenCoins
nodeGroupApplier="1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4" nodeGroupApplier="1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"
#超级账户组申请者私钥 签名交易使用
applierPrikey="0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b" applierPrikey="0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
#超级管理员私钥,在主链上申请不需要填
superManagerPrikey="4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" superManagerPrikey="4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01"
...@@ -87,6 +87,13 @@ function para_import_wallet() { ...@@ -87,6 +87,13 @@ function para_import_wallet() {
./$CHAIN33_CLI --rpc_laddr "http://localhost:$port" wallet status ./$CHAIN33_CLI --rpc_laddr "http://localhost:$port" wallet status
} }
function para_unlock_wallet() {
for ((i = 0; i < ${#authPort[@]}; i++)); do
echo "=========== # para unlock wallet ${authPort[$i]}============="
./$CHAIN33_CLI --rpc_laddr "http://localhost:${authPort[$i]}" wallet unlock -p 1314fuzamei -t 0
done
}
function start() { function start() {
echo "=========== # docker-compose ps =============" echo "=========== # docker-compose ps ============="
docker-compose ps docker-compose ps
...@@ -175,6 +182,7 @@ EOF ...@@ -175,6 +182,7 @@ EOF
volumes: volumes:
- "../storage/parachain$i/paradatadir:/root/paradatadir" - "../storage/parachain$i/paradatadir:/root/paradatadir"
- "../storage/parachain$i/logs:/root/logs" - "../storage/parachain$i/logs:/root/logs"
- "../storage/parachain$i/parawallet:/root/parawallet"
EOF EOF
done done
...@@ -260,6 +268,10 @@ function main() { ...@@ -260,6 +268,10 @@ function main() {
para_set_wallet para_set_wallet
fi fi
if [ "$1" == "miner" ]; then
para_unlock_wallet
fi
echo "===============================parachain startup end=========================================================" echo "===============================parachain startup end========================================================="
} }
......
...@@ -42,6 +42,7 @@ func ParcCmd() *cobra.Command { ...@@ -42,6 +42,7 @@ func ParcCmd() *cobra.Command {
GetHeightCmd(), GetHeightCmd(),
GetBlockInfoCmd(), GetBlockInfoCmd(),
GetLocalBlockInfoCmd(), GetLocalBlockInfoCmd(),
GetConsensDoneInfoCmd(),
) )
return cmd return cmd
} }
...@@ -66,9 +67,6 @@ func addCreateAssetTransferFlags(cmd *cobra.Command) { ...@@ -66,9 +67,6 @@ func addCreateAssetTransferFlags(cmd *cobra.Command) {
cmd.Flags().StringP("note", "n", "", "transaction note info") cmd.Flags().StringP("note", "n", "", "transaction note info")
cmd.Flags().StringP("ptitle", "", "", "the title of para chain, like `user.p.guodun.`")
cmd.MarkFlagRequired("ptitle")
cmd.Flags().StringP("symbol", "s", "", "default for bty, symbol for token") cmd.Flags().StringP("symbol", "s", "", "default for bty, symbol for token")
} }
...@@ -98,9 +96,6 @@ func addCreateAssetWithdrawFlags(cmd *cobra.Command) { ...@@ -98,9 +96,6 @@ func addCreateAssetWithdrawFlags(cmd *cobra.Command) {
cmd.Flags().StringP("note", "n", "", "transaction note info") cmd.Flags().StringP("note", "n", "", "transaction note info")
cmd.Flags().StringP("ptitle", "", "", "the title of para chain, like `user.p.guodun.`")
cmd.MarkFlagRequired("ptitle")
cmd.Flags().StringP("to", "t", "", "receiver account address") cmd.Flags().StringP("to", "t", "", "receiver account address")
cmd.MarkFlagRequired("to") cmd.MarkFlagRequired("to")
...@@ -117,7 +112,7 @@ func createAssetWithdraw(cmd *cobra.Command, args []string) { ...@@ -117,7 +112,7 @@ func createAssetWithdraw(cmd *cobra.Command, args []string) {
} }
func createAssetTx(cmd *cobra.Command, isWithdraw bool) (string, error) { func createAssetTx(cmd *cobra.Command, isWithdraw bool) (string, error) {
title, _ := cmd.Flags().GetString("title") title, _ := cmd.Flags().GetString("paraName")
cfg := types.GetCliSysParam(title) cfg := types.GetCliSysParam(title)
amount, _ := cmd.Flags().GetFloat64("amount") amount, _ := cmd.Flags().GetFloat64("amount")
...@@ -130,12 +125,11 @@ func createAssetTx(cmd *cobra.Command, isWithdraw bool) (string, error) { ...@@ -130,12 +125,11 @@ func createAssetTx(cmd *cobra.Command, isWithdraw bool) (string, error) {
note, _ := cmd.Flags().GetString("note") note, _ := cmd.Flags().GetString("note")
symbol, _ := cmd.Flags().GetString("symbol") symbol, _ := cmd.Flags().GetString("symbol")
ptitle, _ := cmd.Flags().GetString("ptitle") if !strings.HasPrefix(title, "user.p") {
if !strings.HasPrefix(ptitle, "user.p") { fmt.Fprintln(os.Stderr, "title is not right, title format like `user.p.guodun.`")
fmt.Fprintln(os.Stderr, "ptitle is not right, title format like `user.p.guodun.`")
return "", types.ErrInvalidParam return "", types.ErrInvalidParam
} }
execName := ptitle + pt.ParaX execName := title + pt.ParaX
param := types.CreateTx{ param := types.CreateTx{
To: toAddr, To: toAddr,
...@@ -269,7 +263,10 @@ func createNodeJoinTx(cmd *cobra.Command, args []string) { ...@@ -269,7 +263,10 @@ func createNodeJoinTx(cmd *cobra.Command, args []string) {
opAddr, _ := cmd.Flags().GetString("addr") opAddr, _ := cmd.Flags().GetString("addr")
coins, _ := cmd.Flags().GetFloat64("coins") coins, _ := cmd.Flags().GetFloat64("coins")
paraName, _ := cmd.Flags().GetString("paraName") paraName, _ := cmd.Flags().GetString("paraName")
if !strings.HasPrefix(paraName, "user.p") {
fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
payload := &pt.ParaNodeAddrConfig{Title: paraName, Op: 1, Addr: opAddr, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4} payload := &pt.ParaNodeAddrConfig{Title: paraName, Op: 1, Addr: opAddr, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX), Execer: getRealExecName(paraName, pt.ParaX),
...@@ -304,7 +301,10 @@ func createNodeVoteTx(cmd *cobra.Command, args []string) { ...@@ -304,7 +301,10 @@ func createNodeVoteTx(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName") paraName, _ := cmd.Flags().GetString("paraName")
id, _ := cmd.Flags().GetString("id") id, _ := cmd.Flags().GetString("id")
val, _ := cmd.Flags().GetUint32("value") val, _ := cmd.Flags().GetUint32("value")
if !strings.HasPrefix(paraName, "user.p") {
fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
payload := &pt.ParaNodeAddrConfig{Title: paraName, Op: 2, Id: id, Value: val} payload := &pt.ParaNodeAddrConfig{Title: paraName, Op: 2, Id: id, Value: val}
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX), Execer: getRealExecName(paraName, pt.ParaX),
...@@ -337,7 +337,10 @@ func addNodeQuitFlags(cmd *cobra.Command) { ...@@ -337,7 +337,10 @@ func addNodeQuitFlags(cmd *cobra.Command) {
func createNodeQuitTx(cmd *cobra.Command, args []string) { func createNodeQuitTx(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName") paraName, _ := cmd.Flags().GetString("paraName")
opAddr, _ := cmd.Flags().GetString("addr") opAddr, _ := cmd.Flags().GetString("addr")
if !strings.HasPrefix(paraName, "user.p") {
fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
payload := &pt.ParaNodeAddrConfig{Title: paraName, Op: 3, Addr: opAddr} payload := &pt.ParaNodeAddrConfig{Title: paraName, Op: 3, Addr: opAddr}
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX), Execer: getRealExecName(paraName, pt.ParaX),
...@@ -370,7 +373,10 @@ func addNodeCancelFlags(cmd *cobra.Command) { ...@@ -370,7 +373,10 @@ func addNodeCancelFlags(cmd *cobra.Command) {
func createNodeCancelTx(cmd *cobra.Command, args []string) { func createNodeCancelTx(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName") paraName, _ := cmd.Flags().GetString("paraName")
id, _ := cmd.Flags().GetString("id") id, _ := cmd.Flags().GetString("id")
if !strings.HasPrefix(paraName, "user.p") {
fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
payload := &pt.ParaNodeAddrConfig{Title: paraName, Op: 4, Id: id} payload := &pt.ParaNodeAddrConfig{Title: paraName, Op: 4, Id: id}
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX), Execer: getRealExecName(paraName, pt.ParaX),
...@@ -655,6 +661,11 @@ func nodeGroupApply(cmd *cobra.Command, args []string) { ...@@ -655,6 +661,11 @@ func nodeGroupApply(cmd *cobra.Command, args []string) {
addrs, _ := cmd.Flags().GetString("addrs") addrs, _ := cmd.Flags().GetString("addrs")
coins, _ := cmd.Flags().GetFloat64("coins") coins, _ := cmd.Flags().GetFloat64("coins")
if !strings.HasPrefix(paraName, "user.p") {
fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 1, Addrs: addrs, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4} payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 1, Addrs: addrs, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX), Execer: getRealExecName(paraName, pt.ParaX),
...@@ -691,6 +702,11 @@ func nodeGroupApprove(cmd *cobra.Command, args []string) { ...@@ -691,6 +702,11 @@ func nodeGroupApprove(cmd *cobra.Command, args []string) {
id, _ := cmd.Flags().GetString("id") id, _ := cmd.Flags().GetString("id")
coins, _ := cmd.Flags().GetFloat64("coins") coins, _ := cmd.Flags().GetFloat64("coins")
if !strings.HasPrefix(paraName, "user.p") {
fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 2, Id: id, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4} payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 2, Id: id, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX), Execer: getRealExecName(paraName, pt.ParaX),
...@@ -722,7 +738,10 @@ func addNodeGroupQuitCmdFlags(cmd *cobra.Command) { ...@@ -722,7 +738,10 @@ func addNodeGroupQuitCmdFlags(cmd *cobra.Command) {
func nodeGroupQuit(cmd *cobra.Command, args []string) { func nodeGroupQuit(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName") paraName, _ := cmd.Flags().GetString("paraName")
id, _ := cmd.Flags().GetString("id") id, _ := cmd.Flags().GetString("id")
if !strings.HasPrefix(paraName, "user.p") {
fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 3, Id: id} payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 3, Id: id}
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX), Execer: getRealExecName(paraName, pt.ParaX),
...@@ -754,7 +773,10 @@ func addNodeGroupModifyCmdFlags(cmd *cobra.Command) { ...@@ -754,7 +773,10 @@ func addNodeGroupModifyCmdFlags(cmd *cobra.Command) {
func nodeGroupModify(cmd *cobra.Command, args []string) { func nodeGroupModify(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName") paraName, _ := cmd.Flags().GetString("paraName")
coins, _ := cmd.Flags().GetFloat64("coins") coins, _ := cmd.Flags().GetFloat64("coins")
if !strings.HasPrefix(paraName, "user.p") {
fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 4, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4} payload := &pt.ParaNodeGroupConfig{Title: paraName, Op: 4, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX), Execer: getRealExecName(paraName, pt.ParaX),
...@@ -1110,3 +1132,34 @@ func showSelfStages(cmd *cobra.Command, args []string) { ...@@ -1110,3 +1132,34 @@ func showSelfStages(cmd *cobra.Command, args []string) {
ctx := jsonclient.NewRPCCtx(rpcLaddr, "paracross.ListSelfStages", params, &res) ctx := jsonclient.NewRPCCtx(rpcLaddr, "paracross.ListSelfStages", params, &res)
ctx.Run() ctx.Run()
} }
func addConsensDoneCmdFlags(cmd *cobra.Command) {
cmd.Flags().Int64P("height", "g", 0, "height to para chain")
cmd.MarkFlagRequired("height")
}
func consensDoneInfo(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
paraName, _ := cmd.Flags().GetString("paraName")
height, _ := cmd.Flags().GetInt64("height")
params := pt.ReqParacrossTitleHeight{
Title: paraName,
Height: height,
}
var res pt.RespParacrossDone
ctx := jsonclient.NewRPCCtx(rpcLaddr, "paracross.GetDoneTitleHeight", params, &res)
ctx.Run()
}
// GetConsensDoneInfoCmd get para chain done height consens info
func GetConsensDoneInfoCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "consens_done",
Short: "Get para chain done height consensus info",
Run: consensDoneInfo,
}
addConsensDoneCmdFlags(cmd)
return cmd
}
...@@ -30,6 +30,7 @@ func (e *Paracross) ExecLocal_Commit(payload *pt.ParacrossCommitAction, tx *type ...@@ -30,6 +30,7 @@ func (e *Paracross) ExecLocal_Commit(payload *pt.ParacrossCommitAction, tx *type
} else if log.Ty == pt.TyLogParacrossCommitDone { } else if log.Ty == pt.TyLogParacrossCommitDone {
var g pt.ReceiptParacrossDone var g pt.ReceiptParacrossDone
types.Decode(log.Log, &g) types.Decode(log.Log, &g)
g.ChainExecHeight = e.GetHeight()
key := calcLocalTitleKey(g.Title) key := calcLocalTitleKey(g.Title)
set.KV = append(set.KV, &types.KeyValue{Key: key, Value: types.Encode(&g)}) set.KV = append(set.KV, &types.KeyValue{Key: key, Value: types.Encode(&g)})
......
...@@ -385,6 +385,7 @@ func loadLocalTitle(db dbm.KV, title string, height int64) (types.Message, error ...@@ -385,6 +385,7 @@ func loadLocalTitle(db dbm.KV, title string, height int64) (types.Message, error
MostSameCommit: st.MostSameCommit, MostSameCommit: st.MostSameCommit,
Title: st.Title, Title: st.Title,
Height: st.Height, Height: st.Height,
ChainExecHeight: st.ChainExecHeight,
TxResult: hex.EncodeToString(st.TxResult), TxResult: hex.EncodeToString(st.TxResult),
}, nil }, nil
} }
......
...@@ -328,6 +328,7 @@ message ReceiptParacrossDone { ...@@ -328,6 +328,7 @@ message ReceiptParacrossDone {
repeated bytes crossTxHashs = 12; repeated bytes crossTxHashs = 12;
bytes mainBlockHash = 13; bytes mainBlockHash = 13;
int64 mainBlockHeight = 14; int64 mainBlockHeight = 14;
int64 chainExecHeight = 15;
} }
message ReceiptParacrossRecord { message ReceiptParacrossRecord {
...@@ -356,6 +357,8 @@ message RespParacrossDone { ...@@ -356,6 +357,8 @@ message RespParacrossDone {
string stateHash = 6; string stateHash = 6;
uint32 txCounts = 7; uint32 txCounts = 7;
string txResult = 8; string txResult = 8;
//commitDone chainHeight
int64 chainExecHeight= 9;
} }
message RespParacrossTitles { message RespParacrossTitles {
......
...@@ -118,6 +118,19 @@ func (c *channelClient) GetDoneTitleHeight(ctx context.Context, req *pt.ReqParac ...@@ -118,6 +118,19 @@ func (c *channelClient) GetDoneTitleHeight(ctx context.Context, req *pt.ReqParac
return nil, types.ErrDecode return nil, types.ErrDecode
} }
// GetAssetTxResult get asset tx result
func (c *Jrpc) GetDoneTitleHeight(req *pt.ReqParacrossTitleHeight, result *interface{}) error {
if req == nil {
return types.ErrInvalidParam
}
data, err := c.cli.GetDoneTitleHeight(context.Background(), req)
if err != nil {
return err
}
*result = data
return err
}
func (c *channelClient) GetAssetTxResult(ctx context.Context, req *types.ReqString) (*pt.ParacrossAssetRsp, error) { func (c *channelClient) GetAssetTxResult(ctx context.Context, req *types.ReqString) (*pt.ParacrossAssetRsp, error) {
cfg := c.GetConfig() cfg := c.GetConfig()
data, err := c.Query(pt.GetExecName(cfg), "GetAssetTxResult", req) data, err := c.Query(pt.GetExecName(cfg), "GetAssetTxResult", req)
......
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