Skip to content

Commit

Permalink
core,internal/ethapi: Fixed fee calculation error and added feePayer …
Browse files Browse the repository at this point in the history
…null check
  • Loading branch information
cp-wjhan committed May 4, 2023
1 parent 136473a commit 3833f2d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (st *StateTransition) buyGas() error {
return fmt.Errorf("%w: fee delegation type not supported", ErrTxTypeNotSupported)
}
FDmgval := new(big.Int).SetUint64(st.msg.Gas())
FDmgval = FDmgval.Mul(FDmgval, st.gasFeeCap)
FDmgval = FDmgval.Mul(FDmgval, st.gasPrice)
feePayer := *st.msg.FeePayer()
if feePayer == st.msg.From() {
FDbalanceCheck := new(big.Int).SetUint64(st.msg.Gas())
Expand Down
5 changes: 4 additions & 1 deletion core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,11 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
// fee delegation
if tx.Type() == types.FeeDelegateDynamicFeeTxType {
// Make sure the transaction is signed properly.
if tx.FeePayer() == nil {
return ErrInvalidFeePayer
}
feePayer, err := types.FeePayer(types.NewFeeDelegateSigner(pool.chainconfig.ChainID), tx)
if *tx.FeePayer() != feePayer || err != nil {
if err != nil || *tx.FeePayer() != feePayer {
return ErrInvalidFeePayer
}
if pool.currentState.GetBalance(feePayer).Cmp(tx.FeePayerCost()) < 0 {
Expand Down
4 changes: 4 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,10 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
// Ensure only eip155 signed transactions are submitted if EIP155Required is set.
return common.Hash{}, errors.New("only replay-protected (EIP-155) transactions allowed over RPC")
}
// fee delegation
if tx.Type() == types.FeeDelegateDynamicFeeTxType && tx.FeePayer() == nil {
return common.Hash{}, errors.New("FeePayer address is null")
}
if err := b.SendTx(ctx, tx); err != nil {
return common.Hash{}, err
}
Expand Down

0 comments on commit 3833f2d

Please sign in to comment.