Use saved head in DB

This commit is contained in:
Terence Tsao
2019-08-30 09:54:27 -07:00
parent 40e5f39cc5
commit c5f3404fdf

View File

@@ -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,
}