Skip to content

Commit

Permalink
fix BalanceTokenFee
Browse files Browse the repository at this point in the history
  • Loading branch information
JukLee0ira committed Dec 6, 2024
1 parent 7d620fd commit ea9bb17
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call XDPoSChain.Cal
feeCapacity := state.GetTRC21FeeCapacityFromState(statedb)
if msg.To != nil {
if value, ok := feeCapacity[*msg.To]; ok {
msg.CallMsg.BalanceTokenFee = value
msg.BalanceTokenFee = value
}
}

Expand Down
6 changes: 3 additions & 3 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type Message struct {
GasTipCap *big.Int
Data []byte
AccessList types.AccessList
balanceTokenFee *big.Int
BalanceTokenFee *big.Int

// When SkipAccountCheckss is true, the message nonce is not checked against the
// account nonce in state. It also disables checking that the sender is an EOA.
Expand All @@ -152,7 +152,7 @@ func TransactionToMessage(tx *types.Transaction, s types.Signer, balanceFee, blo
Data: tx.Data(),
AccessList: tx.AccessList(),
SkipAccountChecks: false,
balanceTokenFee: balanceFee,
BalanceTokenFee: balanceFee,
// }
// // If baseFee provided, set gasPrice to effectiveGasPrice.
// if baseFee != nil {
Expand Down Expand Up @@ -245,7 +245,7 @@ func (st *StateTransition) from() vm.AccountRef {
}

func (st *StateTransition) balanceTokenFee() *big.Int {
return st.msg.BalanceTokenFee()
return st.msg.BalanceTokenFee
}

func (st *StateTransition) to() vm.AccountRef {
Expand Down
2 changes: 1 addition & 1 deletion core/token_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func CallContractWithState(call ethereum.CallMsg, chain consensus.ChainContext,
feeCapacity := state.GetTRC21FeeCapacityFromState(statedb)
if msg.To != nil {
if value, ok := feeCapacity[*msg.To]; ok {
msg.CallMsg.BalanceTokenFee = value
msg.BalanceTokenFee = value
}
}
txContext := NewEVMTxContext(msg)
Expand Down
9 changes: 0 additions & 9 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,15 +771,6 @@ func (t *TransactionsByPriceAndNonce) Pop() {
heap.Pop(&t.heads)
}

func (m *Message) SetBalanceTokenFeeForCall() {
m.balanceTokenFee = new(big.Int).SetUint64(m.gasLimit)
m.balanceTokenFee.Mul(m.balanceTokenFee, m.gasPrice)
}

func (m *Message) SetBalanceTokenFee(balanceTokenFee *big.Int) {
m.balanceTokenFee = balanceTokenFee
}

// copyAddressPtr copies an address.
func copyAddressPtr(a *common.Address) *common.Address {
if a == nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,8 @@ func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash
if err != nil {
return nil, err
}
msg.SetBalanceTokenFeeForCall()
msg.BalanceTokenFee = new(big.Int).SetUint64(msg.GasLimit)
msg.BalanceTokenFee.Mul(msg.BalanceTokenFee, msg.GasPrice)

// Get a new instance of the EVM.
evm, vmError, err := b.GetEVM(ctx, msg, statedb, XDCxState, header, &vm.Config{NoBaseFee: true})
Expand Down Expand Up @@ -2086,7 +2087,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
if value, ok := feeCapacity[to]; ok {
balanceTokenFee = value
}
msg.SetBalanceTokenFee(balanceTokenFee)
msg.BalanceTokenFee = balanceTokenFee

// Apply the transaction with the access list tracer
tracer := vm.NewAccessListTracer(accessList, args.from(), to, precompiles)
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (b *backendMock) GetTd(common.Hash) *big.Int {
return nil
}

func (b *backendMock) GetEVM(context.Context, core.Message, *state.StateDB, *tradingstate.TradingStateDB, *types.Header, *vm.Config) (*vm.EVM, func() error, error) {
func (b *backendMock) GetEVM(context.Context, *core.Message, *state.StateDB, *tradingstate.TradingStateDB, *types.Header, *vm.Config) (*vm.EVM, func() error, error) {
return nil, nil, nil
}

Expand Down
2 changes: 2 additions & 0 deletions les/odr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
GasTipCap: new(big.Int),
Data: data,
SkipAccountChecks: true,
BalanceTokenFee: balanceTokenFee,
// msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, true, balanceTokenFee, header.Number)}
}
context := core.NewEVMBlockContext(header, bc, nil)
Expand Down Expand Up @@ -169,6 +170,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
GasTipCap: new(big.Int),
Data: data,
SkipAccountChecks: true,
BalanceTokenFee: balanceTokenFee,
}
context := core.NewEVMBlockContext(header, lc, nil)
txContext := core.NewEVMTxContext(msg)
Expand Down
1 change: 1 addition & 0 deletions light/odr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain
GasTipCap: new(big.Int),
Data: data,
SkipAccountChecks: true,
BalanceTokenFee: balanceTokenFee,
}
txContext := core.NewEVMTxContext(msg)
context := core.NewEVMBlockContext(header, chain, nil)
Expand Down

0 comments on commit ea9bb17

Please sign in to comment.