Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change BlockLocator index selection logic #2583

Closed
greymistcube opened this issue Nov 26, 2022 · 0 comments
Closed

Change BlockLocator index selection logic #2583

greymistcube opened this issue Nov 26, 2022 · 0 comments
Assignees
Labels
api Related to user-facing APIs

Comments

@greymistcube
Copy link
Contributor

Given hashes [0x00, 0x01, ..., 0x0e, 0x0f], we should expect the following results:

  • BlockLocator created with sampleAfter value 0: [0x0f, 0x0e, 0x0c, 0x08, 0x00]
  • BlockLocator created with sampleAfter value 1: [0x0f, 0x0e, 0x0d, 0x0b, 0x07, 0x00]
    • Current actual value: [0x0f, 0x0e, 0x0c, 0x08, 0x00]
  • BlockLocator created with sampleAfter value 2: [0x0f, 0x0e, 0x0d, 0x0c, 0x0a, 0x06, 0x00]
    • Current actual value: [0x0f, 0x0e, 0x0d, 0x0b, 0x07, 0x00]

In the last example above, [0x0f, 0x0e] would correspond to non-sampled indices and and [0x0d, 0x0c, 0x0a, 0x06, 0x00] would correspond to sampled indices. From my perspective, there are two problems with current implementation:

  • There is no difference between BlockLocator created with sampleAfter value of 0 and 1.
  • The initial delta of indices for "sampling" starts with 2 not 1.

Given starting index $n$, I think the cleanest way to define the act of "sampling indices" would be the following:

  • $i_{0} = n$
  • $i_{1} = i_{0} - 1$
  • $i_{k} = i_{k-1} - 2(i_{k - 2} - i_{k - 1})$ for $k \geq 2$

Or in a more compact form:

  • $i_{0} = n$
  • $i_{k} = i_{k - 1} - d_{k - 1}$ where $d_{t} = 2^{t}$ for $k \geq 1$

Or in a closed form:

  • $i_{k} = n - (2^{k} - 1)$
@greymistcube greymistcube changed the title Fix BlockLocator index selection logic Change BlockLocator index selection logic Nov 26, 2022
@greymistcube greymistcube self-assigned this Nov 26, 2022
@greymistcube greymistcube added the api Related to user-facing APIs label Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to user-facing APIs
Projects
Status: Done
Development

No branches or pull requests

1 participant