New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hive-engine light node #144
Hive-engine light node #144
Conversation
…of the latest block processed by the node
Less memory is also required to run, and apps which only need current data to run(ex just care about current NFT inventory etc) can self host a node for a lot cheaper reducing the load on public infastructure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not completely comfortable with exposing cleanupBlocks
to the smart contracts API. I also don't like the idea of modifying the witnesses contract to do that, because this is a breaking change which will force everyone to upgrade their node software. I'd rather have the next version release be an optional upgrade, so if you don't want to run a light node you don't need to upgrade.
Can you remove that from the witnesses contract and have it be done internally to the node software? It could be done as a maintenance operation every so often (maybe every 50 blocks, say) inside the produceBlock
function of libs/Block.js
. Also, please make sure that running a light node does not affect database hashes.
Can you merge the changes from this PR by @Rishi556 (which I've already approved) into your own branch: #145
That PR makes changes to the getStatus
function, which may cause a conflict since you touch that function too. Would be convenient to have that resolved in your PR so I don't have to do conflict resolution when preparing the next release.
Agree with this ask. Right now the witness contract changes wouldn't even work as is because it would need it to be deployed and all nodes would have to understand this action. But this isn't the right way to do the clean anyway, and @bt-cryptomancer suggestion is better to have it happen internally for light nodes in the appropriate location (produce block is sensible) |
…stVerifiedBlockNumber - blocksToKeep
… getBlockInfo and getTransactionInfo for light nodes again
Thanks for the review and for your comments regarding the changes. Running a light node does not affect database hashes. Everything is the same as for full nodes, except that light nodes do not store all blocks / transactions. I have now updated the code as follows:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good now, just a couple minor points that I'm concerned about (see comments below).
Also, can you put some comments in the code wherever it seems appropriate to indicate that blocksToKeep only applies in the event that lightNode is true?
…de blocksToKeep in getStatus if lightNode enabled; fix wasLightNodeBefore condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks good now, thanks for the revisions. Will include this PR in the next version release.
Description
This pull requests adds light node functionality to hive-engine. Instead of storing all data of the hive-engine blockchain, light nodes only store smart contract data and data required for block verification, but not the full chain (blocks, transactions are cleaned up periodically). This will allow for faster restoring / synchronizing and make the network / the witness block signing process more stable.
How to enable
Stop the node. Set
lightNode: true
in theconfig.json
. Start the node and it will initially delete all transactions and blocks< lastVerifiedBlockNumber - blocksToKeep
from the database. This process may take a few minutes - if you want to be faster you may want to use a lightnode snapshot and restore the database first. Ask me on discord for a snapshot or check out the following url:https://snap.primersion.com/light/
Restoring process is the same as for full nodes:
startHiveBlock
inconfig.json
lightNode: true
inconfig.json
If switching from a full node you may need to run
db.runCommand({compact: 'chain', force: true})
to free up storage consumed by mongodb.Differences of light nodes
lightNode: true
andblocksToKeep: 14400
lastVerifiedBlockNumber - blocksToKeep
up to the head blocklastVerifiedBlockNumber - blocksToKeep
up to the head blockCons
blocksToKeep
blocks)lastVerifiedBlockNumber - blocksToKeep
Pros
A few more details in the post over here: https://peakd.com/hiveengine/@primersion/hive-engine-light-nodes