---
eip: 1682
label: EIP-1682
title: Storage Rent
status: Withdrawn
type: Standards Track
category: Core
created: 2018-11-10
official: https://eips.ethereum.org/EIPS/eip-1682
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1682.md
canonical: https://eips.huatuo.xyz/zh/eip-1682/
lang: zh
tldr: 已撤回的提案：对账户占用的状态持续收取租金，停止缴费的账户会被停用，之后任何人都可以将其恢复。
tags: [state, rent, storage, core, withdrawn]
---

# EIP-1682: Storage Rent

> This EIP describes a scheme to charge for data in state, and 'archive' data which is no longer being paid for. It also describes how resurrection of 'archived' data happens.

**TL;DR:** 已撤回的提案：对账户占用的状态持续收取租金，停止缴费的账户会被停用，之后任何人都可以将其恢复。

## 它解决什么问题？

写入以太坊的每一个账户和存储槽，都必须被每个全节点永久保存。用户在写入数据时只付一次费，但存储成本却由网络无限期地承担。作者认为这种无限制的增长不可持续，协议需要对状态大小设置一个硬性上限。

EIP-1682 提出了**存储租金（storage rent）**：账户为其使用的空间持续付费，停止付费的账户会被移出活跃状态，但可以复活。

## 它如何运作

**账户新增三个字段：**

```text
account = [nonce, balance, storageroot, codehash, rentbalance, rentblock, storagesize]
```

- `rentbalance`：专门为租金预留的以太币。
- `rentblock`：上一次结算租金的区块。
- `storagesize`：正在使用的存储槽数量。

**收取租金。** 当区块修改某个账户时，会按自 `rentblock` 以来经过的区块数、与 `storagesize` 成比例地计算租金，先从 `rentbalance` 中扣，再从普通余额中扣，并将其**销毁**。随着总状态接近常量 `MAX_STORAGE_SIZE = 2**32` 个 trie 节点，每个存储槽的费用会上升，因此链越满，租金越陡。

**停用账户。** 无法支付的账户会变为*停用*状态：它的代码和存储被移除，表现得就像没有代码一样。

**新操作码：**

| 操作码 | 作用 |
| --- | --- |
| `PAYRENT amount addr` | 把以太币从调用者转入 `addr` 的租金余额（任何人都可以为任何人付费） |
| `RENTBALANCE addr` | 压入 `addr` 的租金余额 |
| `SSIZE addr` | 压入 `addr` 的存储大小 |
| `RESTORETO addr codeaddr` | 用存储根与之匹配的合约来恢复一个停用账户 |

要恢复账户 A，你需要部署一个新合约 B，用 `SSTORE` 重建 A 的完全相同的存储，然后调用 `RESTORETO`。因此，恢复的成本等于重新创建这些数据的成本。

之所以另设租金余额，是因为有些合约会拒绝普通的以太币转账，或精确追踪自己的余额（例如众筹），不能从中扣除租金。

## 示例代码

规范中的租金计算（Python 伪代码）：

```python
MAX_STORAGE_SIZE = 2**32

def storagefee_factor(block):
    ramp = MAX_STORAGE_SIZE / (MAX_STORAGE_SIZE - total_storage_size(block))
    return 2**22 * ramp

def charge_rent(prestate, poststate, addr, currentblock):
    fee = rent(prestate, poststate, addr, currentblock)
    if fee <= poststate[addr].rentbalance:
        poststate[addr].rentbalance -= fee
    else:
        fee -= poststate[addr].rentbalance
        poststate[addr].rentbalance = 0
        poststate[addr].balance -= min(poststate[addr].balance, fee)
    poststate[addr].rentblock = currentblock
```

## 需要注意

- **状态：Withdrawn。** 存储租金从未在以太坊上被采纳，若干 gas 成本（`PAYRENT`、`RESTORETO`）也一直是“TBD”。
- 租金打破了合约存储永久保存这一基本预期；恢复机制本想缓和这一点，但恢复需要有人仍然持有完整的数据。
- 账户只有在被触及时才会被收费，所以闲置账户不会被自动移除；规范接受这一点，以避免追踪每一个账户。
- 以太坊在状态增长方面的工作后来转向了其他方向，例如历史过期（[EIP-4444](/eip-4444/)）以及带有 Verkle 式 gas 改动的无状态客户端（[EIP-4762](/eip-4762/)）。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-1682
