简体   繁体   English

状态数据如何存储在以太坊区块链上?

[英]How is state data stored on Ethereum blockchain?

Was thinking about storage costs on Ethereum and trying to comprehend the implication of storing a globally standardized credit score (like Bloom) on-chain.正在考虑以太坊的存储成本,并试图理解在链上存储全球标准化信用评分(如 Bloom)的含义。

In the simplest case, you would store three 256bit words of data per user, indexed by user addresses, which would mean 4 words of storage.在最简单的情况下,您将为每个用户存储三个 256 位字的数据,按用户地址索引,这意味着存储 4 个字。

In the scenario where you reached 100M users, you are looking at 400M words of storage, total.在您达到 1 亿用户的场景中,您正在查看总共 4 亿字的存储空间。 Each word of storage on the Ethereum blockchain requires 20K in gas fees, so with even 1 gwei at the current price of $1147/ETH, you are looking at ~$9.4M to store all credit scores of the user base.以太坊区块链上的每个存储字都需要 20K 的 gas 费用,因此即使以当前 1147 美元/ETH 的价格计算 1 gwei,您也需要大约 940 万美元来存储用户群的所有信用评分。

So, my question is thus:所以,我的问题是:

If you change the state of the contract above by updating one user's score, does it require storing the entire 400M words of data again (and incurring the $9.4M charge), or is only a delta of the state stored in some metadata layer?如果您通过更新一个用户的分数来更改上述合约的状态,是否需要再次存储整个 4 亿字的数据(并产生 940 万美元的费用),还是仅存储在某个元数据层中的状态的增量?

Unless you're changing the order of records (by removing one of them, for example), you won't have to overwrite the whole array.除非您要更改记录的顺序(例如,通过删除其中之一),否则您不必覆盖整个数组。 You'll only pay gas for data that you add or update.您只需为添加或更新的数据支付 gas。

In short, you wouldn't be storing that information directly on the Ethereum blockchain.简而言之,您不会将该信息直接存储在以太坊区块链上。 You would use IPFS.你会使用 IPFS。

Basically, you store any file into IPFS and then you store the IPFS hash in the Ethereum contract.基本上,您将任何文件存储到 IPFS 中,然后将 IPFS 哈希存储在以太坊合约中。 Any user with an IPFS node is going to be able to access the file using that hash.任何拥有 IPFS 节点的用户都将能够使用该哈希访问该文件。 You can store data, images, the front end, etc. whatever you want.您可以随心所欲地存储数据、图像、前端等。

Here you have an example: https://github.com/AdrianClv/ethereum-ipfs这里有一个例子: https : //github.com/AdrianClv/ethereum-ipfs

Finally, where should I store my data?最后,我应该在哪里存储我的数据?

Well, maybe not on the Ethereum Blockchain.好吧,也许不在以太坊区块链上。 The data stored there, with Smart Contracts, is safe and easy to access.使用智能合约存储在那里的数据安全且易于访问。 But the cost and the structure of the store makes it relevant for metadata-related uses.但是存储的成本和结构使其与元数据相关的用途相关。

Taking the examples from the introduction: Users Posts, Files and Message Boxes will probably be on another platform like IPFS.以介绍为例:用户帖子、文件和消息框可能会在另一个平台上,如 IPFS。 In the Ethereum Blockchain, we would store critical data.在以太坊区块链中,我们将存储关键数据。 Data like encryption keys, roots to storage trees & authorizations.加密密钥、存储树根和授权等数据。

Source: https://www.lsenta.io/posts/storage-and-dapps-on-ethereum-blockchain/来源: https : //www.lsenta.io/posts/storage-and-dapps-on-ethereum-blockchain/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM