-
Notifications
You must be signed in to change notification settings - Fork 208
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
[Merged by Bors] - sync, blocks: request blocks when tortoise crossed local threshold #4826
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package blockssync | ||
|
||
import ( | ||
"context" | ||
|
||
"go.uber.org/zap" | ||
"golang.org/x/sync/errgroup" | ||
|
||
"github.com/spacemeshos/go-spacemesh/common/types" | ||
) | ||
|
||
type blockFetcher interface { | ||
GetBlocks(context.Context, []types.BlockID) error | ||
} | ||
|
||
// Sync requests last specified blocks in background. | ||
func Sync(ctx context.Context, logger *zap.Logger, requests <-chan []types.BlockID, fetcher blockFetcher) error { | ||
var ( | ||
eg errgroup.Group | ||
lastch = make(chan []types.BlockID) | ||
) | ||
eg.Go(func() error { | ||
var ( | ||
send chan []types.BlockID | ||
last []types.BlockID | ||
) | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
close(lastch) | ||
return ctx.Err() | ||
case req := <-requests: | ||
dshulyak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if last == nil { | ||
send = lastch | ||
} | ||
last = req | ||
case send <- last: | ||
last = nil | ||
send = nil | ||
} | ||
} | ||
}) | ||
for batch := range lastch { | ||
if err := fetcher.GetBlocks(ctx, batch); err != nil { | ||
logger.Warn("failed to fetch blocks", zap.Error(err)) | ||
} | ||
} | ||
return eg.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this approach still relies on ProcessLayer being triggered by some component.
currently there are two components (proposal builder and state syncer) that calls TallyVotes(), which cause the tortoise to verify a layer. only state syncer will call ProcessLayer and cause the block to be fetched.
is it possible to tie the block fetching with TallyVote instead? tho that may delay generating block proposals.
or maybe TallyVote() should be called with OnBallot() (too expensive?) and cause the blocks to be fetched more frequently?
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.
it is also called by block builder (check ProcessPerHareOutput), i would prefer not to add it to the tortoise. maybe at some point when i remove ProcessLayer alltogether
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.
it makes sense to tie with local threshold, it is bigger change though. and this is needed semi-urgently