diff --git a/core/tx_list.go b/core/tx_list.go index 523d24430b..030c4cd300 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -290,7 +290,7 @@ func (l *txList) Forward(threshold uint64) types.Transactions { // a point in calculating all the costs or if the balance covers all. If the threshold // is lower than the costgas cap, the caps will be reset to a new high after removing // the newly invalidated transactions. -func (l *txList) Filter(costLimit *big.Int, gasLimit uint64, trc21Issuers map[common.Address]*big.Int) (types.Transactions, types.Transactions) { +func (l *txList) Filter(costLimit *big.Int, gasLimit uint64, trc21Issuers map[common.Address]*big.Int, number *big.Int) (types.Transactions, types.Transactions) { // If all transactions are below the threshold, short circuit if l.costcap.Cmp(costLimit) <= 0 && l.gascap <= gasLimit { return nil, nil @@ -303,7 +303,7 @@ func (l *txList) Filter(costLimit *big.Int, gasLimit uint64, trc21Issuers map[co maximum := costLimit if tx.To() != nil { if feeCapacity, ok := trc21Issuers[*tx.To()]; ok { - return new(big.Int).Add(costLimit, feeCapacity).Cmp(tx.TRC21Cost()) < 0 || tx.Gas() > gasLimit + return new(big.Int).Add(costLimit, feeCapacity).Cmp(tx.TxCost(number)) < 0 || tx.Gas() > gasLimit } } return tx.Cost().Cmp(maximum) > 0 || tx.Gas() > gasLimit diff --git a/core/tx_pool.go b/core/tx_pool.go index d7a97ee1c2..7866371827 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -645,8 +645,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { if !state.ValidateTRC21Tx(pool.pendingState.StateDB, from, *tx.To(), tx.Data()) { return ErrInsufficientFunds } - cost = tx.TRC21Cost() - minGasPrice = common.TRC21GasPrice + cost = tx.TxCost(number) } } if new(big.Int).Add(balance, feeCapacity).Cmp(cost) < 0 { @@ -1070,7 +1069,11 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) { pool.priced.Removed() } // Drop all transactions that are too costly (low balance or out of gas) - drops, _ := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas, pool.trc21FeeCapacity) + var number *big.Int = nil + if pool.chain.CurrentHeader() != nil { + number = pool.chain.CurrentHeader().Number + } + drops, _ := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas, pool.trc21FeeCapacity, number) for _, tx := range drops { hash := tx.Hash() log.Trace("Removed unpayable queued transaction", "hash", hash) @@ -1228,7 +1231,11 @@ func (pool *TxPool) demoteUnexecutables() { pool.priced.Removed() } // Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later - drops, invalids := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas, pool.trc21FeeCapacity) + var number *big.Int = nil + if pool.chain.CurrentHeader() != nil { + number = pool.chain.CurrentHeader().Number + } + drops, invalids := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas, pool.trc21FeeCapacity, number) for _, tx := range drops { hash := tx.Hash() log.Trace("Removed unpayable pending transaction", "hash", hash) diff --git a/core/types/transaction.go b/core/types/transaction.go index 6c94f1b6cd..57f69ea0d8 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -293,8 +293,8 @@ func (tx *Transaction) Cost() *big.Int { } // Cost returns amount + gasprice * gaslimit. -func (tx *Transaction) TRC21Cost() *big.Int { - total := new(big.Int).Mul(common.TRC21GasPrice, new(big.Int).SetUint64(tx.data.GasLimit)) +func (tx *Transaction) TxCost(number *big.Int) *big.Int { + total := new(big.Int).Mul(common.GetGasPrice(number), new(big.Int).SetUint64(tx.data.GasLimit)) total.Add(total, tx.data.Amount) return total }