Skip to content

Commit

Permalink
Introduction of effectiveGasPrice (#333)
Browse files Browse the repository at this point in the history
* implementation of effective gas price

* unit test and lint fix

* comment fix

* lint fix

* comment fix
  • Loading branch information
dusannosovic-ethernal authored Aug 14, 2024
1 parent c9e9d37 commit dc9be5d
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 3 deletions.
3 changes: 2 additions & 1 deletion jsonrpc/testsuite/receipt-contract-deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"contractAddress": "0x0000000000000000000000000000000000000003",
"from": "0x0000000000000000000000000000000000000001",
"to": null,
"type": "0x0"
"type": "0x0",
"effectiveGasPrice": "0x190"
}
3 changes: 2 additions & 1 deletion jsonrpc/testsuite/receipt-no-logs.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"contractAddress": null,
"from": "0x0000000000000000000000000000000000000001",
"to": "0x0000000000000000000000000000000000000002",
"type": "0x0"
"type": "0x0",
"effectiveGasPrice": "0x190"
}
3 changes: 2 additions & 1 deletion jsonrpc/testsuite/receipt-with-logs.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
"contractAddress": null,
"from": "0x0000000000000000000000000000000000000001",
"to": "0x0000000000000000000000000000000000000002",
"type": "0x0"
"type": "0x0",
"effectiveGasPrice":"0x190"
}
2 changes: 2 additions & 0 deletions jsonrpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ type receipt struct {
FromAddr types.Address `json:"from"`
ToAddr *types.Address `json:"to"`
Type argUint64 `json:"type"`
EffectiveGasPrice argBig `json:"effectiveGasPrice"`
}

func toReceipt(src *types.Receipt, tx *types.Transaction,
Expand All @@ -285,6 +286,7 @@ func toReceipt(src *types.Receipt, tx *types.Transaction,
ToAddr: tx.To(),
Logs: logs,
Type: argUint64(tx.Type()),
EffectiveGasPrice: argBig(*tx.EffectiveGasPrice(new(big.Int).SetUint64(header.BaseFee))),
}
}

Expand Down
3 changes: 3 additions & 0 deletions types/access_list_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ func (tx *AccessListTxn) chainID() *big.Int { return tx.ChainID }
func (tx *AccessListTxn) gasPrice() *big.Int { return tx.GasPrice }
func (tx *AccessListTxn) gasTipCap() *big.Int { return tx.GasPrice }
func (tx *AccessListTxn) gasFeeCap() *big.Int { return tx.GasPrice }
func (tx *AccessListTxn) effectiveGasPrice(baseFee *big.Int) *big.Int {
return new(big.Int).Set(tx.gasPrice())
}

func (tx *AccessListTxn) accessList() TxAccessList {
return tx.AccessList
Expand Down
16 changes: 16 additions & 0 deletions types/dynamic_fee_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ func (tx *DynamicFeeTx) gasPrice() *big.Int { return nil }
func (tx *DynamicFeeTx) gasTipCap() *big.Int { return tx.GasTipCap }
func (tx *DynamicFeeTx) gasFeeCap() *big.Int { return tx.GasFeeCap }

func (tx *DynamicFeeTx) effectiveGasPrice(baseFee *big.Int) *big.Int {
tmp := new(big.Int)

if baseFee == nil {
return tmp.Set(tx.GasFeeCap)
}

tmp.Sub(tx.GasFeeCap, baseFee)

if tmp.Cmp(tx.GasTipCap) > 0 {
tmp.Set(tx.GasTipCap)
}

return tmp.Add(tmp, baseFee)
}

func (tx *DynamicFeeTx) accessList() TxAccessList { return tx.AccessList }

func (tx *DynamicFeeTx) setChainID(id *big.Int) {
Expand Down
3 changes: 3 additions & 0 deletions types/legacy_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func (tx *LegacyTx) chainID() *big.Int { return deriveChainID(tx.v()) }
func (tx *LegacyTx) gasPrice() *big.Int { return tx.GasPrice }
func (tx *LegacyTx) gasTipCap() *big.Int { return tx.GasPrice }
func (tx *LegacyTx) gasFeeCap() *big.Int { return tx.GasPrice }
func (tx *LegacyTx) effectiveGasPrice(baseFee *big.Int) *big.Int {
return new(big.Int).Set(tx.GasPrice)
}

func (tx *LegacyTx) accessList() TxAccessList { return nil }

Expand Down
3 changes: 3 additions & 0 deletions types/state_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func (tx *StateTx) chainID() *big.Int { return deriveChainID(tx.v()) }
func (tx *StateTx) gasPrice() *big.Int { return tx.GasPrice }
func (tx *StateTx) gasTipCap() *big.Int { return tx.GasPrice }
func (tx *StateTx) gasFeeCap() *big.Int { return tx.GasPrice }
func (tx *StateTx) effectiveGasPrice(baseFee *big.Int) *big.Int {
return new(big.Int).Set(tx.gasPrice())
}

func (tx *StateTx) accessList() TxAccessList {
return nil
Expand Down
8 changes: 8 additions & 0 deletions types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ type TxData interface {
marshalJSON(a *fastjson.Arena) *fastjson.Value
unmarshalJSON(v *fastjson.Value) error
copy() TxData

// effectiveGasPrice computes the gas price paid by the transaction, given
// the inclusion block baseFee.
effectiveGasPrice(baseFee *big.Int) *big.Int
}

func (tx *Transaction) String() string {
Expand Down Expand Up @@ -194,6 +198,10 @@ func (t *Transaction) RawSignatureValues() (v, r, s *big.Int) {
return t.Inner.rawSignatureValues()
}

func (t *Transaction) EffectiveGasPrice(baseFee *big.Int) *big.Int {
return t.Inner.effectiveGasPrice(baseFee)
}

// set methods for transaction fields
func (t *Transaction) SetSignatureValues(v, r, s *big.Int) {
t.Inner.setSignatureValues(v, r, s)
Expand Down

0 comments on commit dc9be5d

Please sign in to comment.