Skip to content

Commit

Permalink
Merge PR: fix mempool gas (#2912)
Browse files Browse the repository at this point in the history
* pack one tx at least

* simulation gas wanted must less than gas limit
  • Loading branch information
yann-sjtu authored Jan 7, 2023
1 parent 9caef58 commit 58e9a43
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions libs/tendermint/mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ func (mem *CListMempool) CheckTx(tx types.Tx, cb func(*abci.Response), txInfo Tx
if r, ok := reqRes.Response.Value.(*abci.Response_CheckTx); ok {
mem.logger.Info(fmt.Sprintf("mempool.SimulateTx: txhash<%s>, gasLimit<%d>, gasUsed<%d>",
hex.EncodeToString(tx.Hash(mem.Height())), r.CheckTx.GasWanted, gasUsed))
r.CheckTx.GasWanted = gasUsed
if gasUsed < r.CheckTx.GasWanted {
r.CheckTx.GasWanted = gasUsed
}
}
}
reqRes.SetCallback(mem.reqResCb(tx, txInfo, cb))
Expand Down Expand Up @@ -841,7 +843,10 @@ func (mem *CListMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) []types.Tx {
// must be non-negative, it follows that this won't overflow.
gasWanted := atomic.LoadInt64(&memTx.gasWanted)
newTotalGas := totalGas + gasWanted
if maxGas > -1 && newTotalGas > maxGas {
if gasWanted >= maxGas {
mem.logger.Error("tx gas overflow", "txHash", hex.EncodeToString(key[:]), "gasWanted", gasWanted, "isSim", memTx.isSim)
}
if maxGas > -1 && newTotalGas > maxGas && len(txs) > 0 {
return txs
}
if totalTxNum >= cfg.DynamicConfig.GetMaxTxNumPerBlock() {
Expand Down Expand Up @@ -1378,7 +1383,9 @@ func (mem *CListMempool) simulationJob(memTx *mempoolTx) {
return
}
gas := int64(simuRes.GasUsed) * int64(cfg.DynamicConfig.GetPGUAdjustment()*100) / 100
atomic.StoreInt64(&memTx.gasWanted, gas)
if gas < atomic.LoadInt64(&memTx.gasWanted) {
atomic.StoreInt64(&memTx.gasWanted, gas)
}
atomic.AddUint32(&memTx.isSim, 1)
mem.gasCache.Add(hex.EncodeToString(memTx.realTx.TxHash()), gas)
}
Expand Down

0 comments on commit 58e9a43

Please sign in to comment.