Commit 1b62e231 authored by mdj33's avatar mdj33 Committed by vipwzw

add local height query

parent 017bcf9e
......@@ -115,6 +115,8 @@ MainForkParacrossCommitTx=2270000
MainParaSelfConsensusForkHeight=-1
#主链开启循环检查共识交易done的fork高度
MainLoopCheckCommitTxDoneForkHeight=-1
#主链过滤平行链tx
FetchFilterParaTxsEnable=-1
[store]
name="kvmvccmavl"
......
......@@ -15,6 +15,8 @@ import (
"time"
"test/common"
"github.com/33cn/chain33/client/api"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/merkle"
......@@ -343,6 +345,40 @@ func (client *client) Query_IsCaughtUp(req *types.ReqNil) (types.Message, error)
return &types.IsCaughtUp{Iscaughtup: client.isCaughtUp()}, nil
}
func (client *client) Query_LocalBlockInfo(req *types.ReqInt) (types.Message, error) {
if client == nil {
return nil, fmt.Errorf("%s", "client not bind message queue.")
}
var block *pt.ParaLocalDbBlock
var err error
if req.Height <= -1 {
block, err = client.getLastLocalBlock()
if err != nil {
return nil, err
}
} else {
block, err = client.getLocalBlockByHeight(req.Height)
if err != nil {
return nil, err
}
}
blockInfo := &pt.ParaLocalDbBlockInfo{
Height: block.Height,
MainHash: common.ToHex(block.MainHash),
MainHeight: block.MainHeight,
ParentMainHash: common.ToHex(block.ParentMainHash),
BlockTime: block.BlockTime,
}
for _, tx := range block.Txs {
blockInfo.Txs = append(blockInfo.Txs, common.ToHex(tx.Hash()))
}
return blockInfo, nil
}
func checkMinerTx(current *types.BlockDetail) error {
//检查第一个笔交易的execs, 以及执行状态
if len(current.Block.Txs) == 0 {
......
......@@ -47,6 +47,7 @@ func initTestSyncBlock() {
//新建一个para测试实例并初始化一些参数
func createParaTestInstance(t *testing.T, q queue.Queue) *client {
para := new(client)
para.subCfg = new(subConfig)
baseCli := drivers.NewBaseClient(&types.Consensus{Name: "name"})
para.BaseClient = baseCli
......
......@@ -41,6 +41,7 @@ function para_set_toml() {
sed -i $xsedfix 's/^MainForkParacrossCommitTx=.*/MainForkParacrossCommitTx=10/g' "${1}"
sed -i $xsedfix 's/^MainParaSelfConsensusForkHeight=.*/MainParaSelfConsensusForkHeight=50/g' "${1}"
sed -i $xsedfix 's/^MainLoopCheckCommitTxDoneForkHeight=.*/MainLoopCheckCommitTxDoneForkHeight=60/g' "${1}"
sed -i $xsedfix 's/^FetchFilterParaTxsEnable=.*/FetchFilterParaTxsEnable=1/g' "${1}"
# rpc
sed -i $xsedfix 's/^jrpcBindAddr=.*/jrpcBindAddr="0.0.0.0:8901"/g' "${1}"
......
......@@ -45,6 +45,7 @@ func ParcCmd() *cobra.Command {
IsSyncCmd(),
GetHeightCmd(),
GetBlockInfoCmd(),
GetLocalBlockInfoCmd(),
)
return cmd
}
......@@ -400,6 +401,36 @@ func blockInfo(cmd *cobra.Command, args []string) {
}
// GetLocalBlockInfoCmd get blocks hash with main chain hash map
func GetLocalBlockInfoCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "local_block",
Short: "Get para local block info",
Run: localBlockInfo,
}
addLocalBlockBodyCmdFlags(cmd)
return cmd
}
func addLocalBlockBodyCmdFlags(cmd *cobra.Command) {
cmd.Flags().Int64P("start", "t", 0, "block height,-1:latest height")
cmd.MarkFlagRequired("start")
}
func localBlockInfo(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
startH, _ := cmd.Flags().GetInt64("start")
params := types.ReqInt{
Height: startH,
}
var res pt.ParaLocalDbBlockInfo
ctx := jsonclient.NewRPCCtx(rpcLaddr, "paracross.GetParaLocalBlockInfo", params, &res)
ctx.Run()
}
// GetParaInfoCmd get para chain status by height
func GetParaInfoCmd() *cobra.Command {
cmd := &cobra.Command{
......
......@@ -310,6 +310,14 @@ message ParaLocalDbBlock {
repeated Transaction txs = 6;
}
message ParaLocalDbBlockInfo {
int64 height = 1;
string mainHash = 2;
int64 mainHeight = 3;
string parentMainHash = 4;
int64 blockTime = 5;
repeated string txs = 6;
}
service paracross {
rpc GetTitle(ReqString) returns (ParacrossConsensusStatus) {}
......
......@@ -160,6 +160,25 @@ func (c *Jrpc) IsSync(in *types.ReqNil, result *interface{}) error {
return nil
}
// GetParaLocalBlockInfo query para local height
func (c *channelClient) GetParaLocalBlockInfo(ctx context.Context, in *types.ReqInt) (*pt.ParaLocalDbBlockInfo, error) {
data, err := c.QueryConsensusFunc("para", "LocalBlockInfo", in)
if err != nil {
return nil, err
}
return data.(*pt.ParaLocalDbBlockInfo), nil
}
// GetParaLocalBlockInfo query para local height
func (c *Jrpc) GetParaLocalBlockInfo(in *types.ReqInt, result *interface{}) error {
data, err := c.cli.GetParaLocalBlockInfo(context.Background(), in)
if err != nil {
return err
}
*result = data
return nil
}
func (c *channelClient) GetBlock2MainInfo(ctx context.Context, req *types.ReqBlocks) (*pt.ParaBlock2MainInfo, error) {
ret := &pt.ParaBlock2MainInfo{}
details, err := c.GetBlocks(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