Skip to content

Commit 839b187

Browse files
authored
Merge pull request #7596 from multiversx/fix-trigger-epoch-start-on-boot
Fix trigger epoch start on boot
2 parents dafbec8 + aa30a9b commit 839b187

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

epochStart/metachain/epochStartData.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func (e *epochStartData) CreateEpochStartData() (*block.EpochStart, error) {
183183
func (e *epochStartData) CreateEpochStartShardDataMetablockV3(metablock data.MetaHeaderHandler) ([]block.EpochStartShardData, error) {
184184
log.Debug("CreateEpochStartShardDataMetablockV3",
185185
"metablock epoch", metablock.GetEpoch(),
186+
"for epoch", metablock.GetEpoch()+1,
186187
"isEpochChangeProposed", metablock.IsEpochChangeProposed(),
187188
"trigger epoch", e.epochStartTrigger.Epoch())
188189

@@ -390,17 +391,34 @@ func (e *epochStartData) getShardDataFromEpochStartData(
390391
return nil, nil, process.ErrGettingShardDataFromEpochStartData
391392
}
392393

394+
func (e *epochStartData) getPrevEpoch() uint32 {
395+
prevEpoch := e.genesisEpoch
396+
397+
epochStartTriggerEpoch := e.epochStartTrigger.Epoch()
398+
399+
if epochStartTriggerEpoch <= e.genesisEpoch {
400+
return prevEpoch
401+
}
402+
403+
prevEpoch = e.epochStartTrigger.Epoch()
404+
405+
isAfterSupernova := epochStartTriggerEpoch > e.enableEpochsHandler.GetActivationEpoch(common.SupernovaFlag)
406+
if !isAfterSupernova {
407+
prevEpoch--
408+
}
409+
410+
return prevEpoch
411+
}
412+
393413
func (e *epochStartData) computePendingMiniBlockList(
394414
startData *block.EpochStart,
395415
allShardHdrList [][]data.HeaderHandler,
396416
) ([]block.MiniBlockHeader, error) {
397-
398-
prevEpoch := e.genesisEpoch
399-
if e.epochStartTrigger.Epoch() > e.genesisEpoch {
400-
prevEpoch = e.epochStartTrigger.Epoch() - 1
401-
}
417+
prevEpoch := e.getPrevEpoch()
402418

403419
epochStartIdentifier := core.EpochStartIdentifier(prevEpoch)
420+
421+
// TODO: analyse error handling here
404422
previousEpochStartMeta, _ := process.GetMetaHeaderFromStorage([]byte(epochStartIdentifier), e.marshalizer, e.store)
405423

406424
allPending := make([]block.MiniBlockHeader, 0)

epochStart/metachain/trigger.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (t *trigger) Update(round uint64, nonce uint64) {
261261
}
262262

263263
if t.shouldTriggerEpochStart(round, nonce) {
264-
t.setEpochChange(round)
264+
t.setEpochChange(round, t.epoch+1)
265265
}
266266
}
267267

@@ -270,11 +270,11 @@ func (t *trigger) SetEpochChange(round uint64) {
270270
t.mutTrigger.Lock()
271271
defer t.mutTrigger.Unlock()
272272

273-
t.setEpochChange(round)
273+
t.setEpochChange(round, t.epoch+1)
274274
}
275275

276-
func (t *trigger) setEpochChange(round uint64) {
277-
t.epoch += 1
276+
func (t *trigger) setEpochChange(round uint64, epoch uint32) {
277+
t.epoch = epoch
278278
t.isEpochStart = true
279279
t.prevEpochStartRound = t.currEpochStartRound
280280
t.currEpochStartRound = round
@@ -300,7 +300,7 @@ func (t *trigger) SetProcessed(header data.HeaderHandler, body data.BodyHandler)
300300
}
301301

302302
if header.IsHeaderV3() {
303-
t.setEpochChange(header.GetRound())
303+
t.setEpochChange(header.GetRound(), header.GetEpoch())
304304
}
305305

306306
metaBuff, errNotCritical := t.marshaller.Marshal(metaBlock)

storage/pruning/pruningStorer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ func (ps *PruningStorer) changeEpochWithExisting(epoch uint32) error {
978978
for e := int64(epoch); e >= oldestEpochActive; e-- {
979979
p, ok := ps.persistersMapByEpoch[uint32(e)]
980980
if !ok {
981-
return nil
981+
continue
982982
}
983983
persisters = append(persisters, p)
984984
}
@@ -1007,7 +1007,7 @@ func (ps *PruningStorer) extendActivePersisters(from uint32, to uint32) error {
10071007
for e := int(to); e >= int(from); e-- {
10081008
p, ok := ps.persistersMapByEpoch[uint32(e)]
10091009
if !ok {
1010-
return nil
1010+
continue
10111011
}
10121012
persisters = append(persisters, p)
10131013
}

0 commit comments

Comments
 (0)