Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug of wasm pgu #3097

Merged
merged 5 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions libs/tendermint/mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,8 @@ func (mem *CListMempool) CheckTx(tx types.Tx, cb func(*abci.Response), txInfo Tx
defer mem.updateMtx.RUnlock()

var err error
var gasUsed int64
if cfg.DynamicConfig.GetMaxGasUsedPerBlock() > -1 {
gasUsed = mem.txInfoparser.GetTxHistoryGasUsed(tx)
if gasUsed < 0 {
simuRes, err := mem.simulateTx(tx)
if err != nil {
return err
}
gasUsed = int64(simuRes.GasUsed)
}
txInfo.gasUsed = mem.txInfoparser.GetTxHistoryGasUsed(tx)
}

if mem.preCheck != nil {
Expand All @@ -374,11 +366,10 @@ func (mem *CListMempool) CheckTx(tx types.Tx, cb func(*abci.Response), txInfo Tx
if cfg.DynamicConfig.GetMaxGasUsedPerBlock() > -1 {
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))
if gasUsed < r.CheckTx.GasWanted {
r.CheckTx.GasWanted = gasUsed
hex.EncodeToString(tx.Hash(mem.Height())), r.CheckTx.GasWanted, txInfo.gasUsed))
if txInfo.gasUsed <= 0 || txInfo.gasUsed > r.CheckTx.GasWanted {
txInfo.gasUsed = r.CheckTx.GasWanted
}

}
}
reqRes.SetCallback(mem.reqResCb(tx, txInfo, cb))
Expand Down Expand Up @@ -702,7 +693,8 @@ func (mem *CListMempool) resCbFirstTime(

memTx := &mempoolTx{
height: mem.Height(),
gasWanted: r.CheckTx.GasWanted,
gasLimit: r.CheckTx.GasWanted,
gasWanted: txInfo.gasUsed,
tx: tx,
realTx: r.CheckTx.Tx,
nodeKey: txInfo.wtx.GetNodeKey(),
Expand Down Expand Up @@ -1245,8 +1237,9 @@ func MultiPriceBump(rawPrice *big.Int, priceBump int64) *big.Int {

// mempoolTx is a transaction that successfully ran
type mempoolTx struct {
height int64 // height that this tx had been validated in
gasWanted int64 // amount of gas this tx states it will require
height int64 // height that this tx had been validated in
gasWanted int64 // amount of gas this tx states it will require
gasLimit int64
tx types.Tx //
realTx abci.TxEssentials
nodeKey []byte
Expand Down Expand Up @@ -1447,10 +1440,10 @@ 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) {
if gas < atomic.LoadInt64(&memTx.gasLimit) {
atomic.StoreInt64(&memTx.gasWanted, gas)
}
atomic.AddUint32(&memTx.isSim, 1)
mem.gasCache.Add(hex.EncodeToString(memTx.realTx.TxHash()), gas)
}

Expand Down
2 changes: 1 addition & 1 deletion libs/tendermint/mempool/clist_mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestReapMaxBytesMaxGas(t *testing.T) {
tx0 := mempool.TxsFront().Value.(*mempoolTx)
// assert that kv store has gas wanted = 1.
require.Equal(t, app.CheckTx(abci.RequestCheckTx{Tx: tx0.tx}).GasWanted, int64(1), "KVStore had a gas value neq to 1")
require.Equal(t, tx0.gasWanted, int64(1), "transactions gas was set incorrectly")
require.Equal(t, tx0.gasWanted, int64(0), "transactions gas was set incorrectly")
// ensure each tx is 20 bytes long
require.Equal(t, len(tx0.tx), 20, "Tx is longer than 20 bytes")
mempool.Flush()
Expand Down
2 changes: 2 additions & 0 deletions libs/tendermint/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ type TxInfo struct {
wtx *WrappedTx
checkType abci.CheckTxType

gasUsed int64

wrapCMTx *types.WrapCMTx
}

Expand Down