Usually, I wrote experimental blockchain code. Sometimes, I wrote it using RSK Node as a code base. To test some changes, I run the modified code locally, and then, test it againts RSK testnet or mainnet. But if I need to synchronize my local node from zero against, ie, RSK testnet, the process could run for two or three days (some months ago, it was worse). So, I wrote another experimental code: an alternative long synchronization algorithm.
The code is at my forked project, branch altsync.
You can download the code. To build the solution run:
./gradlew build -x test
This command builds a .jar file with all the needed code. To run it using the alternative algorithm, execute:
java -cp rskj-core-0.6.1-ORCHID-all.jar -Dsync.alternative=true co.rsk.Start --testnet
Usually, I could sync with testnet from scratch in 8 hours (460000 blocks at the time of my experiment), instead of 2 or 3 days.
The alternative algorithm was designed with some principles:
- Talks with the known nodes, without discriminate between them
- Use the force of the swarm (the friend nodes), Luke
The last point means: it take advantage of every message sent by the friend nodes, and try to get more message from the friend nodes that show more active response. In order to be effective, I had use the supported messages in existing implementation to communicate with other nodes. Maybe, it could be improved if some new message (like “get block by number”) could be added.
Even in the case of having “bad” friend nodes, the node advances toward to have a valid synchronized blockchain.
There are some other improvements to add. One case not covered yet with elegance: when the local node is in a long fork different from the public mainchain.
Angel “Java” Lopez