KomodoPlatform / zebra

An ongoing Rust implementation of a Komodo node. 🦓
Apache License 2.0
3 stars 5 forks source link

zebra node did not reach the tip when syncing with komodo node #18

Open dimxy opened 1 year ago

dimxy commented 1 year ago

There is a slight difference in zcash and komodo p2p protocol due to which the current zebra code may not fully sync with a komodo node and stops syncing at one block off the komodo peer tip. The reason for that is that zebra uses 'getblocks' p2p message instead of 'getheaders' used in komodo. The zebra code normally expects one erroneously sent tip block from a zcash node and drops the last block. Then it resumes syncing from the last remembered block and sends a 'getblocks' request with a locator starting from this block. The komodo p2p protocol does not send a block in answer to a repeated 'getblocks' ('inv' messages which were already sent to this node are not sent again). That way zebra node's getblocks requests may time out and the node's tip may be one off. After zebra node restarts or reconnects syncing resumes though.

Suggested fix: use getheaders in zebra instead of getblocks as getheaders are always answered by a komodo peer, even repeated plus do not throw the last block hash. (A downside is that responses to 'getheaders' would return complete headers than 'getblocks' responses which only include block hashes)

dimxy commented 1 year ago

Note if we only fix trimming the last coming block hash (like zcash does it) and continue using getblocks we still will be getting time out errors, so to fix that too we need yet to switch to 'getheaders'

dimxy commented 1 year ago

In #2 experimental code added to use "getheaders" instead of "getblocks" and do not trim the last block in the response. Hope this improved sync. However getheaders involve more payload. Maybe we could close this issue if agree to use getheaders.