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

eth: update highest block we know during the sync if a higher was found #16283

Merged
merged 2 commits into from
Mar 9, 2018

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented Mar 8, 2018

In this PR, fix two problems:

  1. Avoid useless synchronization during the fast sync if the peer doesn't have higher difficulty than our fast block head.

  2. Update highest block we know during the sync

@rjl493456442 rjl493456442 requested a review from karalabe as a code owner March 8, 2018 04:48
@@ -80,7 +80,7 @@ func (s *PublicEthereumAPI) Syncing() (interface{}, error) {
progress := s.b.Downloader().Progress()

// Return not syncing if the synchronisation already completed
if progress.CurrentBlock >= progress.HighestBlock {
if !s.b.Downloader().Synchronising() {
Copy link
Member

@karalabe karalabe Mar 8, 2018

Choose a reason for hiding this comment

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

This won't be a good change:

// Synchronising returns whether the downloader is currently retrieving blocks.
func (d *Downloader) Synchronising() bool {
	return atomic.LoadInt32(&d.synchronising) > 0
}

During the node's initial sync (and maybe even afterwards), sync will abort and restart a few times if the master peer we're connected to disappears. The current code progress.CurrentBlock >= progress.HighestBlock doesn't care about that, and will just report syncing until we're actually in sync. Your change would report sync done whenever the downloader aborts for a few second.

@rjl493456442
Copy link
Member Author

@karalabe Updated.

Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

LGTM!

@karalabe karalabe added this to the 1.8.3 milestone Mar 8, 2018
Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

Hmm, I think the fast sync stall check you added causes some test to fail. Me might just need to patch that test up to cater for this extra check.

@rjl493456442
Copy link
Member Author

@karalabe Please take a look again

eth/sync.go Outdated
// Make sure the peer's total difficulty we are synchronizing is higher.
if pm.blockchain.GetTdByHash(pm.blockchain.CurrentFastBlock().Hash()).Cmp(pTd) >= 0 {
return
}
Copy link
Member

Choose a reason for hiding this comment

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

This is only one path where fast sync is enabled, the above if branch also enables fast sync.

Please move these two lines below outside of both branches, and do something like

if mode == downloader.FastSync {
	if pm.blockchain.GetTdByHash(pm.blockchain.CurrentFastBlock().Hash()).Cmp(pTd) >= 0 {
		return
	}
}

Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

LGTM, lets hope nothing breaks with that extra check :)

@karalabe karalabe merged commit 77da203 into ethereum:master Mar 9, 2018
@fjl fjl changed the title eth: update higest block we know during the sync if a higher was found eth: update highest block we know during the sync if a higher was found Mar 26, 2018
prestonvanloon pushed a commit to prestonvanloon/go-ethereum that referenced this pull request Apr 2, 2018
ethereum#16283)

* eth: update higest block we know during the sync if a higher was found

* eth: avoid useless sync in fast sync
hackmod pushed a commit to OpenCommunityCoin/go-esn that referenced this pull request Jul 9, 2018
ethereum#16283)

* eth: update higest block we know during the sync if a higher was found

* eth: avoid useless sync in fast sync
mariameda pushed a commit to NiluPlatform/go-nilu that referenced this pull request Aug 23, 2018
ethereum#16283)

* eth: update higest block we know during the sync if a higher was found

* eth: avoid useless sync in fast sync
firmianavan pushed a commit to firmianavan/go-ethereum that referenced this pull request Aug 28, 2018
ethereum#16283)

* eth: update higest block we know during the sync if a higher was found

* eth: avoid useless sync in fast sync
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