diff --git a/epochStart/metachain/epochStartData.go b/epochStart/metachain/epochStartData.go index ba0482085a0..c0553ee6e90 100644 --- a/epochStart/metachain/epochStartData.go +++ b/epochStart/metachain/epochStartData.go @@ -183,6 +183,7 @@ func (e *epochStartData) CreateEpochStartData() (*block.EpochStart, error) { func (e *epochStartData) CreateEpochStartShardDataMetablockV3(metablock data.MetaHeaderHandler) ([]block.EpochStartShardData, error) { log.Debug("CreateEpochStartShardDataMetablockV3", "metablock epoch", metablock.GetEpoch(), + "for epoch", metablock.GetEpoch()+1, "isEpochChangeProposed", metablock.IsEpochChangeProposed(), "trigger epoch", e.epochStartTrigger.Epoch()) @@ -390,17 +391,34 @@ func (e *epochStartData) getShardDataFromEpochStartData( return nil, nil, process.ErrGettingShardDataFromEpochStartData } +func (e *epochStartData) getPrevEpoch() uint32 { + prevEpoch := e.genesisEpoch + + epochStartTriggerEpoch := e.epochStartTrigger.Epoch() + + if epochStartTriggerEpoch <= e.genesisEpoch { + return prevEpoch + } + + prevEpoch = e.epochStartTrigger.Epoch() + + isAfterSupernova := epochStartTriggerEpoch > e.enableEpochsHandler.GetActivationEpoch(common.SupernovaFlag) + if !isAfterSupernova { + prevEpoch-- + } + + return prevEpoch +} + func (e *epochStartData) computePendingMiniBlockList( startData *block.EpochStart, allShardHdrList [][]data.HeaderHandler, ) ([]block.MiniBlockHeader, error) { - - prevEpoch := e.genesisEpoch - if e.epochStartTrigger.Epoch() > e.genesisEpoch { - prevEpoch = e.epochStartTrigger.Epoch() - 1 - } + prevEpoch := e.getPrevEpoch() epochStartIdentifier := core.EpochStartIdentifier(prevEpoch) + + // TODO: analyse error handling here previousEpochStartMeta, _ := process.GetMetaHeaderFromStorage([]byte(epochStartIdentifier), e.marshalizer, e.store) allPending := make([]block.MiniBlockHeader, 0) diff --git a/epochStart/metachain/trigger.go b/epochStart/metachain/trigger.go index 36b06d51fad..2382b00e64a 100644 --- a/epochStart/metachain/trigger.go +++ b/epochStart/metachain/trigger.go @@ -261,7 +261,7 @@ func (t *trigger) Update(round uint64, nonce uint64) { } if t.shouldTriggerEpochStart(round, nonce) { - t.setEpochChange(round) + t.setEpochChange(round, t.epoch+1) } } @@ -270,11 +270,11 @@ func (t *trigger) SetEpochChange(round uint64) { t.mutTrigger.Lock() defer t.mutTrigger.Unlock() - t.setEpochChange(round) + t.setEpochChange(round, t.epoch+1) } -func (t *trigger) setEpochChange(round uint64) { - t.epoch += 1 +func (t *trigger) setEpochChange(round uint64, epoch uint32) { + t.epoch = epoch t.isEpochStart = true t.prevEpochStartRound = t.currEpochStartRound t.currEpochStartRound = round @@ -300,7 +300,7 @@ func (t *trigger) SetProcessed(header data.HeaderHandler, body data.BodyHandler) } if header.IsHeaderV3() { - t.setEpochChange(header.GetRound()) + t.setEpochChange(header.GetRound(), header.GetEpoch()) } metaBuff, errNotCritical := t.marshaller.Marshal(metaBlock) diff --git a/storage/pruning/pruningStorer.go b/storage/pruning/pruningStorer.go index f4895f3b54f..5968aca448a 100644 --- a/storage/pruning/pruningStorer.go +++ b/storage/pruning/pruningStorer.go @@ -978,7 +978,7 @@ func (ps *PruningStorer) changeEpochWithExisting(epoch uint32) error { for e := int64(epoch); e >= oldestEpochActive; e-- { p, ok := ps.persistersMapByEpoch[uint32(e)] if !ok { - return nil + continue } persisters = append(persisters, p) } @@ -1007,7 +1007,7 @@ func (ps *PruningStorer) extendActivePersisters(from uint32, to uint32) error { for e := int(to); e >= int(from); e-- { p, ok := ps.persistersMapByEpoch[uint32(e)] if !ok { - return nil + continue } persisters = append(persisters, p) }