3

Is there a way to get the amount actual weight consumed when an extrinsic is executed

1 Answer 1

1

You mean within a call? No. In contracts there is something like gas_left which returns you the remaining gas, but not in FRAME.
After the call: yes. An extrinsic emits a System::ExtrinsicSuccess event which contains the post-dispatch corrected weight. Something like:

System::ExtrinsicSuccess {
  weight: {
    refTime: 123,127,795
    proofSize: 0
  }
  class: Normal
  paysFee: Yes
}

If you actually want to re-benchmark past blocks you can use the benchmark block command to re-execute historic blocks from a chain snapshot. It then compares that to the declared weight of the block, which is described here. Example output:

$ cargo run --profile=production -- benchmark block --from 9939453 --to 9939462 --db paritydb

Block 9939453 with     2 tx used   4.57% of its weight (    26,458,801 of    579,047,053 ns)
Block 9939454 with     3 tx used   4.80% of its weight (    28,335,826 of    590,414,831 ns)
Block 9939455 with     2 tx used   4.76% of its weight (    27,889,567 of    586,484,595 ns)

By the nature of weight it needs to be run on the same reference hardware, otherwise the execution time will be off.

1
  • 1
    Yes, I wanted to get the weight consumed after the call. Thanks for the help. Let me try it out and come back to you if there is any issue. Thanks once again Commented Nov 30, 2022 at 7:50

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.