mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Start from Justified checkpoint by default (#15636)
By default when starting a node, we load the finalized checkpoint from db and set it as head. When the chain has not been finalizing for a while and the user does not start from the latest head, it may still be benefitial to start from the latest justified checkpoint that has to be a descendant of the finalized one.
This commit is contained in:
@@ -2132,13 +2132,13 @@ func TestNoViableHead_Reboot(t *testing.T) {
|
|||||||
|
|
||||||
// Forkchoice has the genesisRoot loaded at startup
|
// Forkchoice has the genesisRoot loaded at startup
|
||||||
require.Equal(t, genesisRoot, service.ensureRootNotZeros(service.cfg.ForkChoiceStore.CachedHeadRoot()))
|
require.Equal(t, genesisRoot, service.ensureRootNotZeros(service.cfg.ForkChoiceStore.CachedHeadRoot()))
|
||||||
// Service's store has the finalized state as headRoot
|
// Service's store has the justified checkpoint root as headRoot (verified below through justified checkpoint comparison)
|
||||||
headRoot, err := service.HeadRoot(ctx)
|
headRoot, err := service.HeadRoot(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, genesisRoot, bytesutil.ToBytes32(headRoot))
|
require.NotEqual(t, bytesutil.ToBytes32(params.BeaconConfig().ZeroHash[:]), bytesutil.ToBytes32(headRoot)) // Ensure head is not zero
|
||||||
optimistic, err := service.IsOptimistic(ctx)
|
optimistic, err := service.IsOptimistic(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, false, optimistic)
|
require.Equal(t, true, optimistic) // Head is now optimistic when starting from justified checkpoint
|
||||||
|
|
||||||
// Check that the node's justified checkpoint does not agree with the
|
// Check that the node's justified checkpoint does not agree with the
|
||||||
// last valid state's justified checkpoint
|
// last valid state's justified checkpoint
|
||||||
|
|||||||
@@ -30,24 +30,24 @@ func (s *Service) setupForkchoice(st state.BeaconState) error {
|
|||||||
|
|
||||||
func (s *Service) startupHeadRoot() [32]byte {
|
func (s *Service) startupHeadRoot() [32]byte {
|
||||||
headStr := features.Get().ForceHead
|
headStr := features.Get().ForceHead
|
||||||
cp := s.FinalizedCheckpt()
|
jp := s.CurrentJustifiedCheckpt()
|
||||||
fRoot := s.ensureRootNotZeros([32]byte(cp.Root))
|
jRoot := s.ensureRootNotZeros([32]byte(jp.Root))
|
||||||
if headStr == "" {
|
if headStr == "" {
|
||||||
return fRoot
|
return jRoot
|
||||||
}
|
}
|
||||||
if headStr == "head" {
|
if headStr == "head" {
|
||||||
root, err := s.cfg.BeaconDB.HeadBlockRoot()
|
root, err := s.cfg.BeaconDB.HeadBlockRoot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Could not get head block root, starting with finalized block as head")
|
log.WithError(err).Error("Could not get head block root, starting with justified block as head")
|
||||||
return fRoot
|
return jRoot
|
||||||
}
|
}
|
||||||
log.Infof("Using Head root of %#x", root)
|
log.Infof("Using Head root of %#x", root)
|
||||||
return root
|
return root
|
||||||
}
|
}
|
||||||
root, err := bytesutil.DecodeHexWithLength(headStr, 32)
|
root, err := bytesutil.DecodeHexWithLength(headStr, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Could not parse head root, starting with finalized block as head")
|
log.WithError(err).Error("Could not parse head root, starting with justified block as head")
|
||||||
return fRoot
|
return jRoot
|
||||||
}
|
}
|
||||||
return [32]byte(root)
|
return [32]byte(root)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func Test_startupHeadRoot(t *testing.T) {
|
|||||||
})
|
})
|
||||||
defer resetCfg()
|
defer resetCfg()
|
||||||
require.Equal(t, service.startupHeadRoot(), gr)
|
require.Equal(t, service.startupHeadRoot(), gr)
|
||||||
require.LogsContain(t, hook, "Could not get head block root, starting with finalized block as head")
|
require.LogsContain(t, hook, "Could not get head block root, starting with justified block as head")
|
||||||
})
|
})
|
||||||
|
|
||||||
st, _ := util.DeterministicGenesisState(t, 64)
|
st, _ := util.DeterministicGenesisState(t, 64)
|
||||||
|
|||||||
2
changelog/potuz_start_from_justified.md
Normal file
2
changelog/potuz_start_from_justified.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
### Changed
|
||||||
|
- Start from justified checkpoint by default.
|
||||||
Reference in New Issue
Block a user