Skip to content

provider: adding provide and reprovide queue #1114

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

Open
wants to merge 2 commits into
base: provider
Choose a base branch
from

Conversation

guillaumemichel
Copy link
Contributor

Part of #1095


This PR adds 2 queues implementations:

Reprovide queue

This queue keeps track of the prefixes associated with the keyspace regions that should be reprovided as soon as possible. These regions end up in the queue if the provider failed to reprovide them on time.

Provide queue

This queue keeps track of all the keys that should be provided as soon as possible. The keys are grouped by common prefix to optimize batch providing.

Both queues make use of the prefixQueue.

@guillaumemichel guillaumemichel requested a review from a team as a code owner July 24, 2025 08:58
@guillaumemichel guillaumemichel mentioned this pull request Jul 24, 2025
30 tasks
Copy link
Contributor

@gammazero gammazero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor things, see comments

Comment on lines +30 to +37
// Prefix is a prefix of (at least) an existing prefix in the queue.
entriesToRemove := keyspace.AllEntries(subtrie, bit256.ZeroKey())
prefixesToRemove := make([]bitstr.Key, len(entriesToRemove))
for i, entry := range entriesToRemove {
prefixesToRemove[i] = entry.Key
}
// Remove superstrings of `prefix` from the queue
firstRemovedIndex := q.removePrefixesFromQueue(prefixesToRemove)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are also present in Remove. Maybe put them into a function.

Comment on lines +19 to +26
digest := make([]byte, 32)
if _, err := rand.Read(digest); err != nil {
panic(err)
}
h, err := mh.Encode(digest, mh.SHA2_256)
if err != nil {
panic(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at random.Multihashes or even random.Bytes

Suggested change
digest := make([]byte, 32)
if _, err := rand.Read(digest); err != nil {
panic(err)
}
h, err := mh.Encode(digest, mh.SHA2_256)
if err != nil {
panic(err)
}
h := random.Multihashes(1)[0]

panic(err)
}
k := keyspace.MhToBit256(h)
if keyspace.IsPrefix(prefix, k) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of finding enough multihashes that have the prefix by chance, consider generating the requested number of random multihashes, and overwriting them to have the correct prefix.

// queue. It assumes the mutex is held already.
func (q *ProvideQueue) sizeNoLock() int {
return q.keys.Size()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like an unnecessary function. Would it be better to just call q.keys.Size()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants