go-spacemesh
go-spacemesh copied to clipboard
Implement set reconciliation based sync (syncv2)
Motivation
Existing sync is causing a lot of resource usage, including memory consumption and network traffic, and can't replace gossip which can also be unreliable at times.
Description
This implements the new sync protocol as described here. The algorithm is based on Range-Based Set Reconciliation paper by Aljoscha Meyer and also loosely based on SREP: Out-Of-Band Sync of Transaction Pools for Large-Scale Blockchains paper by Novak Boškov, Sevval Simsek, Ari Trachtenberg, and David Starobinski.
Test Plan
Add systests that verify new sync. Verify on testnet, then on mainnet.
TODO
- [ ] Explain motivation or link existing issue(s)
- [X] Sync implementation based on red-black monoid tree
- [X] P2P wire protocol for sync
- [x] Implement SREP-like multi-peer sync
- [ ] Make code more efficient by getting rid of excess monoid abstraction
- [ ] Implement syncv2 for ATXs. This may include adding an untrusted LayerID field to ATXs to make sync more efficient
- [ ] Implement SQLite-based "pre-balanced" monoid tree for old data to reduce memory consumption
- [ ] Harden the protocol by enforcing communication limits
- [ ] Consider replacing red-black monoid tree with a BTree so it can also be used for
atxsdata - [ ] Implement sync for other object types
- [ ] Test changes and document test plan
- [ ] Update documentation as needed
- [ ] Update changelog as needed
Codecov Report
Attention: Patch coverage is 81.49957% with 644 lines in your changes missing coverage. Please review.
Project coverage is 81.7%. Comparing base (
4ab0d09) to head (1d7f9a7). Report is 15 commits behind head on develop.
Additional details and impacted files
@@ Coverage Diff @@
## develop #5769 +/- ##
=========================================
- Coverage 81.7% 81.7% -0.1%
=========================================
Files 312 334 +22
Lines 34625 38076 +3451
=========================================
+ Hits 28306 31127 +2821
- Misses 4480 4908 +428
- Partials 1839 2041 +202
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Did we agree already on adding the LayerID field to ATXs? @poszu @ivan4th. ATXs should only include what's need to be there
@mathcrypto the discussion was not finished yet, but I restarted it https://github.com/spacemeshos/go-spacemesh/pull/5785#discussion_r1590916018
@ivan4th This PR is reaching 14k LoC. Do you think you could start factoring out changes that are already done and could be reviewed to separate PRs?
@poszu that's the plan. Currently debugging ATX sync and this may cause a few more changes in rangesync, but other than that, rangesync together with types subpackages are close to being finished and soon I will split them off into a separate PR