Open fasmat opened 1 year ago
As an alternative the ForkFinder
can also just request a stream of layer hashes covering the range of From
and To
, compare hashes and stop the stream as soon as the first divergent layer is found.
Before changing the implementation we should performance test the current solution and answer the following questions:
The larger the usual search range is the better a binary search should perform compared to a streaming solution, unless it is more likely to find the forking layer close to the beginning (or end) of the search range.
Additionally it needs to be tested if fewer large request or more smaller requests are more efficient (requesting up to 100 at once vs. requesting only 1 layer).
Description
The ForkFinder in the
syncer
package at the moment requests the aggregated hashes of multiple layers at once, up toMaxHashesInReq
(100) to find where the local state started differing from a peers state. This is can be made more efficient by instead using a binary search:The local node should request the aggregated hash in the middle between the
From
andTo
and then narrow the range until the first divergent layer is found. This limits the number of requests and hashes to log2(To
-From
) and removes the need for checks on the client and server side limiting the amount of layers that are requested at once.Affected code
ForkFinder
in thesyncer
packagehandler
in thefetch
packagesql/layers
For more info see discussions in PR https://github.com/spacemeshos/go-spacemesh/pull/4480/