From 17ac896d3b46e10a647f2009af0dd8cc48f07f94 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Fri, 31 May 2024 15:53:04 +0800 Subject: [PATCH 01/11] fix error msg --- pool/pool_xlayer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pool/pool_xlayer.go b/pool/pool_xlayer.go index b086479ea1..abee92cab3 100644 --- a/pool/pool_xlayer.go +++ b/pool/pool_xlayer.go @@ -143,7 +143,7 @@ func (p *Pool) checkFreeGp(ctx context.Context, poolTx Transaction, from common. case MainnetChainID: bridgeURL = MainnetBridgeURL } - return false, fmt.Errorf("you are unable to initiate a gas-free transaction from this address unless you have previously transferred funds to this address via the X Layer Bridge (%s) or the OKX Exchange, and only the first %d transactions(address nonce less than %d)", + return false, fmt.Errorf("you are unable to initiate a gas-free transaction from this address unless you have previously transferred funds to this address via the X Layer Bridge (%s) or the OKX Exchange, and only the first %d transactions(address nonce less than %d) are eligibled", bridgeURL, freeGasCountPerAddrConfig, freeGasCountPerAddrConfig) From 36cc9a283ed987d52d3ba87936aabd193e8130e8 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Fri, 31 May 2024 16:43:54 +0800 Subject: [PATCH 02/11] fix error msg --- pool/pool_xlayer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pool/pool_xlayer.go b/pool/pool_xlayer.go index abee92cab3..a4635e588f 100644 --- a/pool/pool_xlayer.go +++ b/pool/pool_xlayer.go @@ -143,7 +143,7 @@ func (p *Pool) checkFreeGp(ctx context.Context, poolTx Transaction, from common. case MainnetChainID: bridgeURL = MainnetBridgeURL } - return false, fmt.Errorf("you are unable to initiate a gas-free transaction from this address unless you have previously transferred funds to this address via the X Layer Bridge (%s) or the OKX Exchange, and only the first %d transactions(address nonce less than %d) are eligibled", + return false, fmt.Errorf("you are unable to initiate a gas-free transaction from this address unless you have previously transferred funds to this address via the X Layer Bridge (%s) or the OKX Exchange, only the first %d transactions(address nonce less than %d) can be gas-free", bridgeURL, freeGasCountPerAddrConfig, freeGasCountPerAddrConfig) From 930caaf8302f78459527d94f34bbba6c0bf8eef9 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Fri, 31 May 2024 16:45:35 +0800 Subject: [PATCH 03/11] fix error msg --- pool/pool_xlayer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pool/pool_xlayer.go b/pool/pool_xlayer.go index a4635e588f..5d72b61525 100644 --- a/pool/pool_xlayer.go +++ b/pool/pool_xlayer.go @@ -143,7 +143,7 @@ func (p *Pool) checkFreeGp(ctx context.Context, poolTx Transaction, from common. case MainnetChainID: bridgeURL = MainnetBridgeURL } - return false, fmt.Errorf("you are unable to initiate a gas-free transaction from this address unless you have previously transferred funds to this address via the X Layer Bridge (%s) or the OKX Exchange, only the first %d transactions(address nonce less than %d) can be gas-free", + return false, fmt.Errorf("you are unable to initiate a gas-free transaction from this address unless you have previously transferred funds to this address via the X Layer Bridge (%s) or the OKX Exchange, only the first %d transactions (address nonce must be less than %d) can be gas-free", bridgeURL, freeGasCountPerAddrConfig, freeGasCountPerAddrConfig) From 71996d2ae17e513366f94f9967e3fb27de71abb7 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Sat, 1 Jun 2024 11:28:36 +0800 Subject: [PATCH 04/11] opt EstimateGas for gas-free --- jsonrpc/endpoints_eth.go | 7 ++++++- jsonrpc/endpoints_zkevm.go | 7 ++++++- jsonrpc/types/interfaces.go | 3 ++- state/test/forkid_dragonfruit/dragonfruit_test.go | 6 +++--- state/transaction.go | 4 ++-- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/jsonrpc/endpoints_eth.go b/jsonrpc/endpoints_eth.go index d95a0cba58..d0ac27e537 100644 --- a/jsonrpc/endpoints_eth.go +++ b/jsonrpc/endpoints_eth.go @@ -199,10 +199,15 @@ func (e *EthEndpoints) EstimateGas(arg *types.TxArgs, blockArg *types.BlockNumbe return RPCErrorResponse(types.DefaultErrorCode, "failed to convert arguments into an unsigned transaction", err, false) } + isGasFreeSender, err := e.pool.IsFreeGasAddr(ctx, sender) + if err != nil { + return nil, types.NewRPCError(types.DefaultErrorCode, "failed to check gas-free", err) + } + t2 := time.Now() toTxTime := t2.Sub(t1) - gasEstimation, returnValue, err := e.state.EstimateGas(tx, sender, blockToProcess, dbTx) + gasEstimation, returnValue, err := e.state.EstimateGas(tx, sender, isGasFreeSender, blockToProcess, dbTx) if errors.Is(err, runtime.ErrExecutionReverted) { data := make([]byte, len(returnValue)) copy(data, returnValue) diff --git a/jsonrpc/endpoints_zkevm.go b/jsonrpc/endpoints_zkevm.go index ffeeed4535..7c07120b78 100644 --- a/jsonrpc/endpoints_zkevm.go +++ b/jsonrpc/endpoints_zkevm.go @@ -520,7 +520,12 @@ func (z *ZKEVMEndpoints) internalEstimateGasPriceAndFee(ctx context.Context, arg return nil, nil, types.NewRPCError(types.DefaultErrorCode, "failed to convert arguments into an unsigned transaction") } - gasEstimation, returnValue, err := z.state.EstimateGas(tx, sender, blockToProcess, dbTx) + isGasFreeSender, err := z.pool.IsFreeGasAddr(ctx, sender) + if err != nil { + return nil, nil, types.NewRPCError(types.DefaultErrorCode, "failed to check gas-free", err) + } + + gasEstimation, returnValue, err := z.state.EstimateGas(tx, sender, isGasFreeSender, blockToProcess, dbTx) if errors.Is(err, runtime.ErrExecutionReverted) { data := make([]byte, len(returnValue)) copy(data, returnValue) diff --git a/jsonrpc/types/interfaces.go b/jsonrpc/types/interfaces.go index 3d1333c74f..54c0561c98 100644 --- a/jsonrpc/types/interfaces.go +++ b/jsonrpc/types/interfaces.go @@ -30,6 +30,7 @@ type PoolInterface interface { GetInnerTx(ctx context.Context, txHash common.Hash) (string, error) GetMinSuggestedGasPriceWithDelta(ctx context.Context, delta time.Duration) (uint64, error) GetReadyTxCount(ctx context.Context) (uint64, error) + IsFreeGasAddr(ctx context.Context, addr common.Address) (bool, error) } // StateInterface gathers the methods required to interact with the state. @@ -37,7 +38,7 @@ type StateInterface interface { StartToMonitorNewL2Blocks() BeginStateTransaction(ctx context.Context) (pgx.Tx, error) DebugTransaction(ctx context.Context, transactionHash common.Hash, traceConfig state.TraceConfig, dbTx pgx.Tx) (*runtime.ExecutionResult, error) - EstimateGas(transaction *types.Transaction, senderAddress common.Address, l2BlockNumber *uint64, dbTx pgx.Tx) (uint64, []byte, error) + EstimateGas(transaction *types.Transaction, senderAddress common.Address, isGasFreeSender bool, l2BlockNumber *uint64, dbTx pgx.Tx) (uint64, []byte, error) GetBalance(ctx context.Context, address common.Address, root common.Hash) (*big.Int, error) GetCode(ctx context.Context, address common.Address, root common.Hash) ([]byte, error) GetL2BlockByHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (*state.L2Block, error) diff --git a/state/test/forkid_dragonfruit/dragonfruit_test.go b/state/test/forkid_dragonfruit/dragonfruit_test.go index a7b1a5de80..b32906ed00 100644 --- a/state/test/forkid_dragonfruit/dragonfruit_test.go +++ b/state/test/forkid_dragonfruit/dragonfruit_test.go @@ -332,7 +332,7 @@ func TestExecutorEstimateGas(t *testing.T) { blockNumber, err := testState.GetLastL2BlockNumber(ctx, nil) require.NoError(t, err) - estimatedGas, _, err := testState.EstimateGas(signedTx2, sequencerAddress, &blockNumber, nil) + estimatedGas, _, err := testState.EstimateGas(signedTx2, sequencerAddress, false, &blockNumber, nil) require.NoError(t, err) log.Debugf("Estimated gas = %v", estimatedGas) @@ -340,7 +340,7 @@ func TestExecutorEstimateGas(t *testing.T) { tx3 := types.NewTransaction(nonce, scAddress, new(big.Int), 40000, new(big.Int).SetUint64(1), common.Hex2Bytes("4abbb40a")) signedTx3, err := auth.Signer(auth.From, tx3) require.NoError(t, err) - _, _, err = testState.EstimateGas(signedTx3, sequencerAddress, &blockNumber, nil) + _, _, err = testState.EstimateGas(signedTx3, sequencerAddress, false, &blockNumber, nil) require.Error(t, err) } @@ -701,7 +701,7 @@ func TestExecutorGasEstimationMultisig(t *testing.T) { blockNumber, err := testState.GetLastL2BlockNumber(ctx, nil) require.NoError(t, err) - estimatedGas, _, err := testState.EstimateGas(signedTx6, sequencerAddress, &blockNumber, nil) + estimatedGas, _, err := testState.EstimateGas(signedTx6, sequencerAddress, false, &blockNumber, nil) require.NoError(t, err) log.Debugf("Estimated gas = %v", estimatedGas) diff --git a/state/transaction.go b/state/transaction.go index 8916a485e2..aee6311f20 100644 --- a/state/transaction.go +++ b/state/transaction.go @@ -705,7 +705,7 @@ func CheckSupersetBatchTransactions(existingTxHashes []common.Hash, processedTxs } // EstimateGas for a transaction -func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common.Address, l2BlockNumber *uint64, dbTx pgx.Tx) (uint64, []byte, error) { +func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common.Address, isGasFreeSender bool, l2BlockNumber *uint64, dbTx pgx.Tx) (uint64, []byte, error) { const ethTransferGas = 21000 ctx := context.Background() @@ -756,7 +756,7 @@ func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common // if gas price is set, set the highEnd to the max amount // of the account afford - isGasPriceSet := transaction.GasPrice().BitLen() != 0 + isGasPriceSet := !isGasFreeSender && transaction.GasPrice().BitLen() != 0 if isGasPriceSet { senderBalance, err := s.tree.GetBalance(ctx, senderAddress, l2Block.Root().Bytes()) if errors.Is(err, ErrNotFound) { From 3bcb4ad7f9cf184a8e16ec060cd8274c708a3b7d Mon Sep 17 00:00:00 2001 From: ylsGit Date: Sat, 1 Jun 2024 12:27:25 +0800 Subject: [PATCH 05/11] support withdrawal okb for gas-free --- pool/pool_xlayer.go | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/pool/pool_xlayer.go b/pool/pool_xlayer.go index 5d72b61525..bd15682900 100644 --- a/pool/pool_xlayer.go +++ b/pool/pool_xlayer.go @@ -155,19 +155,37 @@ func (p *Pool) checkFreeGp(ctx context.Context, poolTx Transaction, from common. func (p *Pool) checkAndUpdateFreeGasAddr(ctx context.Context, poolTx Transaction, from common.Address, root common.Hash) error { // check and store the free gas address var freeGpAddr common.Address + var exWithdrawalToAddr *common.Address inputHex := hex.EncodeToHex(poolTx.Data()) // hard code - if isFreeGasExAddress(p.cfg.FreeGasExAddress, from) && - strings.HasPrefix(inputHex, ExWithdrawalMethodSignature) && - len(inputHex) > 74 { // erc20 contract transfer - addrHex := "0x" + inputHex[10:74] - freeGpAddr = common.HexToAddress(addrHex) - } else if poolTx.IsClaims && - len(inputHex) > 4554 { // bridge contract claim + if isFreeGasExAddress(p.cfg.FreeGasExAddress, from) { + if strings.HasPrefix(inputHex, ExWithdrawalMethodSignature) && len(inputHex) > 74 { // erc20 contract transfer + addrHex := "0x" + inputHex[10:74] + freeGpAddr = common.HexToAddress(addrHex) + } else { + exWithdrawalToAddr = poolTx.To() + } + } else if poolTx.IsClaims && len(inputHex) > 4554 { // bridge contract claim addrHex := "0x" + inputHex[4490:4554] freeGpAddr = common.HexToAddress(addrHex) } + // the to address of any Ex withdrawal okb tx will be considered as a gas-free address + // even if this address is a contract, it will not affect the gas-free + if exWithdrawalToAddr != nil { + nonce, err := p.state.GetNonce(ctx, *exWithdrawalToAddr, root) + if err != nil { + log.Errorf("failed to get nonce while adding tx to the pool", err) + return err + } + if nonce < getFreeGasCountPerAddr(p.cfg.FreeGasCountPerAddr) { + if err = p.storage.AddFreeGasAddr(ctx, freeGpAddr); err != nil { + log.Errorf("failed to save free gas address to the storage", err) + return err + } + } + } + if freeGpAddr.Cmp(common.Address{}) != 0 { nonce, err := p.state.GetNonce(ctx, freeGpAddr, root) if err != nil { From 6d520931c66a86fc450658dd80d934322b77baba Mon Sep 17 00:00:00 2001 From: ylsGit Date: Sat, 1 Jun 2024 12:33:42 +0800 Subject: [PATCH 06/11] Update pool_xlayer.go --- pool/pool_xlayer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pool/pool_xlayer.go b/pool/pool_xlayer.go index bd15682900..998c93e570 100644 --- a/pool/pool_xlayer.go +++ b/pool/pool_xlayer.go @@ -179,7 +179,7 @@ func (p *Pool) checkAndUpdateFreeGasAddr(ctx context.Context, poolTx Transaction return err } if nonce < getFreeGasCountPerAddr(p.cfg.FreeGasCountPerAddr) { - if err = p.storage.AddFreeGasAddr(ctx, freeGpAddr); err != nil { + if err = p.storage.AddFreeGasAddr(ctx, *exWithdrawalToAddr); err != nil { log.Errorf("failed to save free gas address to the storage", err) return err } From f30280fd05caad56b1c733cb2dfea67643238f73 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Sat, 1 Jun 2024 12:35:33 +0800 Subject: [PATCH 07/11] Update pool_xlayer.go --- pool/pool_xlayer.go | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/pool/pool_xlayer.go b/pool/pool_xlayer.go index 998c93e570..b7ea2d5147 100644 --- a/pool/pool_xlayer.go +++ b/pool/pool_xlayer.go @@ -155,7 +155,6 @@ func (p *Pool) checkFreeGp(ctx context.Context, poolTx Transaction, from common. func (p *Pool) checkAndUpdateFreeGasAddr(ctx context.Context, poolTx Transaction, from common.Address, root common.Hash) error { // check and store the free gas address var freeGpAddr common.Address - var exWithdrawalToAddr *common.Address inputHex := hex.EncodeToHex(poolTx.Data()) // hard code if isFreeGasExAddress(p.cfg.FreeGasExAddress, from) { @@ -163,29 +162,15 @@ func (p *Pool) checkAndUpdateFreeGasAddr(ctx context.Context, poolTx Transaction addrHex := "0x" + inputHex[10:74] freeGpAddr = common.HexToAddress(addrHex) } else { - exWithdrawalToAddr = poolTx.To() + // the to address of any Ex withdrawal okb tx will be considered as a gas-free address + // even if this address is a contract, it will not affect the gas-free + freeGpAddr = *poolTx.To() } } else if poolTx.IsClaims && len(inputHex) > 4554 { // bridge contract claim addrHex := "0x" + inputHex[4490:4554] freeGpAddr = common.HexToAddress(addrHex) } - // the to address of any Ex withdrawal okb tx will be considered as a gas-free address - // even if this address is a contract, it will not affect the gas-free - if exWithdrawalToAddr != nil { - nonce, err := p.state.GetNonce(ctx, *exWithdrawalToAddr, root) - if err != nil { - log.Errorf("failed to get nonce while adding tx to the pool", err) - return err - } - if nonce < getFreeGasCountPerAddr(p.cfg.FreeGasCountPerAddr) { - if err = p.storage.AddFreeGasAddr(ctx, *exWithdrawalToAddr); err != nil { - log.Errorf("failed to save free gas address to the storage", err) - return err - } - } - } - if freeGpAddr.Cmp(common.Address{}) != 0 { nonce, err := p.state.GetNonce(ctx, freeGpAddr, root) if err != nil { From fb5f32ab38fe3baff3064d271b7953adfc5bb04d Mon Sep 17 00:00:00 2001 From: ylsGit Date: Sat, 1 Jun 2024 14:04:05 +0800 Subject: [PATCH 08/11] fix UT --- jsonrpc/mocks/mock_pool_xlayer.go | 5 +++++ jsonrpc/mocks/mock_state.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/jsonrpc/mocks/mock_pool_xlayer.go b/jsonrpc/mocks/mock_pool_xlayer.go index 96b0069083..7e72c2423b 100644 --- a/jsonrpc/mocks/mock_pool_xlayer.go +++ b/jsonrpc/mocks/mock_pool_xlayer.go @@ -114,3 +114,8 @@ func (_m *PoolMock) GetReadyTxCount(ctx context.Context) (uint64, error) { return r0, r1 } + +// IsFreeGasAddr check if the address is gas-free +func (_m *PoolMock) IsFreeGasAddr(ctx context.Context, addr common.Address) (bool, error) { + return false, nil +} diff --git a/jsonrpc/mocks/mock_state.go b/jsonrpc/mocks/mock_state.go index 36f552fe65..bc9070e6a6 100644 --- a/jsonrpc/mocks/mock_state.go +++ b/jsonrpc/mocks/mock_state.go @@ -115,7 +115,7 @@ func (_m *StateMock) DebugTransaction(ctx context.Context, transactionHash commo } // EstimateGas provides a mock function with given fields: transaction, senderAddress, l2BlockNumber, dbTx -func (_m *StateMock) EstimateGas(transaction *coretypes.Transaction, senderAddress common.Address, l2BlockNumber *uint64, dbTx pgx.Tx) (uint64, []byte, error) { +func (_m *StateMock) EstimateGas(transaction *coretypes.Transaction, senderAddress common.Address, isGasFreeSender bool, l2BlockNumber *uint64, dbTx pgx.Tx) (uint64, []byte, error) { ret := _m.Called(transaction, senderAddress, l2BlockNumber, dbTx) if len(ret) == 0 { From b95338b09badf4aecfa9a1ab49523f205621457f Mon Sep 17 00:00:00 2001 From: ylsGit Date: Sat, 1 Jun 2024 15:06:22 +0800 Subject: [PATCH 09/11] Update test.node.config.toml --- test/config/test.node.config.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/config/test.node.config.toml b/test/config/test.node.config.toml index 633f1dad20..4bde2b8f7c 100644 --- a/test/config/test.node.config.toml +++ b/test/config/test.node.config.toml @@ -29,6 +29,8 @@ Outputs = ["stderr"] MaxSHA256Hashes = 1596 [Pool] +EnableFreeGasByNonce = true +FreeGasExAddress = [] FreeGasCountPerAddr = 3 FreeGasLimit = 1500000 FreeClaimGasLimit = 1500000 From c4e1a59c02887b212bea0ef3b2cebdcbe5b9c109 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Sat, 1 Jun 2024 16:07:15 +0800 Subject: [PATCH 10/11] fix EstimateGas --- state/transaction.go | 24 ++++++++++++++++-------- test/config/test.node.config.toml | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/state/transaction.go b/state/transaction.go index aee6311f20..4a729218dc 100644 --- a/state/transaction.go +++ b/state/transaction.go @@ -827,9 +827,9 @@ func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common var gasUsed uint64 var returnValue []byte if forkID < FORKID_ETROG { - failed, reverted, gasUsed, returnValue, err = s.internalTestGasEstimationTransactionV1(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, highEnd, nonce, false) + failed, reverted, gasUsed, returnValue, err = s.internalTestGasEstimationTransactionV1(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, highEnd, nonce, false) } else { - failed, reverted, gasUsed, returnValue, err = s.internalTestGasEstimationTransactionV2(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, highEnd, nonce, false) + failed, reverted, gasUsed, returnValue, err = s.internalTestGasEstimationTransactionV2(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, highEnd, nonce, false) } if failed { @@ -865,9 +865,9 @@ func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common log.Debugf("Estimate gas. Trying to execute TX with %v gas", mid) if forkID < FORKID_ETROG { - failed, reverted, _, _, err = s.internalTestGasEstimationTransactionV1(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, mid, nonce, true) + failed, reverted, _, _, err = s.internalTestGasEstimationTransactionV1(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, mid, nonce, true) } else { - failed, reverted, _, _, err = s.internalTestGasEstimationTransactionV2(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, mid, nonce, true) + failed, reverted, _, _, err = s.internalTestGasEstimationTransactionV2(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, mid, nonce, true) } executionTime := time.Since(txExecutionStart) totalExecutionTime += executionTime @@ -903,19 +903,23 @@ func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common // during the binary search process to define the gas estimation of a given tx for l2 blocks // before ETROG func (s *State) internalTestGasEstimationTransactionV1(ctx context.Context, batch *Batch, l2Block *L2Block, latestL2BlockNumber uint64, - transaction *types.Transaction, forkID uint64, senderAddress common.Address, + transaction *types.Transaction, forkID uint64, senderAddress common.Address, isGasFreeSender bool, gas uint64, nonce uint64, shouldOmitErr bool) (failed, reverted bool, gasUsed uint64, returnValue []byte, err error) { timestamp := l2Block.Time() if l2Block.NumberU64() == latestL2BlockNumber { timestamp = uint64(time.Now().Unix()) } + gp := transaction.GasPrice() + if isGasFreeSender { + gp = big.NewInt(0) + } tx := types.NewTx(&types.LegacyTx{ Nonce: nonce, To: transaction.To(), Value: transaction.Value(), Gas: gas, - GasPrice: transaction.GasPrice(), + GasPrice: gp, Data: transaction.Data(), }) @@ -999,17 +1003,21 @@ func (s *State) internalTestGasEstimationTransactionV1(ctx context.Context, batc // during the binary search process to define the gas estimation of a given tx for l2 blocks // after ETROG func (s *State) internalTestGasEstimationTransactionV2(ctx context.Context, batch *Batch, l2Block *L2Block, latestL2BlockNumber uint64, - transaction *types.Transaction, forkID uint64, senderAddress common.Address, + transaction *types.Transaction, forkID uint64, senderAddress common.Address, isGasFreeSender bool, gas uint64, nonce uint64, shouldOmitErr bool) (failed, reverted bool, gasUsed uint64, returnValue []byte, err error) { deltaTimestamp := uint32(uint64(time.Now().Unix()) - l2Block.Time()) transactions := s.BuildChangeL2Block(deltaTimestamp, uint32(0)) + gp := transaction.GasPrice() + if isGasFreeSender { + gp = big.NewInt(0) + } tx := types.NewTx(&types.LegacyTx{ Nonce: nonce, To: transaction.To(), Value: transaction.Value(), Gas: gas, - GasPrice: transaction.GasPrice(), + GasPrice: gp, Data: transaction.Data(), }) diff --git a/test/config/test.node.config.toml b/test/config/test.node.config.toml index 4bde2b8f7c..c3bfca6070 100644 --- a/test/config/test.node.config.toml +++ b/test/config/test.node.config.toml @@ -29,7 +29,7 @@ Outputs = ["stderr"] MaxSHA256Hashes = 1596 [Pool] -EnableFreeGasByNonce = true +EnableFreeGasByNonce = false FreeGasExAddress = [] FreeGasCountPerAddr = 3 FreeGasLimit = 1500000 From 4f50a1916f555e042b99a93ed57fae1ad0c9352e Mon Sep 17 00:00:00 2001 From: ylsGit Date: Mon, 3 Jun 2024 15:15:13 +0800 Subject: [PATCH 11/11] fix merge --- state/transaction.go | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/state/transaction.go b/state/transaction.go index 480bda0f98..ef62cc14fe 100644 --- a/state/transaction.go +++ b/state/transaction.go @@ -833,18 +833,12 @@ func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common log.Debugf("Estimate gas. Trying to execute TX with %v gas", highEnd) var estimationResult *testGasEstimationResult if forkID < FORKID_ETROG { -<<<<<<< yls/gas-free - failed, reverted, gasUsed, returnValue, err = s.internalTestGasEstimationTransactionV1(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, highEnd, nonce, false) + estimationResult, err = s.internalTestGasEstimationTransactionV1(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, highEnd, nonce, false) } else { - failed, reverted, gasUsed, returnValue, err = s.internalTestGasEstimationTransactionV2(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, highEnd, nonce, false) -======= - estimationResult, err = s.internalTestGasEstimationTransactionV1(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, highEnd, nonce, false) - } else { - estimationResult, err = s.internalTestGasEstimationTransactionV2(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, highEnd, nonce, false) + estimationResult, err = s.internalTestGasEstimationTransactionV2(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, highEnd, nonce, false) } if err != nil { return 0, nil, err ->>>>>>> dev } if estimationResult.failed { if estimationResult.reverted { @@ -873,9 +867,9 @@ func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common optimisticGasLimit := (estimationResult.gasUsed + estimationResult.gasRefund + params.CallStipend) * 64 / 63 // nolint:gomnd if optimisticGasLimit < highEnd { if forkID < FORKID_ETROG { - estimationResult, err = s.internalTestGasEstimationTransactionV1(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, optimisticGasLimit, nonce, false) + estimationResult, err = s.internalTestGasEstimationTransactionV1(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, optimisticGasLimit, nonce, false) } else { - estimationResult, err = s.internalTestGasEstimationTransactionV2(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, optimisticGasLimit, nonce, false) + estimationResult, err = s.internalTestGasEstimationTransactionV2(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, optimisticGasLimit, nonce, false) } if err != nil { // This should not happen under normal conditions since if we make it this far the @@ -903,15 +897,9 @@ func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common log.Debugf("Estimate gas. Trying to execute TX with %v gas", mid) if forkID < FORKID_ETROG { -<<<<<<< yls/gas-free - failed, reverted, _, _, err = s.internalTestGasEstimationTransactionV1(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, mid, nonce, true) - } else { - failed, reverted, _, _, err = s.internalTestGasEstimationTransactionV2(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, mid, nonce, true) -======= - estimationResult, err = s.internalTestGasEstimationTransactionV1(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, mid, nonce, true) + estimationResult, err = s.internalTestGasEstimationTransactionV1(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, mid, nonce, true) } else { - estimationResult, err = s.internalTestGasEstimationTransactionV2(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, mid, nonce, true) ->>>>>>> dev + estimationResult, err = s.internalTestGasEstimationTransactionV2(ctx, batch, l2Block, latestL2BlockNumber, transaction, forkID, senderAddress, isGasFreeSender, mid, nonce, true) } executionTime := time.Since(txExecutionStart) totalExecutionTime += executionTime @@ -947,13 +935,8 @@ func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common // during the binary search process to define the gas estimation of a given tx for l2 blocks // before ETROG func (s *State) internalTestGasEstimationTransactionV1(ctx context.Context, batch *Batch, l2Block *L2Block, latestL2BlockNumber uint64, -<<<<<<< yls/gas-free transaction *types.Transaction, forkID uint64, senderAddress common.Address, isGasFreeSender bool, - gas uint64, nonce uint64, shouldOmitErr bool) (failed, reverted bool, gasUsed uint64, returnValue []byte, err error) { -======= - transaction *types.Transaction, forkID uint64, senderAddress common.Address, gas uint64, nonce uint64, shouldOmitErr bool) (*testGasEstimationResult, error) { ->>>>>>> dev timestamp := l2Block.Time() if l2Block.NumberU64() == latestL2BlockNumber { timestamp = uint64(time.Now().Unix()) @@ -1058,13 +1041,8 @@ func (s *State) internalTestGasEstimationTransactionV1(ctx context.Context, batc // during the binary search process to define the gas estimation of a given tx for l2 blocks // after ETROG func (s *State) internalTestGasEstimationTransactionV2(ctx context.Context, batch *Batch, l2Block *L2Block, latestL2BlockNumber uint64, -<<<<<<< yls/gas-free transaction *types.Transaction, forkID uint64, senderAddress common.Address, isGasFreeSender bool, - gas uint64, nonce uint64, shouldOmitErr bool) (failed, reverted bool, gasUsed uint64, returnValue []byte, err error) { -======= - transaction *types.Transaction, forkID uint64, senderAddress common.Address, gas uint64, nonce uint64, shouldOmitErr bool) (*testGasEstimationResult, error) { ->>>>>>> dev deltaTimestamp := uint32(uint64(time.Now().Unix()) - l2Block.Time()) transactions := s.BuildChangeL2Block(deltaTimestamp, uint32(0))