Skip to content

Commit

Permalink
Wiki Reorg: Tx Fees (#6107)
Browse files Browse the repository at this point in the history
* edits

* reorg text

* moved content

- to transaction page
- added redirect
- update sidebar

* added guides info

* final edits

* redirect kusama
  • Loading branch information
filippoweb3 authored Jul 31, 2024
1 parent 1356c9d commit c73f075
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 210 deletions.
Binary file added docs/assets/fee-details.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions docs/learn/learn-guides-transfers.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ selected does not support teleportation yet.

## Calculating Fees with Polkadot-JS

To calculate fees you can go to Developer > Runtime Calls and select the following extrinsics:

- `transactionPaymentApi.queryInfo`
- `transactionPaymentApi.queryFeeDetails`

and specify the `0x` prefixed hex call data and its length.

![Fee details](../assets/fee-details.png)

The sum of `baseFee`, `lenFee` and `adjustedWeightFee` will yield the `partialFee`.

One useful utility for estimating transaction fees programmatically is the via the
[@polkadot/api](https://www.npmjs.com/package/@polkadot/api). Check out the following script that
logs some relevant fee information:
Expand Down
195 changes: 0 additions & 195 deletions docs/learn/learn-transaction-fees.md

This file was deleted.

76 changes: 74 additions & 2 deletions docs/learn/learn-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ slug: ../learn-transactions
import RPC from "./../../components/RPC-Connection"; import Tabs from "@theme/Tabs"; import TabItem
from "@theme/TabItem"; import DocCardList from '@theme/DocCardList';

<DocCardList />

## Pallets and Extrinsics

{{ polkadot: Polkadot :polkadot }}{{ kusama: Kusama :kusama }} is built using
Expand Down Expand Up @@ -119,6 +117,80 @@ it allows you to add an extra security step. There are
[a multitude of possible attacks](../general/transaction-attacks.md) that will prevent you to send
funds to the desired destination account.

## Transaction Fees

Storage and computation are limited resources in a blockchain network. Transaction fees prevent
individual users from consuming too many resources.
{{ polkadot: Polkadot :polkadot }}{{ kusama: Kusama :kusama }} uses a **weight-based fee model** as
opposed to a gas-metering model. As such, fees are charged before transaction execution. Once
the fee is paid, nodes will execute the transaction.

Polkadot fees consist of three parts:

- `Base fee`: a fixed fee applied to every transaction and set by the runtime.
- `Length fee`: a fee that gets multiplied by the length of the transaction in bytes.
- `Weight fee`: a fee for each varying runtime function. Runtime implementers must implement a
conversion mechanism that determines the corresponding currency amount for the calculated
weight.

The final fee can be summarized as:

```
fee = base_fee + length_of_transaction_in_bytes * length_fee + weight_fee
```

where:

Base fee: 1 milliDOT

Length fee: 0.1 DOT per byte

The weight-to-fee conversion is calculated as follows:

```
weight_fee = weight/1.26 * (10−8)
```

A weight of 126,000 nS is mapped to 1 mDOT. This fee will always be, at most, the max size of an unsigned 128-bit integer.

See [the Polkadot specification]( https://spec.polkadot.network/id-weights#id-definitions-in-polkadot) and [the Substrate documentation](https://docs.substrate.io/build/tx-weights-fees/) for more details.

### Fee Multiplier

{{ polkadot: Polkadot :polkadot }}{{ kusama: Kusama :kusama }} can add an additional fee to
transactions if the network becomes too busy and starts to decelerate the system. This additional fee is known as the `Fee Multiplier` and its value is defined by the
{{ polkadot: Polkadot :polkadot }}{{ kusama: Kusama :kusama }} runtime. The multiplier compares the saturation of blocks; if the previous block is less saturated than the current block
(implying an uptrend in usage), the fee is slightly increased. Similarly, the fee is decreased if the previous block is more
saturated than the current block (implying a downtrend in usage).

The multiplier can
create an incentive to avoid the production of low-priority or insignificant transactions. In
contrast, those additional fees will decrease if the network calms down and transactions can be executed without overheads.

The final fee is calculated as follows:

```
final_fee = fee * fee_multiplier
```

See [the documentation about the Polkadot specifications](https://spec.polkadot.network/id-weights#id-fee-multiplier) for more details.

### Other Resource Limitation Strategies

Transaction weight must be computable before execution and can only represent fixed
logic. Some transactions warrant limiting resources with other strategies. For example:

- Bonds: Some transactions, like voting, may require a bond that will be returned or
[slashed](./learn-offenses.md) after an on-chain event. In the voting example, returned at the end
of the election or slashed if the voter tried anything malicious.
- Deposits: Some transactions, like setting an [identity](learn-identity.md) or claiming an index,
use storage space indefinitely. These require a deposit to be returned if the user decides
to clear their identity and free the storage.
- Burns: A transaction may burn funds internally based on its logic. For example, a transaction may
burn funds from the sender if it creates new storage entries, thus increasing the state size.
- Limits: Some limits are part of the protocol. For example, nominators can only nominate 16
validators. This limits the complexity of [Phragmén](learn-phragmen.md).

## Parachain Transactions

The transactions that take place within
Expand Down
4 changes: 4 additions & 0 deletions kusama-guide/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ module.exports = {
to: '/docs/kusama-getting-started',
from: ['/docs/kusama-index']
},
{
to: '/docs/learn-transactions',
from: ['/docs/learn-transaction-fees']
},
],
createRedirects: function (existingPath) {
if (existingPath.startsWith('/docs/')) {
Expand Down
2 changes: 1 addition & 1 deletion polkadot-wiki/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ module.exports = {
},
{
to: '/docs/learn-transactions',
from: ['/docs/learn-transactions-index', '/docs/learn-extrinsics', '/docs/learn-balance-transfers']
from: ['/docs/learn-transactions-index', '/docs/learn-extrinsics', '/docs/learn-balance-transfers', '/docs/learn-transaction-fees']
},
{
to: '/docs/alpha-program',
Expand Down
13 changes: 1 addition & 12 deletions polkadot-wiki/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,7 @@ module.exports = {
"learn/learn-proxies-pure",
],
},
{
type: "category",
label: "Transactions",
description: 'Extrinsics, Balance Transfers, and Fees.',
link: {
type: 'doc',
id: "learn/learn-transactions",
},
items: [
"learn/learn-transaction-fees",
],
},
"learn/learn-transactions",
{
type: "category",
label: "Staking",
Expand Down

0 comments on commit c73f075

Please sign in to comment.