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

catchup: avoid requesting blocks that aren't needed by the ledger #3089

Merged

Conversation

tsachiherman
Copy link
Contributor

Summary

avoid requesting blocks that aren't needed by the ledger.

This isn't done for the sake of optimization - it's done so we won't have misleading warning messages in the log file due to frequently canceled contexts.

Test Plan

tested manually.

This isn't done for the sake of optimization - it's done so we won't have misleading warning messages in the log file due to frequently canceled contexts.
algonautshant
algonautshant previously approved these changes Oct 18, 2021
Copy link
Contributor

@algonautshant algonautshant left a comment

Choose a reason for hiding this comment

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

I think the fix for the problem is partial.
The new error message will be reported only if the ledger already has the block, but not when the ledger gets the block and cancels the fetch during the innerFetch call.

If the partial fix is good enough, then it will not be necessary to complicate the fix to cover the other cases.

Also, will be nice to test for the error message in a unit test.

Looks good otherwise.

@@ -218,6 +230,10 @@ func (s *Service) fetchAndWrite(r basics.Round, prevFetchCompleteChan chan bool,
block, cert, blockDownloadDuration, err := s.innerFetch(r, peer)

if err != nil {
if err == errLedgerAlreadyHasBlock {
Copy link
Contributor

Choose a reason for hiding this comment

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

This error is reported only when the ledger already has the block by the time innferFetch first statements are executed.
However, when the innerFetch returns an error because the ledger already has the block, but the ledger had the block after the first innerFetch statements were executed, the error will not be reported as errLedgerAlreadyHasBlock.

Is this the expected behavior?

@@ -165,7 +177,7 @@ func (s *Service) innerFetch(r basics.Round, peer network.Peer) (blk *bookkeepin
go func() {
select {
case <-stopWaitingForLedgerRound:
case <-s.ledger.Wait(r):
case <-ledgerWaitCh:
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, don't we want errLedgerAlreadyHasBlock returned when ledgerWaitCh fires?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds like a good idea. I'll make it so.

@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2021

Codecov Report

Merging #3089 (78567d7) into master (b9c6032) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3089   +/-   ##
=======================================
  Coverage   43.66%   43.67%           
=======================================
  Files         391      391           
  Lines       86855    86868   +13     
=======================================
+ Hits        37927    37937   +10     
- Misses      42895    42898    +3     
  Partials     6033     6033           
Impacted Files Coverage Δ
catchup/service.go 71.10% <100.00%> (+0.97%) ⬆️
ledger/blockqueue.go 81.03% <0.00%> (-1.15%) ⬇️
data/abi/abi_type.go 90.90% <0.00%> (-0.91%) ⬇️
ledger/acctupdates.go 64.25% <0.00%> (-0.50%) ⬇️
network/wsPeer.go 74.09% <0.00%> (-0.26%) ⬇️
network/wsNetwork.go 62.58% <0.00%> (-0.19%) ⬇️
catchup/peerSelector.go 100.00% <0.00%> (+1.04%) ⬆️
crypto/merkletrie/node.go 93.48% <0.00%> (+1.86%) ⬆️
crypto/merkletrie/trie.go 68.61% <0.00%> (+2.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9c6032...78567d7. Read the comment docs.

Copy link
Contributor

@algonautshant algonautshant left a comment

Choose a reason for hiding this comment

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

Looks great.

@tsachiherman tsachiherman merged commit f0017f3 into algorand:master Oct 19, 2021
@tsachiherman tsachiherman deleted the tsachi/avoidrequestingblocks branch October 19, 2021 00:19
cce pushed a commit to cce/go-algorand that referenced this pull request Oct 28, 2021
…gorand#3089)

Summary
avoid requesting blocks that aren't needed by the ledger.

This isn't done for the sake of optimization - it's done so we won't have misleading warning messages in the log file due to frequently canceled contexts.

Test Plan
tested manually.
@egieseke egieseke mentioned this pull request Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants