10

During block authorship, the execution time of each transaction is measured, rather than weights right?

Doesn't that mean as a runtime developer, you only need weights for pricing your extrinsics, but technically, we could price them dynamically based on execution time?

Which in turn is a better dev experience, i dunno. Unless i'm missing something?

2 Answers 2

13

During block authorship, the execution time of each transaction is measured, rather than weights right?

We don't measure the execution time per extrinsic. Each block has a fixed slot for proposing/building it. This slot is measured using the wall clock time. However, this is only used to ensure that you are staying in certain limits. Weights are the much more important factor here. Weights are also measured while building a block, but in the runtime. The runtime rejects a transaction when it would use more weight than we have left in the block. This transaction will then be put back into the transaction pool for the next round.

Doesn't that mean as a runtime developer, you only need weights for pricing your extrinsics, but technically, we could price them dynamically based on execution time?

No, weights are extremely important for your chain. The runtime needs to ensure that each block can be imported by a given minimum hardware on time. This minimum hardware is what is used to run the benchmarks. If you would use the wall clock time for this, a really really powerful validator could build blocks that will take other validators more time to import. In a really bad scenario this "malicious" validator may could produce a block that takes minutes to import while it should take seconds. Then the entire network would run behind and may enable this validator to produce a new block resulting in all nodes taking too much time to import the block again.

So, weight is really important to ensure that a block is bounded and stays in certain limits. For Parachains where Weight2D will also track the storage proof usage it will be even more important.

9

The main reason is it is impossible to deterministically determine the execution time of a transaction without heavy overhead (e.g. gas metering).

For example, user send a transaction, the execution time is 10ms on the block producer Alice. Alice created the block, charged 10ms worth of the tx fee and broadcast the produced block. Other fullnode needs to validate this block by replaying it, and remeasure the execution time. For various reason, Bob may need 20ms to evaluate this tx. Should Bob reject this block because it is under charging? How could Alice proof the execution time is 10ms?

Could a valuator just say I have this magic computer that can execute all the transactions in 1ms and under charge the tx fee to DOS the network?

Could a valuator just say hey my machine for some reason requires 500ms to execute this tx so I am going to charge you 500ms instead of an executed execution time of 10ms.

Weight functions provide a way to provide a reasonable estimation of the execution time of a call that is deterministic and reproducible.

Of course, you can do gas metering just like any other smart contract chain. But you will also need to pay for the overhead of the gas metering, which are significant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.