跳到主要内容

Costs

Cost is a unit of measurement that represents resources expended to record a transaction in a block. Cost is a unit of measurement that is used to represent the available space in a block. It is measured by the amount of computing power required to execute the programs within it, as well as the physical drive space required to store data on each node's machine.

信息

The maximum cost per block is 11,000,000,000 (11 billion), which is typically equivalent to around 400 KB of space. However, not every block is completely full.

It is important to keep the cost usage of programs on the Chia blockchain as low as possible, to minimize the network pressure and resulting fees incurred.

Cost Calculation

Cost has several components. First, every CLVM program uses a certain amount of cost during execution, based on the operators and the values they are called on. You can refer to the Cost page on the Chialisp website to learn more about the cost of various CLVM operators.

Additionally, certain conditions in a coin spend have a cost associated with them as well. Additionally, certain conditions in a coin spend have a cost associated with them as well. A few common examples are CREATE_COIN and AGG_SIG_ME, which are expensive operations.

Finally, each byte of data that gets added to the blockchain has a cost of 12,000. Spend bundles are created using a serialized format of CLVM programs, calculated by running opc on the original CLVM program. Each two-digit pair of this format is equivalent to one byte, which costs 12,000 to store on the blockchain.

Aside from cost, the maximum number of atoms and pairs (counted separately) in a CLVM program is 2^31 apiece. If this threshold is exceeded, the program will terminate. However, this is likely a moot point, since it's extremely unlikely to write a program with this many atoms or pairs without exceeding the maximum cost per block.

Minimum Specs - Farming

The minimum spec machine to run a full node is the Raspberry Pi 4. How do we know if this machine can stay synced? The worst case scenario occurs when multiple full transaction blocks are created with the minimum amount of time between them. This will temporarily put maximum load on the system. If the Pi can stay synced in this scenario, then it easily should be able to stay synced under normal load.

The first question we must answer is how much time elapses between transaction blocks. The first question we must answer is how much time elapses between transaction blocks. Chia's consensus mandates that at least three signage points must be reached before infusion_iterations may occur, so the minimum time between blocks is the following:

3 signage points * signage point time
3 signage points * (600 seconds per sub-slot / 64 signage points per sub-slot)
3 signage points * 9.375 seconds per signage point

Which is 28.125 seconds.

备注

The average time between transaction blocks is 51.95 seconds. The lower a given time interval between transaction blocks (down to 28.125 seconds), the lower the probability of a transaction block being created in that time interval.

A transaction block is considered "full" when it contains 2000 outputs. For this document, we'll assume this translates to 1000 vanilla transactions, each with two inputs and two outputs. This would give the network an average of 19.25 (1000/51.95) transactions per second.

备注

A transaction with only one input and one output is also possible. In theory, a block could therefore hold up to 2000 transactions, in which case the network would process an average of 38.5 (2000/51.95) transactions per second.

With this goal in mind, Chia has created a generator program that processes 2000 compressed inputs and outputs. This program simulates a "full block".

To calculate the total amount of time for a Raspberry Pi 4 to process a full block, we must take into account three factors:

  • The time required to run the generator program (2000 inputs and outputs)
    • The Raspberry Pi 4 accomplishes this in 5.2 seconds
  • The time required to validate 2000 public keys
    • 2.2 seconds
  • The time required to validate 2000 aggregate signatures
    • 10.63 seconds

Therefore, the total amount of time required for a Raspberry Pi 4 to process a full block is 5.2 + 2.2 + 10.63 = 18.03 seconds. This is 10.095 seconds faster than the minimum time between blocks, and 33.92 seconds faster than the average. When considering other factors such as network latency and time required to fetch a full proof (640 ms on a slow HDD), this still allows plenty of leeway for a Raspberry Pi 4 to stay synced and collect farming rewards.

Minimum Specs - Syncing

As a benchmark, we use the Raspberry Pi 4, Chia's minimum spec machine for farming. A Raspberry Pi 4 has four cores, so it can validate a pre-existing block in 18.03 / 4 = 4.5075 seconds, which is around 11.5 times the average real-time rate of 51.95 seconds. Even in the worst-case scenario where every transaction block is full, the Pi can sync faster than the chain is being created.

Maximum Block Cost

Now that we've established that a Raspberry Pi 4 can, indeed, sync and farm, even when every transaction block is full, we'll calculate the maximum cost per block.

There are three categories that go into determining a block's maximum cost:

  1. Generator program cost, which is split into two parts
    • Execution cost
    • Signature validation cost
  2. Generator program size (each byte has a cost)
  3. Generator program coins (each new coin has a cost)

In the case of calculating the maximum cost, these three categories are to be given equal weight. We'll go through each of the categories individually.

Generator Execution

(This is the first half of 1, above.)

An Intel Macbook Pro was used as a reference platform to determine baseline costs based on CPU usage. The costs were then hand-tweaked for various reasons:

  • To ascribe additional cost to operations that allocate memory, i.e. the operand per-byte cost was inflated. This additional cost is called MALLOC_PER_BYTE_COST and amounts to 10 cost per byte.
  • The especially CPU intensive BLS operations (point_add and pubkey_for_exp) had their cost inflated to not differ too much from the Raspberry Pi 4.
  • Some operations that do not allocate memory and end up being common in relatively simple programs had their cost deflated. Specifically, if, cons, listp, first, and rest.

The result is that the generator program has an execution cost of 1 317 054 957.

Generator Signature Validation

(This is the second half of 1, above.)

The signature validation cost is based on computation time. BLS operations involve public key and aggregate signature validation, which are multiplied by the number of outputs.

  • Time per public key validation: 0.179370 ms
  • Time per aggregate signature validation: 0.972140 ms
  • Total time for 2000 key and signature validations: (0.179370 + 0.972140) * 2000 = 2303.02 ms

Each 1 cost is designed to require 1 nanosecond, so we need to multiply the result by 1 million (ns/ms).

  • Cost for the generator program's BLS operations: 2303.02 * 1 000 000 = 2 303 020 000.

Using this info, we can also calculate the cost of each AGG_SIG_UNSAFE and AGG_SIG_ME condition in all CLVM programs:

  • Cost per BLS condition: (0.179370 + 0.972140) * 1 000 000 = 1 151 510. We round this number up to 1 200 000.

Generator Cost

(This is the total cost of 1, above.)

Taking the previous two calculations into account, the total cost to execute and run the BLS operations of the generator program is: 1 317 054 957 + 2 303 020 000 = 3 620 074 957.

Generator Program Size

(This is the cost of 2, above.)

We know that 1, 2, and 3 all will be assigned equal maximum costs, which we've already established is 3 620 074 957. This is the size-based cost of the generator program.

The generator program itself is 298 249 bytes. Each byte, therefore has a cost of 3 620 074 957 / 298 249 = 12 137.76. We round this number to 12 000 per byte. This is the cost per bye of all CLVM programs.

Generator Program Coins

(This is the cost of 3, above.)

Just like the previous calculation, the total cost of the generator program's coins is 3 620 074 957. The generator program creates 2000 coins, so the cost per CREATE_COIN in all CLVM programs is 3 620 074 957 / 2000 = 1 810 037.4785. We round this number to 1 800 000.

Maximum Cost Per Block

To calculate the maximum cost per block, we simply add the generator program's execution, size, and coin costs:

Theoretical maximum cost per block: 3 620 074 957 + 3 620 074 957 + 3 620 074 957 = 10 860 224 871 We round this number to 11 000 000 000.

Maximum Block Size

The theoretical maximum size of a single block is maximum cost per block / cost per byte, or 11 000 000 000 / 12 000 = 916 667 bytes. However, this number ignores the costs of all operators. If you want a CLVM program to do anything useful, the maximum size would be closer to 400 KB.

Even this number is not realistic because it assumes that a single program will take up an entire block. The maximum number of vanilla transactions (with two outputs) per block is 1000. Therefore, if there is fee pressure on Chia's blockchain, a 400 KB program would need to include a larger fee than the top 1000 vanilla transactions in the mempool -- combined -- in order for a farmer to include it.

Estimated Transaction Costs

The below chart contains costs for various transactions on the blockchain, each of these assumes the inputs and outputs have been optimized and represent a best case scenario.

备注

The minimum effective fee represents 5 x the clvm cost and is the minimum fee recognized by the default consensus rules (any fee less would be the same as 1 mojo). This means one needs to use at least the fees listed below during moderate fee pressure but greater fees might be needed for time sensitive transactions to process in a timely manner.

Please note that the costs and fees listed are for vanilla versions of these transactions, they can vary based on the number of input and output coins needed so consider these the bare minimum. Transactions with a '*' are listed with a fee of 3 x the minimum effective fee. This is to ensure the fees are more realistic for how coins are distributed in users wallets but note that vanilla versions of these would be 1/3 that which is listed.

Transaction Typeclvm CostMinimum Effective Fee
Full Block (with 50% cap)5,500,000,00027,500,000,000 mojo (0.0275 xch)
Standard Transaction6,000,00090,000,000 mojo (0.00009 xch) *
PlotNFT Creation18,000,00090,000,000 mojo (0.00009 xch)
Minting NFT with DID123,000,000615,000,000 mojo (0.000615 xch)
Minting NFT without DID53,000,000265,000,000 mojo (0.000265 xch)
Adding URI to NFT with DID71,000,000355,000,000 mojo (0.000355 xch)
Adding URI to NFT without DID41,000,000205,000,000 mojo (0.000205 xch)
Transfer NFT with DID67,000,000335,000,000 mojo (0.000335 xch)
Assign DID to NFT107,000,000535,000,000 mojo (0.000535 xch)
Send Clawback Transaction10,000,000150,000,000 mojo (0.00015 xch) *
Claim Clawback Transaction1,400,0007,000,000 mojo (.000007 xch)
Clawback Clawback Transaction15,600,00075,800,000 mojo (.0000758 xch)
Combine 500 Farming Rewards3,100,000,00015,500,000,000 mojo (.0155 xch)
Split 1 Coin into 211,000,00055,000,000 mojo (.000055 xch)
Cat Transaction37,000,000555,000,000 mojo (.000555 xch) *