Skip to content

Commit

Permalink
pgu twice
Browse files Browse the repository at this point in the history
  • Loading branch information
yann-sjtu committed Jul 17, 2023
1 parent 1960c0f commit 26ddad0
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions libs/tendermint/mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ func (mem *CListMempool) resCbFirstTime(
if txInfo.isGasPrecise {
// gas for hgu is precise, just mark it simulated, so it will not be simulated again
memTx.isSim = 1
memTx.hguPrecise = true
}

if txInfo.wrapCMTx != nil {
Expand Down Expand Up @@ -1264,6 +1265,9 @@ type mempoolTx struct {
outdated uint32
isSim uint32

// `hguPrecise` is true means hgu for this tx is precise and simulation is not necessary
hguPrecise bool

isWrapCMTx bool
wrapCMNonce uint64

Expand Down Expand Up @@ -1487,6 +1491,50 @@ func (mem *CListMempool) simulationJob(memTx *mempoolTx) {
atomic.AddUint32(&memTx.isSim, 1)
}

// trySimulate4BlockAfterNext will be called during Update()
// assume that next step is to proposal a block of height `n` through ReapMaxBytesMaxGas
// trySimulate4NextBlock will skip those txs which would be packed into that block,
// and simulate txs to be packed into block of height `n+1`
func (mem *CListMempool) trySimulate4NextBlock() {
maxGu := cfg.DynamicConfig.GetMaxGasUsedPerBlock()
if maxGu < 0 || !cfg.DynamicConfig.GetEnablePGU() {
return
}

var gu int64
var ele *clist.CElement
// skip the txs that will be packed into next block
for ele = mem.txs.Front(); ele != nil; ele = ele.Next() {
gu += ele.Value.(*mempoolTx).gasWanted
if gu > maxGu {
break
}
}

// reset gu for next cycle
gu = 0

for ; ele != nil && gu < maxGu; ele = ele.Next() {
memTx := ele.Value.(*mempoolTx)
var gas int64
var err error
if !memTx.hguPrecise {
gas, err = mem.simulateTx(memTx.tx, memTx.gasLimit)
if err != nil {
mem.logger.Error("trySimulate4BlockAfterNext", "error", err, "txHash", memTx.tx.Hash(mem.Height()))
return
}
atomic.StoreInt64(&memTx.gasWanted, gas)
atomic.AddUint32(&memTx.isSim, 1)
} else {
gas = memTx.gasWanted
}

gu += gas
}

}

func (mem *CListMempool) deleteMinGPTxOnlyFull() {
//check weather exceed mempool size,then need to delet the minimum gas price
for mem.Size() > cfg.DynamicConfig.GetMempoolSize() || mem.TxsBytes() > mem.config.MaxTxsBytes {
Expand Down

0 comments on commit 26ddad0

Please sign in to comment.