如何升级智能合约?
3 个回答
- 投票数
-
- 2019-02-28
因为类型
lambda
的值可以保存在存储中或作为参数传递(作为lambda
或作为bytes
表示为UNPACK
),可能写可以自我升级的合同……这并不总是很有意义,但有时可能会有用.例如,一个非常早期的主网合同似乎具有一种升级机制: https://tzscan.io/KT1R3uoZ6W1ZxEwzqtv75Ro7DhVY6UAcxuK2 .配置的所有者可以向其中一个入口点提供一个lambda,该入口点将被存储在存储区中,并且在某些情况下将覆盖合同的行为.
Because values of type
lambda
can be kept in storage or passed as parameters (either aslambda
or asbytes
to beUNPACK
ed), it is possible to write contracts which can upgrade themselves... This won't always make sense, but might sometimes be useful.For example, one of the very early mainnet contracts appears to have a kind of upgrade mechanism: https://tzscan.io/KT1R3uoZ6W1ZxEwzqtv75Ro7DhVY6UAcxuK2. The configured owner can supply a lambda to one of the entry points, which will be placed in storage and will override the contract's behavior in some cases.
-
- 2019-02-26
免责声明:这只是出于教育目的的示例,请勿在生产中使用.
以下是流动性智能合约的相当原始的可升级设计:
代理合同
- 保留状态/存储空间
- 指向逻辑合约,并代理其入口点
- 可以由其合法所有者修改/升级.您可能会在这里遇到去中心化/治理问题-所有底层逻辑合同更改仍在链上跟踪,因此这是一个折衷.
- 公开一个入口点
setData
,由逻辑合约使用以应用存储更改
逻辑合同
- 由代理合同独家致电
- 每个入口点调用都会导致代理合同上的
setData
入口点调用
从理论上讲,您应该能够使用Liquidity的"类似于模块的合同系统" .为了使上述方法正常运行,您必须仔细实现一个体面的ACL(谁可以调用哪些入口点).
Disclaimer: This is just an example for educational purposes, don't use it in production.
Here is a fairly primitive upgradable design for a Liquidity smart contract:
Proxy Contract
- Holds the state / storage
- Points to a Logic Contract, and proxies its entry points
- Can be amended / upgraded, by its rightful owner. You can run into decentralization / governance issues here - all the underlying logic contract changes are still tracked on-chain, so it's a trade-off.
- Exposes an entry point
setData
, consumed by the Logic Contract to apply storage changes
Logic Contract
- Is called exclusively by the Proxy Contract
- Each entry point call, results into a
setData
entry point call on the Proxy Contract
In theory, you should be able to implement this using Liquidity's 'module-like contract system'. For the above described to work well, you must carefully implement a decent ACL (who can call which entry points).
-
- 2019-07-29
Cryptonomic 发表了文章最近恰好在这个主题上.
Cryptonomic published an article on exactly this topic recently.
我正在建立一个智能合约,该合约有点像已签名文档的索引(指向实际文档的ipfs).
如果我想在以后的
app
中添加一些功能并需要升级合同怎么办?我了解我需要签订新合同,但是如何将旧合同的当前状态转移到新合同呢?
初始化具有大状态的新合同会花费很多XTZ吗?还有另一种方法可以实现这一目标吗?