Invert init-sync-batch-save-blocks flag for v0.11 (#5293)

This commit is contained in:
terence tsao
2020-04-02 14:46:14 -07:00
committed by GitHub
parent b43e43b4a9
commit 3544ed2818
7 changed files with 37 additions and 28 deletions

View File

@@ -170,14 +170,20 @@ func (s *Service) generateState(ctx context.Context, startRoot [32]byte, endRoot
return nil, err
}
if preState == nil {
return nil, errors.New("finalized state does not exist in db")
}
var endBlock *ethpb.SignedBeaconBlock
if featureconfig.Get().InitSyncBatchSaveBlocks && s.hasInitSyncBlock(endRoot) {
if err := s.beaconDB.SaveBlocks(ctx, s.getInitSyncBlocks()); err != nil {
preState, err = s.stateGen.StateByRoot(ctx, startRoot)
if err != nil {
return nil, err
}
if preState == nil {
return nil, errors.New("finalized state does not exist in db")
}
}
if err := s.beaconDB.SaveBlocks(ctx, s.getInitSyncBlocks()); err != nil {
return nil, err
}
var endBlock *ethpb.SignedBeaconBlock
if !featureconfig.Get().NoInitSyncBatchSaveBlocks && s.hasInitSyncBlock(endRoot) {
s.clearInitSyncBlocks()
endBlock = s.getInitSyncBlock(endRoot)
} else {

View File

@@ -219,7 +219,7 @@ func (s *Service) onBlockInitialSyncStateTransition(ctx context.Context, signed
if err != nil {
return errors.Wrapf(err, "could not get signing root of block %d", b.Slot)
}
if featureconfig.Get().InitSyncBatchSaveBlocks {
if !featureconfig.Get().NoInitSyncBatchSaveBlocks {
s.saveInitSyncBlock(root, signed)
} else {
if err := s.beaconDB.SaveBlock(ctx, signed); err != nil {
@@ -281,7 +281,7 @@ func (s *Service) onBlockInitialSyncStateTransition(ctx context.Context, signed
}
}
if featureconfig.Get().InitSyncBatchSaveBlocks {
if !featureconfig.Get().NoInitSyncBatchSaveBlocks {
if err := s.beaconDB.SaveBlocks(ctx, s.getInitSyncBlocks()); err != nil {
return err
}

View File

@@ -232,7 +232,7 @@ func (s *Service) shouldUpdateCurrentJustified(ctx context.Context, newJustified
var newJustifiedBlockSigned *ethpb.SignedBeaconBlock
justifiedRoot := bytesutil.ToBytes32(newJustifiedCheckpt.Root)
var err error
if featureconfig.Get().InitSyncBatchSaveBlocks && s.hasInitSyncBlock(justifiedRoot) {
if !featureconfig.Get().NoInitSyncBatchSaveBlocks && s.hasInitSyncBlock(justifiedRoot) {
newJustifiedBlockSigned = s.getInitSyncBlock(justifiedRoot)
} else {
newJustifiedBlockSigned, err = s.beaconDB.Block(ctx, justifiedRoot)
@@ -250,7 +250,7 @@ func (s *Service) shouldUpdateCurrentJustified(ctx context.Context, newJustified
}
var justifiedBlockSigned *ethpb.SignedBeaconBlock
cachedJustifiedRoot := bytesutil.ToBytes32(s.justifiedCheckpt.Root)
if featureconfig.Get().InitSyncBatchSaveBlocks && s.hasInitSyncBlock(cachedJustifiedRoot) {
if !featureconfig.Get().NoInitSyncBatchSaveBlocks && s.hasInitSyncBlock(cachedJustifiedRoot) {
justifiedBlockSigned = s.getInitSyncBlock(cachedJustifiedRoot)
} else {
justifiedBlockSigned, err = s.beaconDB.Block(ctx, cachedJustifiedRoot)
@@ -394,7 +394,7 @@ func (s *Service) ancestor(ctx context.Context, root []byte, slot uint64) ([]byt
return nil, errors.Wrap(err, "could not get ancestor block")
}
if featureconfig.Get().InitSyncBatchSaveBlocks && s.hasInitSyncBlock(bytesutil.ToBytes32(root)) {
if !featureconfig.Get().NoInitSyncBatchSaveBlocks && s.hasInitSyncBlock(bytesutil.ToBytes32(root)) {
signed = s.getInitSyncBlock(bytesutil.ToBytes32(root))
}

View File

@@ -175,7 +175,7 @@ func (s *Service) roundRobinSync(genesis time.Time) error {
}
}
var startBlock uint64
if featureconfig.Get().InitSyncBatchSaveBlocks {
if !featureconfig.Get().NoInitSyncBatchSaveBlocks {
lastFinalizedEpoch := s.chain.FinalizedCheckpt().Epoch
lastFinalizedState, err := s.db.HighestSlotStatesBelow(ctx, helpers.StartSlot(lastFinalizedEpoch))
if err != nil {

View File

@@ -251,22 +251,27 @@ func TestRoundRobinSync(t *testing.T) {
genesisRoot := cache.rootCache[0]
cache.RUnlock()
err := beaconDB.SaveBlock(context.Background(), &eth.SignedBeaconBlock{
gBlock := &eth.SignedBeaconBlock{
Block: &eth.BeaconBlock{
Slot: 0,
}})
}}
err := beaconDB.SaveBlock(context.Background(), gBlock)
if err != nil {
t.Fatal(err)
}
gRoot, _ := ssz.HashTreeRoot(gBlock.Block)
beaconDB.SaveGenesisBlockRoot(context.Background(), gRoot)
st, err := stateTrie.InitializeFromProto(&p2ppb.BeaconState{})
if err != nil {
t.Fatal(err)
}
beaconDB.SaveState(context.Background(), st, gRoot)
mc := &mock.ChainService{
State: st,
Root: genesisRoot[:],
DB: beaconDB,
State: st,
Root: genesisRoot[:],
DB: beaconDB,
FinalizedCheckPoint: &eth.Checkpoint{Epoch: helpers.SlotToEpoch(st.Slot())},
} // no-op mock
s := &Service{
chain: mc,

View File

@@ -53,7 +53,7 @@ type Flags struct {
DisableInitSyncQueue bool // DisableInitSyncQueue disables the new initial sync implementation.
EnableFieldTrie bool // EnableFieldTrie enables the state from using field specific tries when computing the root.
EnableBlockHTR bool // EnableBlockHTR enables custom hashing of our beacon blocks.
InitSyncBatchSaveBlocks bool // InitSyncBatchSaveBlocks enables batch save blocks mode during initial syncing.
NoInitSyncBatchSaveBlocks bool // NoInitSyncBatchSaveBlocks disables batch save blocks mode during initial syncing.
// DisableForkChoice disables using LMD-GHOST fork choice to update
// the head of the chain based on attestations and instead accepts any valid received block
// as the chain head. UNSAFE, use with caution.
@@ -186,9 +186,9 @@ func ConfigureBeaconChain(ctx *cli.Context) {
log.Warn("Enabling custom block hashing")
cfg.EnableBlockHTR = true
}
if ctx.Bool(initSyncBatchSaveBlocks.Name) {
log.Warn("Enabling init sync batch save blocks mode")
cfg.InitSyncBatchSaveBlocks = true
if ctx.Bool(disableInitSyncBatchSaveBlocks.Name) {
log.Warn("Disabling init sync batch save blocks mode")
cfg.NoInitSyncBatchSaveBlocks = true
}
Init(cfg)
}

View File

@@ -137,10 +137,9 @@ var (
Name: "enable-custom-block-htr",
Usage: "Enables the usage of a custom hashing method for our block",
}
initSyncBatchSaveBlocks = &cli.BoolFlag{
Name: "init-sync-batch-save-blocks",
Usage: "Instead of saving one block per slot to the DB during initial syncing, this enables batch saving" +
" of epochs worth of blocks to the DB",
disableInitSyncBatchSaveBlocks = &cli.BoolFlag{
Name: "disable-init-sync-batch-save-blocks",
Usage: "Instead of saving batch blocks to the DB during initial syncing, this disables batch saving of blocks",
}
)
@@ -345,7 +344,7 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{
disableInitSyncQueue,
enableFieldTrie,
enableCustomBlockHTR,
initSyncBatchSaveBlocks,
disableInitSyncBatchSaveBlocks,
}...)
// E2EBeaconChainFlags contains a list of the beacon chain feature flags to be tested in E2E.
@@ -357,7 +356,6 @@ var E2EBeaconChainFlags = []string{
"--enable-state-gen-sig-verify",
"--check-head-state",
"--enable-state-field-trie",
"--init-sync-batch-save-blocks",
// TODO(5123): This flag currently fails E2E. Commenting until it's resolved.
//"--enable-dynamic-committee-subnets",
}