Geth实际运行占用磁盘情况

go-ethereum 在 2019 年 7 月推出了 v1.9.x 版本。1.9.x 在数据方面做了重新整理,大概有以下两个非兼容的改动:

  1. 历史的区块链数据(header,body, receipts等)被挪到一个flaten file存储中,因为这部分数据已经是不会更改的了

  2. 更改了部分数据结构的scheme,例如receipt。原先很多字段不需要存到db,是可以在read之后重新计算出来的。这部分会占据大量的存储空间,在1.9把这些字段删去了。

geth 有一个 inspect 命令,统计数据库详细信息。help中的内容是 inspect,Inspect the storage size for each type of data in the database

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
+-----------------+--------------------+------------+
| DATABASE | CATEGORY | SIZE |
+-----------------+--------------------+------------+
| Key-Value store | Headers | 211.40 KiB |
| Key-Value store | Bodies | 44.00 B |
| Key-Value store | Receipts | 42.00 B |
| Key-Value store | Difficulties | 19.07 KiB |
| Key-Value store | Block number->hash | 17.24 KiB |
| Key-Value store | Block hash->number | 845.67 KiB |
| Key-Value store | Transaction index | 0.00 B |
| Key-Value store | Bloombit index | 0.00 B |
| Key-Value store | Trie nodes | 4.79 MiB |
| Key-Value store | Trie preimages | 547.13 KiB |
| Key-Value store | Clique snapshots | 0.00 B |
| Key-Value store | Singleton metadata | 149.00 B |
| Ancient store | Headers | 5.97 MiB |
| Ancient store | Bodies | 851.64 KiB |
| Ancient store | Receipts | 182.32 KiB |
| Ancient store | Difficulties | 279.10 KiB |
| Ancient store | Block number->hash | 769.77 KiB |
| Light client | CHT trie nodes | 0.00 B |
| Light client | Bloom trie nodes | 0.00 B |
+-----------------+--------------------+------------+
| TOTAL | 14.40 MIB |
+-----------------+--------------------+------------+

这里的flaten file 存储,其实是把历史数据挪到了 ancient 文件夹(在前文亦有size说明),不在用 LeveldDB 存储,而用普通的二进制格式储存数据。

当从更加老的版本升级到 v1.9.x (或者Geth1.9.x重新启动)时,Geth将自动地升级Blocks和Receipts,从 LevelDB 转移到 ancient 文件夹。也可以通过手动设定 ancient 文件夹位置 --datadir.ancient

chaindata 存放了账本数据(cold data),默认的话,ancientchaindata 里面。state 存放了业务数据(hotdata)。

  • 如果 chaindata 账本数据被删除(或者指定到了错误的位置),节点将变得不可用。这种操作是命令禁止的。
  • 如果 state 业务数据被删除,Geth将在 chaindata 账本数据的基础上重建其索引,并在顶部快速同步到丢失的状态数据。

参考文档==> Geth v1.9.0 Six months distilled