diff --git a/accounts/abi/bind/base.go b/accounts/abi/bind/base.go index 7d3304511a..56bf28530d 100644 --- a/accounts/abi/bind/base.go +++ b/accounts/abi/bind/base.go @@ -128,7 +128,7 @@ func (c *BoundContract) Call(opts *CallOpts, result interface{}, method string, return err } var ( - msg = XDPoSChain.CallMsg{From: opts.From, To: &c.address, Data: input, GasPrice: common.MinGasPrice, Gas: uint64(4200000)} + msg = XDPoSChain.CallMsg{From: opts.From, To: &c.address, Data: input, GasPrice: common.MinGasPrice50x, Gas: uint64(4200000)} ctx = ensureContext(opts.Context) code []byte output []byte diff --git a/cmd/XDC/config.go b/cmd/XDC/config.go index 4dad8306ae..948e59f417 100644 --- a/cmd/XDC/config.go +++ b/cmd/XDC/config.go @@ -185,6 +185,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, XDCConfig) { common.MinGasPrice = big.NewInt(gasPrice) } } + common.MinGasPrice50x = common.MinGasPrice50x.Mul(common.MinGasPrice, big.NewInt(50)) // read passwords from environment passwords := []string{} diff --git a/common/constants.go b/common/constants.go index c0d9004c67..9566b4bf42 100644 --- a/common/constants.go +++ b/common/constants.go @@ -77,6 +77,7 @@ var BaseTopUp = big.NewInt(100) var BaseRecall = big.NewInt(100) var TIPTRC21Fee = big.NewInt(38383838) var TIPTRC21FeeTestnet = big.NewInt(38383838) +var BlockNumberGas50x = big.NewInt(TIPTRC21Fee.Int64() + 30000000) var LimitTimeFinality = uint64(30) // limit in 30 block var IgnoreSignerCheckBlockArray = map[uint64]bool{ diff --git a/common/constants/constants.go.devnet b/common/constants/constants.go.devnet index bf756ca3ba..2cd660802f 100644 --- a/common/constants/constants.go.devnet +++ b/common/constants/constants.go.devnet @@ -77,6 +77,7 @@ var BaseTopUp = big.NewInt(100) var BaseRecall = big.NewInt(100) var TIPTRC21Fee = big.NewInt(13523400) var TIPTRC21FeeTestnet = big.NewInt(225000) +var BlockNumberGas50x = big.NewInt(11818181) var LimitTimeFinality = uint64(30) // limit in 30 block var IgnoreSignerCheckBlockArray = map[uint64]bool{ diff --git a/common/gas.go b/common/gas.go new file mode 100644 index 0000000000..a5b5690a76 --- /dev/null +++ b/common/gas.go @@ -0,0 +1,34 @@ +package common + +import "math/big" + +var MinGasPrice50x = big.NewInt(12500000000) +var GasPrice50x = big.NewInt(12500000000) + +func GetGasFee(blockNumber, gas uint64) *big.Int { + fee := new(big.Int).SetUint64(gas) + + if blockNumber >= BlockNumberGas50x.Uint64() { + fee = fee.Mul(fee, GasPrice50x) + } else if blockNumber > TIPTRC21Fee.Uint64() { + fee = fee.Mul(fee, TRC21GasPrice) + } + + return fee +} + +func GetGasPrice(number *big.Int) *big.Int { + if number == nil || number.Cmp(BlockNumberGas50x) < 0 { + return new(big.Int).Set(TRC21GasPrice) + } else { + return new(big.Int).Set(GasPrice50x) + } +} + +func GetMinGasPrice(number *big.Int) *big.Int { + if number == nil || number.Cmp(BlockNumberGas50x) < 0 { + return new(big.Int).Set(MinGasPrice) + } else { + return new(big.Int).Set(MinGasPrice50x) + } +} diff --git a/contracts/trc21issuer/simulation/test/main.go b/contracts/trc21issuer/simulation/test/main.go index ef2eb197e8..1ee2aff60e 100644 --- a/contracts/trc21issuer/simulation/test/main.go +++ b/contracts/trc21issuer/simulation/test/main.go @@ -4,15 +4,16 @@ import ( "context" "encoding/json" "fmt" + "log" + "math/big" + "time" + "github.com/XinFinOrg/XDPoSChain/accounts/abi/bind" "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common/hexutil" "github.com/XinFinOrg/XDPoSChain/contracts/trc21issuer" "github.com/XinFinOrg/XDPoSChain/contracts/trc21issuer/simulation" "github.com/XinFinOrg/XDPoSChain/ethclient" - "log" - "math/big" - "time" ) var ( @@ -48,11 +49,10 @@ func airDropTokenToAccountNoXDC() { if err != nil { log.Fatal("can't transaction's receipt ", err, "hash", tx.Hash().Hex()) } - fee := big.NewInt(0).SetUint64(hexutil.MustDecodeUint64(receipt["gasUsed"].(string))) - if hexutil.MustDecodeUint64(receipt["blockNumber"].(string)) > common.TIPTRC21Fee.Uint64() { - fee = fee.Mul(fee, common.TRC21GasPrice) - } - fmt.Println("fee", fee.Uint64(), "number", hexutil.MustDecodeUint64(receipt["blockNumber"].(string))) + gasUsed := hexutil.MustDecodeUint64(receipt["gasUsed"].(string)) + blockNumber := hexutil.MustDecodeUint64(receipt["blockNumber"].(string)) + fee := common.GetGasFee(blockNumber, gasUsed) + fmt.Println("fee", fee.Uint64(), "number", blockNumber) remainFee = big.NewInt(0).Sub(remainFee, fee) //check balance fee balanceIssuerFee, err := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr) @@ -111,11 +111,10 @@ func testTransferTRC21TokenWithAccountNoXDC() { if err != nil { log.Fatal("can't transaction's receipt ", err, "hash", tx.Hash().Hex()) } - fee := big.NewInt(0).SetUint64(hexutil.MustDecodeUint64(receipt["gasUsed"].(string))) - if hexutil.MustDecodeUint64(receipt["blockNumber"].(string)) > common.TIPTRC21Fee.Uint64() { - fee = fee.Mul(fee, common.TRC21GasPrice) - } - fmt.Println("fee", fee.Uint64(), "number", hexutil.MustDecodeUint64(receipt["blockNumber"].(string))) + gasUsed := hexutil.MustDecodeUint64(receipt["gasUsed"].(string)) + blockNumber := hexutil.MustDecodeUint64(receipt["blockNumber"].(string)) + fee := common.GetGasFee(blockNumber, gasUsed) + fmt.Println("fee", fee.Uint64(), "number", blockNumber) remainFee = big.NewInt(0).Sub(remainFee, fee) //check balance fee balanceIssuerFee, err := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr) @@ -178,11 +177,10 @@ func testTransferTrc21Fail() { if err != nil { log.Fatal("can't transaction's receipt ", err, "hash", tx.Hash().Hex()) } - fee := big.NewInt(0).SetUint64(hexutil.MustDecodeUint64(receipt["gasUsed"].(string))) - if hexutil.MustDecodeUint64(receipt["blockNumber"].(string)) > common.TIPTRC21Fee.Uint64() { - fee = fee.Mul(fee, common.TRC21GasPrice) - } - fmt.Println("fee", fee.Uint64(), "number", hexutil.MustDecodeUint64(receipt["blockNumber"].(string))) + gasUsed := hexutil.MustDecodeUint64(receipt["gasUsed"].(string)) + blockNumber := hexutil.MustDecodeUint64(receipt["blockNumber"].(string)) + fee := common.GetGasFee(blockNumber, gasUsed) + fmt.Println("fee", fee.Uint64(), "number", blockNumber) remainFee = big.NewInt(0).Sub(remainFee, fee) //check balance fee balanceIssuerFee, err = trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr) diff --git a/contracts/trc21issuer/trc21issuer_test.go b/contracts/trc21issuer/trc21issuer_test.go index e28344caf0..e0744b26d1 100644 --- a/contracts/trc21issuer/trc21issuer_test.go +++ b/contracts/trc21issuer/trc21issuer_test.go @@ -1,13 +1,14 @@ package trc21issuer import ( + "math/big" + "testing" + "github.com/XinFinOrg/XDPoSChain/accounts/abi/bind" "github.com/XinFinOrg/XDPoSChain/accounts/abi/bind/backends" "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/core" "github.com/XinFinOrg/XDPoSChain/crypto" - "math/big" - "testing" ) var ( @@ -81,10 +82,7 @@ func TestFeeTxWithTRC21Token(t *testing.T) { if err != nil { t.Fatal("can't transaction's receipt ", err, "hash", tx.Hash()) } - fee := big.NewInt(0).SetUint64(receipt.GasUsed) - if receipt.Logs[0].BlockNumber > common.TIPTRC21Fee.Uint64() { - fee = fee.Mul(fee, common.TRC21GasPrice) - } + fee := common.GetGasFee(receipt.Logs[0].BlockNumber, receipt.GasUsed) remainFee := big.NewInt(0).Sub(minApply, fee) // check balance trc21 again @@ -133,10 +131,7 @@ func TestFeeTxWithTRC21Token(t *testing.T) { if err != nil { t.Fatal("can't transaction's receipt ", err, "hash", tx.Hash()) } - fee = big.NewInt(0).SetUint64(receipt.GasUsed) - if receipt.Logs[0].BlockNumber > common.TIPTRC21Fee.Uint64() { - fee = fee.Mul(fee, common.TRC21GasPrice) - } + fee = common.GetGasFee(receipt.Logs[0].BlockNumber, receipt.GasUsed) remainFee = big.NewInt(0).Sub(remainFee, fee) //check balance fee balanceIssuerFee, err = trc21Issuer.GetTokenCapacity(trc21TokenAddr) diff --git a/core/chain_makers.go b/core/chain_makers.go index a19cf0c5a5..348d68d168 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -108,10 +108,7 @@ func (b *BlockGen) AddTxWithChain(bc *BlockChain, tx *types.Transaction) { b.txs = append(b.txs, tx) b.receipts = append(b.receipts, receipt) if tokenFeeUsed { - fee := new(big.Int).SetUint64(gas) - if b.header.Number.Cmp(common.TIPTRC21Fee) > 0 { - fee = fee.Mul(fee, common.TRC21GasPrice) - } + fee := common.GetGasFee(b.header.Number.Uint64(), gas) state.UpdateTRC21Fee(b.statedb, map[common.Address]*big.Int{*tx.To(): new(big.Int).Sub(feeCapacity[*tx.To()], new(big.Int).SetUint64(gas))}, fee) } } diff --git a/core/state_processor.go b/core/state_processor.go index 97e45f3f6a..acfec0c8fd 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -120,10 +120,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, tra receipts = append(receipts, receipt) allLogs = append(allLogs, receipt.Logs...) if tokenFeeUsed { - fee := new(big.Int).SetUint64(gas) - if block.Header().Number.Cmp(common.TIPTRC21Fee) > 0 { - fee = fee.Mul(fee, common.TRC21GasPrice) - } + fee := common.GetGasFee(block.Header().Number.Uint64(), gas) balanceFee[*tx.To()] = new(big.Int).Sub(balanceFee[*tx.To()], fee) balanceUpdated[*tx.To()] = balanceFee[*tx.To()] totalFeeUsed = totalFeeUsed.Add(totalFeeUsed, fee) @@ -201,10 +198,7 @@ func (p *StateProcessor) ProcessBlockNoValidator(cBlock *CalculatedBlock, stated receipts[i] = receipt allLogs = append(allLogs, receipt.Logs...) if tokenFeeUsed { - fee := new(big.Int).SetUint64(gas) - if block.Header().Number.Cmp(common.TIPTRC21Fee) > 0 { - fee = fee.Mul(fee, common.TRC21GasPrice) - } + fee := common.GetGasFee(block.Header().Number.Uint64(), gas) balanceFee[*tx.To()] = new(big.Int).Sub(balanceFee[*tx.To()], fee) balanceUpdated[*tx.To()] = balanceFee[*tx.To()] totalFeeUsed = totalFeeUsed.Add(totalFeeUsed, fee) 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 abb55e4948..7866371827 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -632,7 +632,11 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { // cost == V + GP * GL balance := pool.currentState.GetBalance(from) cost := tx.Cost() - minGasPrice := common.MinGasPrice + var number *big.Int = nil + if pool.chain.CurrentHeader() != nil { + number = pool.chain.CurrentHeader().Number + } + minGasPrice := common.GetMinGasPrice(number) feeCapacity := big.NewInt(0) if tx.To() != nil { @@ -641,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 { @@ -1066,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) @@ -1224,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 1a87a679a9..03f1bbe39a 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -262,7 +262,9 @@ func (tx *Transaction) AsMessage(s Signer, balanceFee *big.Int, number *big.Int) var err error msg.from, err = Sender(s, tx) if balanceFee != nil { - if number.Cmp(common.TIPTRC21Fee) > 0 { + if number.Cmp(common.BlockNumberGas50x) >= 0 { + msg.gasPrice = common.GasPrice50x + } else if number.Cmp(common.TIPTRC21Fee) > 0 { msg.gasPrice = common.TRC21GasPrice } else { msg.gasPrice = common.TRC21GasPriceBefore @@ -291,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 } @@ -700,9 +702,9 @@ type Message struct { balanceTokenFee *big.Int } -func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool, balanceTokenFee *big.Int) Message { +func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool, balanceTokenFee *big.Int, number *big.Int) Message { if balanceTokenFee != nil { - gasPrice = common.TRC21GasPrice + gasPrice = common.GetGasPrice(number) } return Message{ from: from, diff --git a/eth/api_tracer.go b/eth/api_tracer.go index be95e78d87..218781b57b 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -706,10 +706,7 @@ func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, ree } if tokenFeeUsed { - fee := new(big.Int).SetUint64(gas) - if block.Header().Number.Cmp(common.TIPTRC21Fee) > 0 { - fee = fee.Mul(fee, common.TRC21GasPrice) - } + fee := common.GetGasFee(block.Header().Number.Uint64(), gas) feeCapacity[*tx.To()] = new(big.Int).Sub(feeCapacity[*tx.To()], fee) balanceUpdated[*tx.To()] = feeCapacity[*tx.To()] totalFeeUsed = totalFeeUsed.Add(totalFeeUsed, fee) diff --git a/eth/gasprice/gasprice.go b/eth/gasprice/gasprice.go index fec29cd436..8dfaeec43a 100644 --- a/eth/gasprice/gasprice.go +++ b/eth/gasprice/gasprice.go @@ -141,7 +141,7 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) { } // Check gas price min. - minGasPrice := common.MinGasPrice + minGasPrice := common.GetMinGasPrice(head.Number) if price.Cmp(minGasPrice) < 0 { price = new(big.Int).Set(minGasPrice) } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 9facea5937..1a0ec61881 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1066,7 +1066,7 @@ func (s *PublicBlockChainAPI) doCall(ctx context.Context, args CallArgs, blockNr balanceTokenFee := big.NewInt(0).SetUint64(gas) balanceTokenFee = balanceTokenFee.Mul(balanceTokenFee, gasPrice) // Create new call message - msg := types.NewMessage(addr, args.To, 0, args.Value.ToInt(), gas, gasPrice, args.Data, false, balanceTokenFee) + msg := types.NewMessage(addr, args.To, 0, args.Value.ToInt(), gas, gasPrice, args.Data, false, balanceTokenFee, header.Number) // Setup context so it may be cancelled the call has completed // or, in case of unmetered gas, setup a context with a timeout. diff --git a/les/odr_test.go b/les/odr_test.go index a9eb41baeb..bbaa7c0dfa 100644 --- a/les/odr_test.go +++ b/les/odr_test.go @@ -133,7 +133,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai if value, ok := feeCapacity[testContractAddr]; ok { balanceTokenFee = value } - msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, balanceTokenFee)} + msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, balanceTokenFee, header.Number)} context := core.NewEVMContext(msg, header, bc, nil) vmenv := vm.NewEVM(context, statedb, nil, config, vm.Config{}) @@ -153,7 +153,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai if value, ok := feeCapacity[testContractAddr]; ok { balanceTokenFee = value } - msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, balanceTokenFee)} + msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, balanceTokenFee, header.Number)} context := core.NewEVMContext(msg, header, lc, nil) vmenv := vm.NewEVM(context, statedb, nil, config, vm.Config{}) gp := new(core.GasPool).AddGas(math.MaxUint64) diff --git a/light/odr_test.go b/light/odr_test.go index da50255041..4905260ade 100644 --- a/light/odr_test.go +++ b/light/odr_test.go @@ -183,7 +183,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain if value, ok := feeCapacity[testContractAddr]; ok { balanceTokenFee = value } - msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, new(big.Int), data, false, balanceTokenFee)} + msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, new(big.Int), data, false, balanceTokenFee, header.Number)} context := core.NewEVMContext(msg, header, chain, nil) vmenv := vm.NewEVM(context, st, nil, config, vm.Config{}) gp := new(core.GasPool).AddGas(math.MaxUint64) diff --git a/miner/worker.go b/miner/worker.go index 76b5562b00..bc3982094e 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -931,10 +931,7 @@ func (env *Work) commitTransactions(mux *event.TypeMux, balanceFee map[common.Ad log.Debug("Add Special Transaction failed, account skipped", "hash", tx.Hash(), "sender", from, "nonce", tx.Nonce(), "to", tx.To(), "err", err) } if tokenFeeUsed { - fee := new(big.Int).SetUint64(gas) - if env.header.Number.Cmp(common.TIPTRC21Fee) > 0 { - fee = fee.Mul(fee, common.TRC21GasPrice) - } + fee := common.GetGasFee(env.header.Number.Uint64(), gas) balanceFee[*tx.To()] = new(big.Int).Sub(balanceFee[*tx.To()], fee) balanceUpdated[*tx.To()] = balanceFee[*tx.To()] totalFeeUsed = totalFeeUsed.Add(totalFeeUsed, fee) @@ -1049,10 +1046,7 @@ func (env *Work) commitTransactions(mux *event.TypeMux, balanceFee map[common.Ad txs.Shift() } if tokenFeeUsed { - fee := new(big.Int).SetUint64(gas) - if env.header.Number.Cmp(common.TIPTRC21Fee) > 0 { - fee = fee.Mul(fee, common.TRC21GasPrice) - } + fee := common.GetGasFee(env.header.Number.Uint64(), gas) balanceFee[*tx.To()] = new(big.Int).Sub(balanceFee[*tx.To()], fee) balanceUpdated[*tx.To()] = balanceFee[*tx.To()] totalFeeUsed = totalFeeUsed.Add(totalFeeUsed, fee) diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 301fba6aef..f0db5bd40e 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -131,7 +131,7 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateD statedb := MakePreState(db, t.json.Pre) post := t.json.Post[subtest.Fork][subtest.Index] - msg, err := t.json.Tx.toMessage(post) + msg, err := t.json.Tx.toMessage(post, block.Number()) if err != nil { return nil, err } @@ -190,7 +190,7 @@ func (t *StateTest) genesis(config *params.ChainConfig) *core.Genesis { } } -func (tx *stTransaction) toMessage(ps stPostState) (core.Message, error) { +func (tx *stTransaction) toMessage(ps stPostState, number *big.Int) (core.Message, error) { // Derive sender from private key if present. var from common.Address if len(tx.PrivateKey) > 0 { @@ -235,7 +235,7 @@ func (tx *stTransaction) toMessage(ps stPostState) (core.Message, error) { if err != nil { return nil, fmt.Errorf("invalid tx data %q", dataHex) } - msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, data, true, nil) + msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, data, true, nil, number) return msg, nil }