-
Notifications
You must be signed in to change notification settings - Fork 1
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
Ingester main loop #5
Conversation
clients. TODO: TESTS, this is logic that is nuanced
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!!
case <-ctx.Done(): | ||
return ctx.Err() | ||
case payload, ok := <-blocksCh: | ||
// TODO: we should batch RCP blocks here before sending to Dune. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this?
// Every N seconds: Send the batched blocks
buffer := make([]*Block, 0, concurrency)
ticker := time.NewTicker(batchInterval)
for {
select {
case block := <-blocks:
buffer = append(buffer, block)
if len(buffer) == cap(buffer) {
sendBlocks(buffer)
buffer = buffer[:0] // Clear the buffer after sending.
}
case <-ticker.C:
if len(buffer) > 0 {
sendBlocks(buffer)
buffer = buffer[:0] // Clear the buffer after sending.
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly, but batchInterval should be like 150millis.. so we don't cause delays, its only for the case where we can harvest fast (or forces us to harvest fast?)
return latest | ||
} | ||
|
||
func (i *ingester) ReportProgress(ctx context.Context) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running this in a separate goroutine is such a great idea!
For the main loop, when we start trying to do reliable delivery, I'm thinking we might want to use more of a pipeline with channels
What do you think? Wrote a prototype here: https://gist.github.com/vegarsti/bc4d9dceec87666f456f3fbf6b213edb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, LGTM :)
return latestBlockNumber | ||
} | ||
|
||
for blockNumber := startBlockNumber; dontStop || startBlockNumber <= endBlockNumber; blockNumber++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future do we consider parallelizing this part ? I mean to consume blocks in parallel ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, like Vegard proposed above
This is the main loop logic, it connects the:
it has a few responsabilities: