mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
Use saved head in DB
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
@@ -70,8 +71,12 @@ func (s *InitialSync) Start() {
|
||||
return
|
||||
}
|
||||
|
||||
// Get last saved head block in DB
|
||||
headBlock, _ := s.db.HeadBlock(context.Background())
|
||||
headRoot, _ := ssz.SigningRoot(headBlock)
|
||||
|
||||
// Are we already in sync, or close to it?
|
||||
if helpers.SlotToEpoch(s.chain.HeadSlot()) == helpers.SlotToEpoch(currentSlot) {
|
||||
if helpers.SlotToEpoch(headBlock.Slot) == helpers.SlotToEpoch(currentSlot) {
|
||||
log.Info("Already synced to the current epoch.")
|
||||
return
|
||||
}
|
||||
@@ -94,10 +99,10 @@ func (s *InitialSync) Start() {
|
||||
pid, best := bestHello(s.helloTracker.Hellos())
|
||||
|
||||
var last *eth.BeaconBlock
|
||||
for headSlot := s.chain.HeadSlot(); headSlot < uint64(roughtime.Since(genesis).Seconds()) / params.BeaconConfig().SecondsPerSlot; {
|
||||
for headSlot := headBlock.Slot; headSlot < uint64(roughtime.Since(genesis).Seconds()) / params.BeaconConfig().SecondsPerSlot; {
|
||||
req := &pb.BeaconBlocksRequest{
|
||||
HeadSlot: headSlot,
|
||||
HeadBlockRoot: s.chain.HeadRoot(),
|
||||
HeadBlockRoot: headRoot[:],
|
||||
Count: 64,
|
||||
Step: 1,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user