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

Only Sync With the Peer With the Highest Observed Slot #2280

Merged
merged 22 commits into from
Apr 26, 2019
Merged

Conversation

rauljordan
Copy link
Contributor

@rauljordan rauljordan commented Apr 17, 2019

This is part of #1586


Description

Write why you are making the changes in this pull request

Currently, our chain head querier naively accepts any response it gets, even though it might be from a peer that is really far behind or forked. Instead, we should query all peers and use the highest one as our reference to sync with the network.

Where it requests the latest heads from all peers and only exits after a timeout. It then goes with the peer that has the highest canonical slot.

@@ -268,24 +274,6 @@ func (s *InitialSync) checkInMemoryBlocks() {
}
}

// listenForNewBlocks listens for block announcements beyond the canonical head slot that may
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer relevant as this is handled by regular sync

Copy link
Member

Choose a reason for hiding this comment

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

we still should have it, otherwise the node will always have to play catch up whenever it starts regular sync

@prestonvanloon
Copy link
Member

Build and lint errors

@stale
Copy link

stale bot commented Apr 24, 2019

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale There hasn't been any activity here in some time... label Apr 24, 2019
@rauljordan rauljordan removed the Stale There hasn't been any activity here in some time... label Apr 25, 2019
@terencechain
Copy link
Member

Build and test failing

@prestonvanloon
Copy link
Member

Test failures

@codecov
Copy link

codecov bot commented Apr 25, 2019

Codecov Report

Merging #2280 into master will decrease coverage by 1.4%.
The diff coverage is 86.36%.

@@            Coverage Diff             @@
##           master    #2280      +/-   ##
==========================================
- Coverage    66.6%   65.19%   -1.41%     
==========================================
  Files         119      119              
  Lines        9642     9533     -109     
==========================================
- Hits         6422     6215     -207     
- Misses       2503     2627     +124     
+ Partials      717      691      -26

@@ -17,6 +17,8 @@ import (
"sync"
"time"

peer "github.com/libp2p/go-libp2p-peer"

Copy link
Member

Choose a reason for hiding this comment

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

Space

@@ -5,6 +5,8 @@ import (
"math/big"
"time"

peer "github.com/libp2p/go-libp2p-peer"

Copy link
Member

Choose a reason for hiding this comment

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

Space

@@ -8,6 +8,8 @@ import (
"runtime/debug"
"sync"

peer "github.com/libp2p/go-libp2p-peer"

Copy link
Member

Choose a reason for hiding this comment

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

Space

@@ -184,6 +184,11 @@ func (s *Server) Status() error {
return nil
}

// Peers returns a slice of currently connected peer id's to be used throughout the runtime.
func (s *Server) Peers() peer.IDSlice {
return s.host.Peerstore().Peers()
Copy link
Member

Choose a reason for hiding this comment

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

Use s.host.Network().Peers()

@rauljordan rauljordan self-assigned this Apr 25, 2019
@rauljordan rauljordan added Priority: Critical Highest, immediate priority item Ready For Review labels Apr 25, 2019
@rauljordan rauljordan added this to the Sapphire milestone Apr 25, 2019
@rauljordan rauljordan requested a review from terencechain April 25, 2019 17:58
terencechain
terencechain previously approved these changes Apr 25, 2019
@rauljordan
Copy link
Contributor Author

PTAL @prestonvanloon

@@ -268,24 +274,6 @@ func (s *InitialSync) checkInMemoryBlocks() {
}
}

// listenForNewBlocks listens for block announcements beyond the canonical head slot that may
Copy link
Member

Choose a reason for hiding this comment

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

we still should have it, otherwise the node will always have to play catch up whenever it starts regular sync

@@ -96,11 +97,11 @@ func (s *InitialSync) processState(msg p2p.Message) {
}

// requestStateFromPeer requests for the canonical state, finalized state, and justified state from a peer.
func (s *InitialSync) requestStateFromPeer(ctx context.Context, lastFinalizedRoot [32]byte) error {
func (s *InitialSync) requestStateFromPeer(ctx context.Context, lastFinalizedRoot [32]byte, peerID peer.ID) error {
Copy link
Member

Choose a reason for hiding this comment

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

you should just use s.bestPeer here, since we are only going to sync with one peer

prestonvanloon
prestonvanloon previously approved these changes Apr 26, 2019
Copy link
Member

@prestonvanloon prestonvanloon left a comment

Choose a reason for hiding this comment

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

Minor comments. Overall LGTM.

This is a great interim solution until we rethink the sync logic with the weak subjectivity logic.

Thanks!

if msg.Peer != s.bestPeer {
// Only process batch block responses that come from the best peer
// we originally synced with.
log.Debugf("Received batch blocks from a different peer: %s", msg.Peer.Pretty())
Copy link
Member

Choose a reason for hiding this comment

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

Use WithField

case msg := <-q.responseBuf:
response := msg.Data.(*pb.ChainHeadResponse)
case <-timeout:
queryLog.Infof("Peer with highest canonical head: %v", q.bestPeer.Pretty())
Copy link
Member

Choose a reason for hiding this comment

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

These should conform to WithFields logging standard, please

// RequestLatestHead broadcasts out a request for all
// the latest chain heads from the node's peers.
// RequestLatestHead sends a request for all
// the latest chain head slot and state root to a peer.
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to change this comment back? It’s still broadcasting

prestonvanloon
prestonvanloon previously approved these changes Apr 26, 2019
@prestonvanloon
Copy link
Member

You have new lint issues

beacon-chain/sync/initial-sync/metrics.go:22:2: U1000: var `recBlockAnnounce` is unused (unused)
	recBlockAnnounce = promauto.NewCounter(prometheus.CounterOpts{
	^
beacon-chain/sync/initial-sync/sync_blocks.go:17:23: U1000: func `(*InitialSync).processBlockAnnounce` is unused (unused)
func (s *InitialSync) processBlockAnnounce(msg p2p.Message) {
                      ^
beacon-chain/sync/regular_sync_test.go:51:2: U1000: field `bFeed` is unused (unused)
	bFeed           *event.Feed
	^

@prestonvanloon prestonvanloon dismissed their stale review April 26, 2019 14:28

Lint issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Critical Highest, immediate priority item
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants