Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions core/token_gas.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package core

import (
"bytes"
"fmt"
"math/big"

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/tx_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions rollup/fees/rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
12 changes: 6 additions & 6 deletions rollup/fees/token_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[:])
Expand Down Expand Up @@ -162,21 +162,21 @@ 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 {
return nil, nil, fmt.Errorf("failed to get token info: %v", err)
}

// 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)
}
Expand Down
2 changes: 1 addition & 1 deletion rollup/fees/token_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down