# Substrate 源码追新导读: Call调用索引化, 存储层事物化全面完成

By [彭亚伦](https://paragraph.com/@0x0b0cb3e3be658bd582cf22474d43c21b773c203a) · 2022-06-30

---

20220523 - 20220529
===================

新增一个脚本用来运行全部Benchmarks的命令
-------------------------

4月份以来, `Benchmark`相关的命令和子命令进行了一系列更新和扩展, 本周又新添加一个脚本用于执行全部的`Benchmark`命令; 并对Benchmark相关源码进行了诸多修正和更新. 脚本文件基于[https://github.com/paritytech/polkadot/blob/master/scripts/ci/run\_benches\_for\_runtime.sh](https://github.com/paritytech/polkadot/blob/master/scripts/ci/run_benches_for_runtime.sh).

详情:[https://github.com/paritytech/substrate/pull/11493](https://github.com/paritytech/substrate/pull/11493)

新增Call索引化的属性宏
-------------

目前来说, 任何dispatchable的Call都没有设置执行顺序, 其执行大致是根据交易池和权重规则来判定, 现在提供一个`#[pallet::call_index($idx)]`属性宏, 用于固定`Call`enum中的变量位置索引值, 不涉及执行顺序, 仅仅用于引用时方便区分等场景.

详情: [https://github.com/paritytech/substrate/pull/11381](https://github.com/paritytech/substrate/pull/11381)

存储层的事务化全面更新以及bug修复
------------------

自2021年起, Parity的核心开发者Shawn Tabrizi就提交一个新的储存层事务处理构想, 基本上分3步走: 第一步设置一个嵌套事务处理层数量的限制常量, 第二步在所有Frame和Pallet中对于事务化的Call调用实现全新的事务处理机制, 第三步则是将`Transaction`更名, 以便将"事务"跟"交易"这者区分开来(两者的单词都是`Transaction`). 今年4月份第一步已经完成, 而最关键的第二步则直到本周才彻底实现完毕. 这一部分提供了一些新的辅助函数日`with_storage_layer`, `in_storage_layer`等, 来替代之前的`with_transactional`函数, 相比之前的方式, 新的函数返回值是一个`Result`, 这样更符合`事务`处理的定义: 返回成功, 或者失败回滚.

储存层新的更新还包含一个`DispatchWithStorageLayer`的trait接口, 任何pallet都可以调用其中的`.dispatch_with_storage_layer`方法来使用新的储存层事务处理逻辑, 同时`UnfliteredDispatchable`用于兼容之前的处理逻辑.

另外, 第三步可能不会完成了, 因为改动太大, 对以前的代码兼容性不太好.

详情: [https://github.com/paritytech/substrate/pull/11431](https://github.com/paritytech/substrate/pull/11431)

关于储存层的更新, 本周还有Gavin对多项储存容易出现删除相同key的问题.

详情: [https://github.com/paritytech/substrate/pull/11490](https://github.com/paritytech/substrate/pull/11490)

* * *

**_本文为SEP Creation 原创组文章, 作者彭亚伦_**

**_未经许可, 请勿转载._**

---

*Originally published on [彭亚伦](https://paragraph.com/@0x0b0cb3e3be658bd582cf22474d43c21b773c203a/substrate-call)*
