Commit 7bc33343 authored by mdj33's avatar mdj33 Committed by vipwzw

delay send commit tx when block has all user.p.x.paracross commit tx

parent a1c5bef5
......@@ -130,6 +130,9 @@ out:
plog.Error("para commit msg read tick", "err", err.Error())
continue
}
if len(status) == 0 {
continue
}
signTx, count, err := client.calcCommitMsgTxs(status)
if err != nil || signTx == nil {
......@@ -426,9 +429,20 @@ func (client *commitMsgClient) getNodeStatus(start, end int64) ([]*pt.ParacrossN
nodeList[block.Block.Height].StateHash = block.Block.StateHash
}
var needSentTxs uint32
for i := 0; i < int(count); i++ {
ret = append(ret, nodeList[req.Start+int64(i)])
needSentTxs += nodeList[req.Start+int64(i)].TxCounts
}
//1.如果是只有commit tx的空块,推迟发送,直到等到一个完全没有commit tx的空块或者其他tx的块
//2,如果20个块都是 commit tx的空块,20个块打包一次发送,尽量减少commit tx造成的空块
//3,如果形如xxoxx的块排列,x代表commit空块,o代表实际的块,即只要不全部是commit块,也要全部打包一起发出去
//如果=0 意味着全部是paracross commit tx,延迟发送
if needSentTxs == 0 && count < types.TxGroupMaxCount {
plog.Info("para commitmsg getNodeStatus all self consensus commit tx,send delay", "start", start, "end", end)
return nil, nil
}
return ret, nil
}
......
......@@ -164,23 +164,43 @@ func setMinerTxResult(payload *pt.ParacrossMinerAction, txs []*types.Transaction
return nil
}
func setMinerTxResultFork(payload *pt.ParacrossMinerAction, txs []*types.Transaction, receipts []*types.ReceiptData) {
func setMinerTxResultFork(status *pt.ParacrossNodeStatus, txs []*types.Transaction, receipts []*types.ReceiptData) error {
isCommitTx := make(map[string]bool)
var curTxHashs [][]byte
for _, tx := range txs {
hash := tx.Hash()
curTxHashs = append(curTxHashs, hash)
if types.IsMyParaExecName(string(tx.Execer)) && bytes.HasSuffix(tx.Execer, []byte(pt.ParaX)) {
var payload pt.ParacrossAction
err := types.Decode(tx.Payload, &payload)
if err != nil {
clog.Error("setMinerTxResultFork", "txHash", common.ToHex(hash))
return err
}
if payload.Ty == pt.ParacrossActionCommit {
isCommitTx[string(hash)] = true
}
}
}
baseCrossTxHashs := FilterParaCrossTxHashes(types.GetTitle(), txs)
//有tx且全部是user.p.x.paracross的commit tx时候设为0
status.TxCounts = 1
if len(curTxHashs) != 0 && len(curTxHashs) == len(isCommitTx) {
status.TxCounts = 0
}
crossTxHashs := FilterParaCrossTxHashes(types.GetTitle(), txs)
//主链自己过滤平行链tx, 对平行链执行失败的tx主链无法识别,主链和平行链需要获取相同的最初的tx map
//全部平行链tx结果
payload.Status.TxResult = util.CalcBitMap(curTxHashs, curTxHashs, receipts)
status.TxResult = util.CalcBitMap(curTxHashs, curTxHashs, receipts)
//跨链tx结果
payload.Status.CrossTxResult = util.CalcBitMap(baseCrossTxHashs, curTxHashs, receipts)
status.CrossTxResult = util.CalcBitMap(crossTxHashs, curTxHashs, receipts)
status.TxHashs = [][]byte{CalcTxHashsHash(curTxHashs)}
status.CrossTxHashs = [][]byte{CalcTxHashsHash(crossTxHashs)}
payload.Status.TxHashs = [][]byte{CalcTxHashsHash(curTxHashs)}
payload.Status.CrossTxHashs = [][]byte{CalcTxHashsHash(baseCrossTxHashs)}
return nil
}
//ExecLocal_Miner miner tx local db process
......@@ -196,7 +216,10 @@ func (e *Paracross) ExecLocal_Miner(payload *pt.ParacrossMinerAction, tx *types.
//removed the 0 vote tx
if payload.Status.MainBlockHeight >= forkHeight {
setMinerTxResultFork(payload, txs[1:], e.GetReceipt()[1:])
err := setMinerTxResultFork(payload.Status, txs[1:], e.GetReceipt()[1:])
if err != nil {
return nil, err
}
} else {
err := setMinerTxResult(payload, txs[1:], e.GetReceipt()[1:])
if err != nil {
......
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