-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from 15 commits
7e1dd70
ebe6977
6bc8e96
f6b84ce
6920423
84521e4
47c499a
2007b69
d49b2af
9a9809d
ae4e008
55059da
eebfce7
9677a56
513b509
d3ef315
01f69e3
11ce6ad
574ca10
e5ebb19
75f32a9
70ccd16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package initialsync | |
import ( | ||
"context" | ||
|
||
peer "github.com/libp2p/go-libp2p-peer" | ||
"github.com/prysmaticlabs/prysm/shared/hashutil" | ||
|
||
"github.com/prysmaticlabs/prysm/beacon-chain/core/validators" | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
ctx, span := trace.StartSpan(ctx, "beacon-chain.sync.initial-sync.requestStateFromPeer") | ||
defer span.End() | ||
stateReq.Inc() | ||
return s.p2p.Send(ctx, &pb.BeaconStateRequest{ | ||
FinalizedStateRootHash32S: lastFinalizedRoot[:], | ||
}, p2p.AnyPeer) | ||
}, peerID) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
peer "github.com/libp2p/go-libp2p-peer" | ||
"github.com/prysmaticlabs/prysm/beacon-chain/db" | ||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" | ||
"github.com/prysmaticlabs/prysm/shared/bytesutil" | ||
|
@@ -57,6 +58,7 @@ type Querier struct { | |
powchain powChainService | ||
chainStarted bool | ||
atGenesis bool | ||
bestPeer peer.ID | ||
} | ||
|
||
// NewQuerierService constructs a new Sync Querier Service. | ||
|
@@ -151,34 +153,42 @@ func (q *Querier) run() { | |
ticker.Stop() | ||
}() | ||
|
||
q.RequestLatestHead() | ||
|
||
timeout := time.After(5 * time.Second) | ||
for { | ||
select { | ||
case <-q.ctx.Done(): | ||
queryLog.Info("Exiting goroutine") | ||
return | ||
case <-ticker.C: | ||
q.RequestLatestHead() | ||
case msg := <-q.responseBuf: | ||
response := msg.Data.(*pb.ChainHeadResponse) | ||
case <-timeout: | ||
queryLog.Infof("Peer with highest canonical head: %v", q.bestPeer.Pretty()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should conform to WithFields logging standard, please |
||
queryLog.Infof( | ||
"Latest chain head is at slot: %d and state root: %#x", | ||
response.CanonicalSlot-params.BeaconConfig().GenesisSlot, response.CanonicalStateRootHash32, | ||
q.currentHeadSlot-params.BeaconConfig().GenesisSlot, q.currentStateRoot, | ||
) | ||
q.currentHeadSlot = response.CanonicalSlot | ||
q.currentStateRoot = response.CanonicalStateRootHash32 | ||
q.currentFinalizedStateRoot = bytesutil.ToBytes32(response.FinalizedStateRootHash32S) | ||
|
||
ticker.Stop() | ||
responseSub.Unsubscribe() | ||
q.cancel() | ||
case msg := <-q.responseBuf: | ||
response := msg.Data.(*pb.ChainHeadResponse) | ||
queryLog.WithFields(logrus.Fields{ | ||
"peerID": msg.Peer.Pretty(), | ||
"highestSlot": response.CanonicalSlot - params.BeaconConfig().GenesisSlot, | ||
}).Info("Received chain head from peer") | ||
if response.CanonicalSlot > q.currentHeadSlot { | ||
q.currentHeadSlot = response.CanonicalSlot | ||
q.bestPeer = msg.Peer | ||
q.currentHeadSlot = response.CanonicalSlot | ||
q.currentStateRoot = response.CanonicalStateRootHash32 | ||
q.currentFinalizedStateRoot = bytesutil.ToBytes32(response.FinalizedStateRootHash32S) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to change this comment back? It’s still broadcasting |
||
func (q *Querier) RequestLatestHead() { | ||
request := &pb.ChainHeadRequest{} | ||
q.p2p.Broadcast(context.Background(), request) | ||
|
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.
No longer relevant as this is handled by regular sync
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.
we still should have it, otherwise the node will always have to play catch up whenever it starts regular sync