Commit ce619cf7 authored by mdj33's avatar mdj33 Committed by vipwzw

support batch fetch tx

parent 7174ecf7
......@@ -49,6 +49,8 @@ var (
mainParaSelfConsensusForkHeight int64 = types.MaxHeight //para chain self consensus height switch, must >= ForkParacrossCommitTx of main
mainForkParacrossCommitTx int64 = types.MaxHeight //support paracross commit tx fork height in main chain: ForkParacrossCommitTx
localCacheCount int64 = 1000 // local cache block max count
batchFetchSeqEnable bool
batchFetchSeqNum int64 = 128
)
func init() {
......@@ -86,6 +88,8 @@ type subConfig struct {
MainForkParacrossCommitTx int64 `json:"mainForkParacrossCommitTx,omitempty"`
WaitConsensStopTimes uint32 `json:"waitConsensStopTimes,omitempty"`
LocalCacheCount int64 `json:"localCacheCount,omitempty"`
BatchFetchSeqEnable uint32 `json:"batchFetchSeqEnable,omitempty"`
BatchFetchSeqNum int64 `json:"batchFetchSeqNum,omitempty"`
}
// New function to init paracross env
......@@ -129,6 +133,14 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
localCacheCount = subcfg.LocalCacheCount
}
if subcfg.BatchFetchSeqEnable > 0 {
batchFetchSeqEnable = true
}
if subcfg.BatchFetchSeqNum > 0 {
batchFetchSeqNum = subcfg.BatchFetchSeqNum
}
pk, err := hex.DecodeString(minerPrivateKey)
if err != nil {
panic(err)
......
This diff is collapsed.
......@@ -145,3 +145,13 @@ func (client *client) GetBlockOnMainByHash(hash []byte) (*types.Block, error) {
return blocks.Items[0].Block, nil
}
func (client *client) QueryTxOnMainByHash(hash []byte) (*types.TransactionDetail, error) {
detail, err := client.grpcClient.QueryTransaction(context.Background(), &types.ReqHash{Hash: hash})
if err != nil {
plog.Error("QueryTxOnMainByHash Not found", "txhash", common.ToHex(hash))
return nil, err
}
return detail, nil
}
......@@ -72,6 +72,36 @@ func filterParaTxGroup(title string, tx *types.Transaction, main *types.BlockDet
return main.Block.Txs[headIdx:endIdx], endIdx
}
func filterParaTxGroupPlus(title string, tx *types.Transaction, allTxs []*pt.TxDetail, index int, blockHeight, forkHeight int64) ([]*types.Transaction, int) {
var headIdx int
for i := index; i >= 0; i-- {
if bytes.Equal(tx.Header, allTxs[i].Tx.Hash()) {
headIdx = i
break
}
}
endIdx := headIdx + int(tx.GroupCount)
for i := headIdx; i < endIdx; i++ {
if types.IsPara() && blockHeight < forkHeight {
if types.IsSpecificParaExecName(title, string(allTxs[i].Tx.Execer)) {
continue
}
}
if !checkReceiptExecOk(allTxs[i].Receipt) {
return nil, endIdx
}
}
//全部是平行链交易 或平行链在主链执行成功的tx
var retTxs []*types.Transaction
for _, retTx := range allTxs[headIdx:endIdx] {
retTxs = append(retTxs, retTx.Tx)
}
return retTxs, endIdx
}
//FilterTxsForPara include some main tx in tx group before ForkParacrossCommitTx
func FilterTxsForPara(title string, main *types.BlockDetail) []*types.Transaction {
var txs []*types.Transaction
......@@ -96,6 +126,30 @@ func FilterTxsForPara(title string, main *types.BlockDetail) []*types.Transactio
return txs
}
//FilterTxsForPara include some main tx in tx group before ForkParacrossCommitTx
func FilterTxsForParaPlus(title string, main *pt.ParaTxDetail) []*types.Transaction {
var txs []*types.Transaction
forkHeight := pt.GetDappForkHeight(pt.ForkCommitTx)
for i := 0; i < len(main.TxDetails); i++ {
tx := main.TxDetails[i].Tx
if types.IsSpecificParaExecName(title, string(tx.Execer)) {
if tx.GroupCount >= 2 {
mainTxs, endIdx := filterParaTxGroupPlus(title, tx, main.TxDetails, i, main.Header.Height, forkHeight)
txs = append(txs, mainTxs...)
i = endIdx - 1
continue
}
//单独的paracross tx 如果主链执行失败也要排除, 6.2fork原因 没有排除 非user.p.xx.paracross的平行链交易
if main.Header.Height >= forkHeight && bytes.HasSuffix(tx.Execer, []byte(pt.ParaX)) && !checkReceiptExecOk(main.TxDetails[i].Receipt) {
continue
}
txs = append(txs, tx)
}
}
return txs
}
// FilterParaCrossTxHashes only all para chain cross txs like xx.paracross exec
func FilterParaCrossTxHashes(title string, txs []*types.Transaction) [][]byte {
var txHashs [][]byte
......@@ -179,3 +233,32 @@ func CalcTxHashsHash(txHashs [][]byte) []byte {
data := types.Encode(totalTxHash)
return common.Sha256(data)
}
//BlockDetail2ParaTxs blockDetail transfer to paraTxDetail
func BlockDetail2ParaTxs(seqType int64, blockHash []byte, blockDetail *types.BlockDetail) *pt.ParaTxDetail {
header := &types.Header{
Version: blockDetail.Block.Version,
ParentHash: blockDetail.Block.ParentHash,
TxHash: blockDetail.Block.TxHash,
StateHash: blockDetail.Block.StateHash,
Height: blockDetail.Block.Height,
BlockTime: blockDetail.Block.BlockTime,
Difficulty: blockDetail.Block.Difficulty,
Signature: blockDetail.Block.Signature,
}
header.Hash = blockHash
txDetail := &pt.ParaTxDetail{
Type: seqType,
Header: header,
}
for i, tx := range blockDetail.Block.Txs {
detail := &pt.TxDetail{
Tx: tx,
Receipt: blockDetail.Receipts[i],
}
txDetail.TxDetails = append(txDetail.TxDetails, detail)
}
return txDetail
}
......@@ -310,6 +310,30 @@ message ParaLocalDbBlock {
repeated Transaction txs = 6;
}
message ReqParaTxByTitle{
int64 start = 1;
int64 end = 2;
string title = 3;
}
message TxDetail {
uint32 index = 1;
Transaction tx = 2;
ReceiptData receipt = 3;
repeated bytes proofs = 4;
}
message ParaTxDetail{
int64 type = 1;
Header header = 2;
repeated TxDetail txDetails = 3;
}
message ParaTxDetails{
repeated ParaTxDetail items = 1;
}
service paracross {
rpc GetTitle(ReqString) returns (ParacrossConsensusStatus) {}
......
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