Skip to content

Commit

Permalink
Merge pull request #602 from oasisprotocol/ptrus/fix/charged-fee-nonevm
Browse files Browse the repository at this point in the history
runtime-transactions: fix calculated `charged_fee` for non-evm txs
  • Loading branch information
ptrus authored Jan 12, 2024
2 parents 130473b + aa1ce83 commit 59e4c1e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2434,7 +2434,8 @@ components:
description: |
The fee that was charged for the transaction execution (total, native denomination,
ParaTime base units, as a string).
Calculated as `gas_price * gas_used`, where `gas_price = fee / gas_limit`.
For EVM transactions this is calculated as `gas_price * gas_used`, where `gas_price = fee / gas_limit`, for compatibility with Ethereum.
For other transactions this equals to `fee`.
size:
type: integer
format: int32
Expand Down
5 changes: 4 additions & 1 deletion storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ const (
txs.fee,
txs.gas_limit,
txs.gas_used,
COALESCE(FLOOR(txs.fee / NULLIF(txs.gas_limit, 0)) * txs.gas_used, 0) AS charged_fee, -- charged_fee=gas_price * gas_used
CASE
WHEN txs.tx_eth_hash IS NULL THEN txs.fee -- charged_fee=fee for non-EVM txs
ELSE COALESCE(FLOOR(txs.fee / NULLIF(txs.gas_limit, 0)) * txs.gas_used, 0) -- charged_fee=gas_price * gas_used for EVM txs
END AS charged_fee,
txs.size,
txs.method,
txs.body,
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e_regression/expected/emerald_txs.body
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@
},
"to": "oasis1qzypxmt5xg8039329zvre7hxe7kn0vxfugsknqtw"
},
"charged_fee": "6131500000000000",
"charged_fee": "6132100000000000",
"fee": "6132100000000000",
"gas_limit": 61321,
"gas_used": 61315,
Expand Down Expand Up @@ -683,7 +683,7 @@
},
"to": "oasis1qr5vpvmhxgymefgxx66mn5heayeyec69xgvzr5p9"
},
"charged_fee": "6131400000000000",
"charged_fee": "7000000000000000",
"fee": "7000000000000000",
"gas_limit": 70000,
"gas_used": 61314,
Expand Down Expand Up @@ -812,7 +812,7 @@
},
"to": "oasis1qzypxmt5xg8039329zvre7hxe7kn0vxfugsknqtw"
},
"charged_fee": "6131400000000000",
"charged_fee": "6132100000000000",
"fee": "6132100000000000",
"gas_limit": 61321,
"gas_used": 61314,
Expand Down Expand Up @@ -1302,7 +1302,7 @@
},
"to": "oasis1qzypxmt5xg8039329zvre7hxe7kn0vxfugsknqtw"
},
"charged_fee": "6131500000000000",
"charged_fee": "6132100000000000",
"fee": "6132100000000000",
"gas_limit": 61321,
"gas_used": 61315,
Expand Down Expand Up @@ -1716,7 +1716,7 @@
},
"to": "oasis1qzypxmt5xg8039329zvre7hxe7kn0vxfugsknqtw"
},
"charged_fee": "6131500000000000",
"charged_fee": "6132100000000000",
"fee": "6132100000000000",
"gas_limit": 61321,
"gas_used": 61315,
Expand Down Expand Up @@ -2181,7 +2181,7 @@
},
"to": "oasis1qzypxmt5xg8039329zvre7hxe7kn0vxfugsknqtw"
},
"charged_fee": "6131500000000000",
"charged_fee": "6132100000000000",
"fee": "6132100000000000",
"gas_limit": 61321,
"gas_used": 61315,
Expand Down

0 comments on commit 59e4c1e

Please sign in to comment.