Skip to content

Commit ef1c058

Browse files
authored
Merge pull request #7885 from multiversx/request-epoch-start-block-in-case-of-error
request epoch start block
2 parents 38e135a + a0244a9 commit ef1c058

4 files changed

Lines changed: 379 additions & 2 deletions

File tree

process/block/export_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,11 @@ func (sp *shardProcessor) CheckEpochStartInfoAvailableIfNeeded(header data.Shard
909909
return sp.checkEpochStartInfoAvailableIfNeeded(header)
910910
}
911911

912+
// EnsureEpochStartInfoAvailable -
913+
func (sp *shardProcessor) EnsureEpochStartInfoAvailable(header data.ShardHeaderHandler, haveTime func() time.Duration) error {
914+
return sp.ensureEpochStartInfoAvailable(header, haveTime)
915+
}
916+
912917
// HeadersPool -
913918
func (sp *shardProcessor) HeadersPool() dataRetriever.HeadersPool {
914919
return sp.dataPool.Headers()

process/block/shardblock.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,36 @@ func (sp *shardProcessor) checkEpochStartInfoAvailableIfNeeded(header data.Shard
301301
return nil
302302
}
303303

304+
func (sp *shardProcessor) ensureEpochStartInfoAvailable(header data.ShardHeaderHandler, haveTime func() time.Duration) error {
305+
err := sp.checkEpochStartInfoAvailableIfNeeded(header)
306+
if err == nil {
307+
return nil
308+
}
309+
310+
log.Warn("epoch start info missing at execution, requesting",
311+
"epochStartMetaHash", header.GetEpochStartMetaHash(),
312+
"error", err,
313+
)
314+
315+
requestCount := 0
316+
for haveTime() > 0 {
317+
requestCount++
318+
if requestCount%5 == 1 {
319+
go sp.requestHandler.RequestMetaHeader(header.GetEpochStartMetaHash())
320+
sp.requestEpochStartProofIfNeeded(header.GetEpochStartMetaHash(), header.GetEpoch())
321+
}
322+
323+
time.Sleep(timeBetweenCheckForEpochStart)
324+
325+
err = sp.checkEpochStartInfoAvailableIfNeeded(header)
326+
if err == nil {
327+
return nil
328+
}
329+
}
330+
331+
return err
332+
}
333+
304334
func (sp *shardProcessor) requestEpochStartInfo(header data.ShardHeaderHandler, haveTime func() time.Duration) error {
305335
if !sp.shouldEpochStartInfoBeAvailable(header) {
306336
return nil

process/block/shardblockProposal.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ func (sp *shardProcessor) ProcessBlockProposal(
338338
return nil, err
339339
}
340340

341-
// TODO: improvement - add also a request if it is missing as a fallback, although it should not be missing at this point
342-
err = sp.checkEpochStartInfoAvailableIfNeeded(header)
341+
err = sp.ensureEpochStartInfoAvailable(header, haveTime)
343342
if err != nil {
344343
return nil, err
345344
}

0 commit comments

Comments
 (0)