Open akaron opened 5 years ago
So, it's actually the limit of nodejs v8. By default, it is restricted to use only about 1.7GB of memory. Can change to a higher value by add an argument while run nodejs (see https://stackoverflow.com/questions/38558989/node-js-heap-out-of-memory ):
node --max-old-space-size=4096 yourFile.js
or set a environment variable (using bash as example):
export NODE_OPTIONS=--max_old_space_size=4096
But still, it took roughly half a minute if use 2^22 leaves (~4 million) to run the example script in previous comment (it basically generate merkle tree and then get the proof and side from the tree). It's still worth to optimize or at least restrict the amount of tx in a block.
In a "moderate-low" machine (my laptop: Intel core i5-8250U, bought in 2018, with 10GB+ ram available while testing, nodejs version 10.15.3), if there are more than 2 million (~2^21) transactions per block, then it's likely to see error messages as shown below. The test code is also attached in the end.
In theory, the data format can accept up to 2^24 transactions (see
mfields
, the max length of proves is 24), but the result here means in practice the limit is about one million (~2^20). If there are no obvious ways to optimize the code (especially themakeMerkleTree()
part), then the maximum tx per block should be restricted to 1 million (no need to change existing code, just let validators reject tx and probably also submit block while there are already 1 million tx).Here's the error message:
The test code here (the purpose of the code is to generate merkle tree with lots of leaves, in order to test whether
merkleTreeValidator()
in smart contract can handle longproves
andsides
):