diff --git a/core/token_gas.go b/core/token_gas.go index 8206f29e6..25c8cb48f 100644 --- a/core/token_gas.go +++ b/core/token_gas.go @@ -1,7 +1,6 @@ package core import ( - "bytes" "fmt" "math/big" @@ -63,7 +62,7 @@ func GetAltTokenBalance(evm *vm.EVM, tokenID uint16, user common.Address) (*big. return nil, fmt.Errorf("failed to get token address for token ID %d: %v", tokenID, err) } balance := new(big.Int) - if !bytes.Equal(info.BalanceSlot.Bytes(), common.Hash{}.Bytes()) { + if info.HasSlot { // balance slot exist balance, _, err = fees.GetAltTokenBalanceFromSlot(evm.StateDB, info.TokenAddress, user, info.BalanceSlot) if err != nil { diff --git a/core/tx_list.go b/core/tx_list.go index cc1016b69..e7edda2e8 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -357,7 +357,7 @@ func (l *txList) Add(tx *types.Transaction, state *state.StateDB, priceBump uint ethCost = new(big.Int).Add(tx.Cost(), l1DataFee) } if ethCost != nil && ethCost.Sign() > 0 { - if l.costcap.Eth() == nil || l.costcap.Eth().Cmp(ethCost) < 0 { + if l.costcap.Eth().Cmp(ethCost) < 0 { l.costcap.SetEthAmount(ethCost) } } diff --git a/core/types/receipt.go b/core/types/receipt.go index 40946fef8..96bb17f98 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -124,7 +124,7 @@ type storedReceiptRLP struct { } // v7StoredReceiptRLP is the storage encoding of a receipt used in database version 7. -// This version was introduced when AltFee feature was added (2024-11). +// This version was introduced when AltFee feature was added. // It includes L1Fee and all AltFee fields (FeeTokenID, FeeRate, TokenScale, FeeLimit). type v7StoredReceiptRLP struct { PostStateOrStatus []byte diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index a59ba3e1e..383829875 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -170,6 +170,7 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error { MaxFeePerGas: args.MaxFeePerGas, MaxPriorityFeePerGas: args.MaxPriorityFeePerGas, FeeTokenID: args.FeeTokenID, + FeeLimit: args.FeeLimit, Value: args.Value, Data: (*hexutil.Bytes)(&data), AccessList: args.AccessList, diff --git a/rollup/fees/rate.go b/rollup/fees/rate.go index 0e99a9d76..fb97bf347 100644 --- a/rollup/fees/rate.go +++ b/rollup/fees/rate.go @@ -14,7 +14,7 @@ func TokenRate(state StateDB, tokenID uint16) (*big.Int, *big.Int, error) { if tokenID == 0 { return nil, nil, errors.New("token id 0 not support") } - info, rate, err := GetTokenInfoFromStorage(state, TokenRegistryAddress, tokenID) + info, rate, err := GetTokenInfoFromStorage(state, tokenID) if err != nil { log.Error("Failed to get token info from storage", "tokenID", tokenID, "error", err) return nil, nil, err @@ -28,17 +28,17 @@ func TokenRate(state StateDB, tokenID uint16) (*big.Int, *big.Int, error) { } func EthToAlt(state StateDB, tokenID uint16, amount *big.Int) (*big.Int, error) { - rate, tokenScale, err := TokenRate(state, tokenID) + rate, scale, err := TokenRate(state, tokenID) if err != nil { return nil, err } - return types.EthToAlt(amount, rate, tokenScale) + return types.EthToAlt(amount, rate, scale) } func AltToETH(state StateDB, tokenID uint16, amount *big.Int) (*big.Int, error) { - rate, tokenScale, err := TokenRate(state, tokenID) + rate, scale, err := TokenRate(state, tokenID) if err != nil { return nil, err } - return types.AltToEth(amount, rate, tokenScale) + return types.AltToEth(amount, rate, scale) } diff --git a/rollup/fees/token_info.go b/rollup/fees/token_info.go index 24b2dee25..0249fb2b3 100644 --- a/rollup/fees/token_info.go +++ b/rollup/fees/token_info.go @@ -68,12 +68,12 @@ func CalculateStructFieldSlot(baseSlot common.Hash, fieldOffset uint64) common.H } // GetUint256MappingValue retrieves a value from a mapping storage slot -func GetUint256MappingValue(state StateDB, contractAddr common.Address, key uint16, mappingSlot common.Hash) (*big.Int, error) { +func GetUint256MappingValue(state StateDB, key uint16, mappingSlot common.Hash) (*big.Int, error) { // Calculate the storage slot storageKey := CalculateUint16MappingSlot(key, mappingSlot) // Get the value from storage - value := state.GetState(contractAddr, storageKey) + value := state.GetState(TokenRegistryAddress, storageKey) // Convert hash to big.Int result := new(big.Int).SetBytes(value[:]) @@ -162,13 +162,13 @@ func IsTokenActive(state StateDB, tokenID uint16) (bool, error) { } // GetTokenPriceByIDWithState retrieves token price ratio from priceRatio mapping -func GetTokenPriceByIDWithState(state StateDB, contractAddr common.Address, tokenID uint16) (*big.Int, error) { - return GetUint256MappingValue(state, contractAddr, tokenID, rcfg.PriceRatioSlot) +func GetTokenPriceByIDWithState(state StateDB, tokenID uint16) (*big.Int, error) { + return GetUint256MappingValue(state, tokenID, rcfg.PriceRatioSlot) } // GetTokenInfoFromStorage retrieves token address, price, and balance slot from storage // This is a convenience function that combines multiple storage reads -func GetTokenInfoFromStorage(state StateDB, contractAddr common.Address, tokenID uint16) (*TokenInfo, *big.Int, error) { +func GetTokenInfoFromStorage(state StateDB, tokenID uint16) (*TokenInfo, *big.Int, error) { // Get token info from TokenInfo struct info, err := GetTokenInfo(state, tokenID) if err != nil { @@ -176,7 +176,7 @@ func GetTokenInfoFromStorage(state StateDB, contractAddr common.Address, tokenID } // Get token price from priceRatio mapping - price, err := GetTokenPriceByIDWithState(state, contractAddr, tokenID) + price, err := GetTokenPriceByIDWithState(state, tokenID) if err != nil { return nil, nil, fmt.Errorf("failed to get token price: %v", err) } diff --git a/rollup/fees/token_transfer.go b/rollup/fees/token_transfer.go index 86f673bc1..f46d0aae5 100644 --- a/rollup/fees/token_transfer.go +++ b/rollup/fees/token_transfer.go @@ -59,7 +59,7 @@ func changeAltTokenBalanceByState(state StateDB, tokenAddress common.Address, ba amountBytes := common.LeftPadBytes(newBalance.Bytes(), 32) amountHash := common.BytesToHash(amountBytes) - // Calculate the storage slot for the user's balance + // Change user balance state.SetState(tokenAddress, storageSlot, amountHash) return nil