Skip to content

Commit

Permalink
check accumulated sponsor amount
Browse files Browse the repository at this point in the history
  • Loading branch information
abelliumnt committed Feb 26, 2024
1 parent 52122bd commit 2619376
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,7 @@ func (pool *TxPool) validateMetaTxList(list *list) ([]*types.Transaction, *big.I

var invalidMetaTxs []*types.Transaction
sponsorCostSum := big.NewInt(0)
sponsorCostSumPerSponsor := make(map[common.Address]*big.Int)
for _, tx := range list.txs.Flatten() {
metaTxParams, err := types.DecodeAndVerifyMetaTxParams(tx, pool.chainconfig.IsMetaTxV2(pool.chain.CurrentBlock().Time))
if err != nil {
Expand All @@ -1493,17 +1494,26 @@ func (pool *TxPool) validateMetaTxList(list *list) ([]*types.Transaction, *big.I
}
if metaTxParams.ExpireHeight < currHeight {
invalidMetaTxs = append(invalidMetaTxs, tx)
continue
}
txGasCost := new(big.Int).Mul(tx.GasPrice(), new(big.Int).SetUint64(tx.Gas()))
l1Cost := pool.l1CostFn(tx.RollupDataGas(), tx.IsDepositTx(), tx.To())
if l1Cost != nil {
txGasCost = new(big.Int).Add(txGasCost, l1Cost) // gas fee sponsor must sponsor additional l1Cost fee
}
sponsorAmount, _ := types.CalculateSponsorPercentAmount(metaTxParams, txGasCost)
if pool.currentState.GetBalance(metaTxParams.GasFeeSponsor).Cmp(sponsorAmount) >= 0 {
var sponsorAmountAccumulated *big.Int
sponsorAmountAccumulated, ok := sponsorCostSumPerSponsor[metaTxParams.GasFeeSponsor]
if !ok {
sponsorAmountAccumulated = big.NewInt(0)
}
sponsorAmountAccumulated = big.NewInt(0).Add(sponsorAmountAccumulated, sponsorAmount)
sponsorCostSumPerSponsor[metaTxParams.GasFeeSponsor] = sponsorAmountAccumulated
if pool.currentState.GetBalance(metaTxParams.GasFeeSponsor).Cmp(sponsorAmountAccumulated) >= 0 {
sponsorCostSum = new(big.Int).Add(sponsorCostSum, sponsorAmount)
} else {
invalidMetaTxs = append(invalidMetaTxs, tx)
continue
}
}
return invalidMetaTxs, sponsorCostSum
Expand Down

0 comments on commit 2619376

Please sign in to comment.