简体   繁体   English

将区块链块存储在阵列中不是效率低下吗? (Node.js)

[英]Is not it inefficient to store blockchain blocks in an array? (Node.js)

I've read some articles on creating blockchain using Node.js and one common thing I found that they are using arrays to store blocks. 我读过一些有关使用Node.js创建区块链的文章,我发现一件事是,他们正在使用数组存储块。

I don't think it is efficient to use an array here because the size of the chain may increase to hundreds of MB. 我认为在这里使用数组效率不高,因为链的大小可能会增加到数百MB。

So my questions are what is the best way to store blocks? 所以我的问题是存储块的最佳方法是什么? Array? 数组? Redis? Redis? Something else? 还有吗

Edit: 编辑:

One of the articles I have read: https://codingislove.com/simple-blockchain-javascript/ 我读过的文章之一: https : //codingislove.com/simple-blockchain-javascript/

See the array "chain" in the Blockchain class. 请参阅Blockchain类中的数组“ chain”。

The higher length of your block chain, the better that your block chain will get, As of my knowledge to verify a single block, the bit coin block chain (the implementation) does not goes till the root block, bitcoin block chain uses an algorithm depend on the amount of the transaction, how many blocks they need to travel to (higher the amount, higher the reverse traversing). 区块链的长度越长,您的区块链就越好。据我所知,要验证单个区块,比特币区块链(实现)要等到根区块才开始,比特币区块链使用一种算法取决于交易金额,需要行进多少个区块(金额越高,反向遍历越高)。

So my suggestion is to keep a constant amount of blocks on the memory to verify, And persist other blocks to a database or key value storage(like redis) and load them when required. 因此,我的建议是在内存中保留一定数量的块以进行验证,并将其他块持久保存到数据库或键值存储(例如redis)中,并在需要时加载它们。

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

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