A while ago I have implemented a "light node" functionality for Hive-Engine, which allows for node operators to only store some transaction data instead of the full history. You can read more about it in the post over here.
I have been making a few more small changes to the engine light nodes, which I will be describing in detail in this post.
You can find the pull request over here on GitHub: https://github.com/hive-engine/hivesmartcontracts/pull/10
In short, I have implemented some code changes, which add an additional plugin to the Hive-Engine node software. The new plugin is performing cleanup tasks every X seconds, which were previously included in the blockchain parsing code. Additionally I have cleaned up the config by introducing a new json node for light nodes, containing all config values relevant for light nodes.
The newly added plugin is started up together with all other plugins during startup and shutdown when stopping a node. During initialization of the plugin, it checks whether or not the node is actually a light node. Depending on the result it will either return or start the cleanup action:
const init = async (conf, callback) => {
const {
lightNode,
databaseURL,
databaseName,
} = conf;
if (!lightNode.enabled) {
console.log('LightNode not started as it is not enabled in the config.json file');
} else {
database = new Database();
await database.init(databaseURL, databaseName, lightNode.enabled, lightNode.blocksToKeep);
manageLightNode(lightNode.cleanupInterval ? lightNode.cleanupInterval : 600000);
}
callback(null);
};
The cleanup action is performed every X seconds (600000 millis = 600 seconds = 10 minutes) by default:
const manageLightNode = async (cleanupInterval) => {
await database.cleanupLightNode();
manageLightNodeTimeoutHandler = setTimeout(() => {
manageLightNode(cleanupInterval);
}, cleanupInterval);
};
The cleanup simply removes unneeded blocks and transactions from the database of the node. This was previously performed during blockchain parsing, which may have slowed down the process a bit.
The new plugin will help improve light node performance by asynchronously performing the cleanup action and in the future more stuff like that can be added.
Another improvement was made for the configuration of light node values in the config.json
. The config file now includes a separate json node lightNode
, containing all relevant config values for light nodes. The following config is set by default:
"lightNode": {
"enabled": false,
"blocksToKeep": 864000,
"cleanupInterval": 600000
},
The two values blocksToKeep
and cleanupInterval
are only relevant if enabled
is set to true
. blocksToKeep
defines how many blocks (transactions) should be kept in the database before cleaning them up. The default value of 864000 is equivalent to about 30 days of history. cleanupInterval
defines after how many milliseconds the cleanup action (removing unneeded blocks / transactions) should be peformed. The default value is 600000 millis (600 seconds or 10 minutes).
Besides that I have fixed a small bug, which has caused the synchronisation to fail if starting from the genesis block. A light node check has been triggered wrongly, which checks if the node was previously a light node, because switching back to a full node from a light node is not possible and a full restore is required. The code now additionally checks if the startHiveBlock
in the config is equals the genesis block:
if (!lightNode.enabled && startHiveBlock !== genesisHiveBlock)
and I adapted the log message if the check triggers:
Looks like your database belongs to a light node. Did you forget to set lightNode.enabled = true in the config.json? Switching from a light node to a full node is not possible - you would have to do a full database restore in such a case.
That was all the changes included in the PR mentioned above. I have been working on a few other small improvements in a development branch, which may be included in one of the next PRs. Also we are just discussing a few changes regarding Hive-Engine governance, but more on that later.
The PR will hopefully be included in one of the next releases. In the meantime if you would like to try it out, just check out the changes from my forked repository: https://github.com/primersion/hivesmartcontracts
Thx for the genesis bug fix. That one has caused a few problems for me and I don't need to keep on remembering to change light to true in config for some tests.
Thanks for the post, I could give you my vote :)
@primersion! The Hive.Pizza team manually upvoted your post.
Learn more at https://hive.pizza!
Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!
Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).
You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.
Nice
Congratulations @primersion! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)
Your next target is to reach 66000 upvotes.
Your next payout target is 9000 HP.
The unit is Hive Power equivalent because post and comment rewards can be split into HP and HBD
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Check out the last post from @hivebuzz:
Support the HiveBuzz project. Vote for our proposal!
!gif awesome
!gif test
Via Tenor