智能合约的存储和参数大小限制?
1 个回答
- 投票数
-
- 2020-02-20
1.每笔交易的最大参数大小
最大 限制单个事务的每个事务的字节数 几个常数,尤其是for运算的上限
max_operation_data_length
和操作的硬性气体限制 和块(一个块包含一组操作):"max_operation_data_length": 16384, "hard_gas_limit_per_operation": "800000", "hard_gas_limit_per_block": "8000000", "cost_per_byte": "1000", "hard_storage_limit_per_operation": "60000",
如果您的节点正在运行,则可以通过RPC调用获取这些常量:
tezos-client rpc get /chains/main/blocks/head/context/constants | jq
max_operation_data_length
以字节为单位,这意味着您 每个参数的上限为〜16kB 交易.您还必须删除其他数据所需的大小 在交易中,例如发件人,收件人等.气体限制
hard_gas_limit_per_block
和hard_gas_limit_per_operation
间接限制两个最大存储量 和交易规模.每次调用智能合约时,该节点 经过以下几个阶段:- 读取智能合约代码的二进制表示形式+合约状态 从磁盘
- 解码代码,存储并输入到无类型表示形式
- 类型检查代码,存储和输入
- 运行代码
- 将存储编码为无类型的代表.
- (将编码后的存储写入磁盘-批量和异步)
这些相中的每一个都消耗气体.较大的参数会增加气体 2-4阶段的消费.更大的存储量会增加 阶段1-5.因此,存储和参数大小受以下因素限制 硬气限制.但是,我没有任何硬性数字,但是您 可以使用tezos-client进行仿真以获得估算值.
2.每个合约的最大存储空间
最后,关于第二个问题,已经部分 由1. AFAIK回答,没有明确的固定限制存储 智能合约.但是, 一定大小后,合同的存储将无法再解码, 因为这样做会超出硬气限制.另一个限制 因素是资金.
costs_per_byte
当前为1000 哑巴这意味着每增加一个kB需花费〜1tz(目前〜=3usd)的存储成本,由 增加存储量的交易发送者.我们还必须考虑常数
hard_storage_limit_per_operation
.每当交易 注入网络,它与存储限制相关联. 通常,它由用户设置,以确保他们的交易 不会引起意外的存储消耗.如果大小 应用交易产生的存储空间差异的百分比 超过存储限制,则交易被拒绝.的 常量hard_storage_limit_per_operation
给出最高的 可以设置的存储限制,因此也限制了最大值 每笔交易的存储空间增加.因此, 合同的存储不能增加超过60000字节 每笔交易.请注意,今天这种交易费用为〜180美元.1. Maximum parameter size per transaction
The maximum number of bytes per transaction for a single transaction is limited several constants, in particular an upper size of for operations
max_operation_data_length
and the hard gas limits for operations and blocks (a block contains a set of operations):"max_operation_data_length": 16384, "hard_gas_limit_per_operation": "800000", "hard_gas_limit_per_block": "8000000", "cost_per_byte": "1000", "hard_storage_limit_per_operation": "60000",
These constants can be obtained by a RPC call if you have a running node:
tezos-client rpc get /chains/main/blocks/head/context/constants | jq
Presumably
max_operation_data_length
is in bytes, meaning that you have a an upper limit of of ~16kB for the parameter per transaction. You would also have to remove the size needed other data in transaction, such as sender, recipient, etc.The gas limits
hard_gas_limit_per_block
andhard_gas_limit_per_operation
indirectly limit both maximum storage and transaction size. Each time a smart contract is invoked, the node passes through the following phases:- Read binary representation of smart contract code + contract state from disk
- Decode code, storage and input to untyped representation
- Typecheck code, storage and input
- Run code
- Encode storage to untyped repr.
- (write encoded storage to disk – batched & async)
Each of these phases consumes gas. Larger parameter increases the gas consumption in phase 2-4. Larger storage increases gas consumption in phases 1-5. It follows that storage and parameter size are limited by the hard gas limits. However, I do not have any hard numbers, but you could simulate using tezos-client to obtain estimates.
2. Maximum storage size per contract
Finally, for your second question, which is already partially answered by 1. AFAIK, there is no explicit fixed limit on the storage of a smart contract. However, after a certain size, the storage of contract can no longer be decoded, because doing so would exceed the hard gas limits. Another limiting factor is funds. The
costs_per_byte
is currently at 1000 mutez. This means that each additional kB costs ~1tz (currently ~= 3usd) to store, payed by the sender of transaction that increase storage.We also have to consider the constant
hard_storage_limit_per_operation
. Whenever a transaction is injected on the network, it is associated with a storage limit. Typically, it is set by the user, to ensure that their transaction does not provoke an unintended amount of storage burn. If the size of the storage size diff resulting from applying the transaction exceeds the storage limit, then the transaction is rejected. The constanthard_storage_limit_per_operation
gives the highest storage limit that can be set, and thus also limits the maximum storage size increase per transaction. It follows that the storage of a contract cannot increase with more than 60000 bytes per transaction. Note that such a transaction would cost ~180 usd today.-
当您说"这样的txn会花费"时,您指的是交易费用吗?煤气没有金钱意义.txn费用的金额也会随着所需的存储量而增加吗?When you say "such a txn would cost", are you referring to transaction fees? Gas does not have monetary meaning. Does the amount of txn fee also increase with needed storage amount?
- 0
- 2020-02-20
- utdrmac
-
确实,天然气没有固定成本.但是存储刻录的每字节固定成本.例如,请参见此处:https://tezos.stackexchange.com/a/2165/1773,以及此处的http://tezos.gitlab.io/introduction/howtouse.html,以获取完整说明.Indeed, gas does not have a fixed cost. But storage burn has a fixed cost per byte. See here for instance: https://tezos.stackexchange.com/a/2165/1773 and here http://tezos.gitlab.io/introduction/howtouse.html for a full explanation.
- 0
- 2020-02-20
- arvidj
关于智能合约的存储限制,有几个问题.