I would like to know the recommended way to benchmark a chain extension, and then how to charge the calculated weight. According to this document, we need to write benchmarks.
1 Answer
The benchmark docs are the best place to start, and good examples of benchman.rs
files in Substrate as reference. Your goal is to create worst case scenario weights for using your chain extension, as it (like all other pallet logic) cannot be allowed to consume more time to execute than the block allows. As you may be simply a directly calling other properly bechmarked pallet's logic, it could be as simple as a 1 to 1 mapping plus the slight extra overhead the chain extension itself calling this vs. directly. Conversely, this may add significant new logic and more complete benchmarking to match.