Skip to content

Commit 79024b3

Browse files
authored
Merge pull request #6733 from multiversx/further_notarization_fixes
more fixes on the notarization part
2 parents 2a79a9c + 99d6a13 commit 79024b3

File tree

5 files changed

+36
-27
lines changed

5 files changed

+36
-27
lines changed

process/block/baseProcess.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,3 +2232,12 @@ func (bp *baseProcessor) addPrevProofIfNeeded(header data.HeaderHandler) error {
22322232
header.SetPreviousProof(prevBlockProof)
22332233
return nil
22342234
}
2235+
2236+
func (bp *baseProcessor) getHeaderHash(header data.HeaderHandler) ([]byte, error) {
2237+
marshalledHeader, errMarshal := bp.marshalizer.Marshal(header)
2238+
if errMarshal != nil {
2239+
return nil, errMarshal
2240+
}
2241+
2242+
return bp.hasher.Compute(string(marshalledHeader)), nil
2243+
}

process/block/metablock.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,7 @@ func (mp *metaProcessor) checkShardHeadersValidity(metaHdr *block.MetaBlock) (ma
19041904
}
19051905
if mp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, shardHdr.GetEpoch()) {
19061906
if shardData.Epoch != shardHdr.GetEpoch() {
1907-
return nil, process.ErrEpochMissmatch
1907+
return nil, process.ErrEpochMismatch
19081908
}
19091909
}
19101910

@@ -1987,22 +1987,18 @@ func (mp *metaProcessor) checkShardHeadersFinality(
19871987
continue
19881988
}
19891989

1990+
isNotarizedBasedOnProofs, errCheckProof := mp.checkShardHeaderFinalityBasedOnProofs(lastVerifiedHdr, shardId)
1991+
if isNotarizedBasedOnProofs {
1992+
if errCheckProof != nil {
1993+
return errCheckProof
1994+
}
1995+
1996+
continue
1997+
}
1998+
19901999
// verify if there are "K" block after current to make this one final
19912000
nextBlocksVerified := uint32(0)
1992-
isNotarizedBasedOnProofs := false
19932001
for _, shardHdr := range finalityAttestingShardHdrs[shardId] {
1994-
var errCheckProof error
1995-
isNotarizedBasedOnProofs, errCheckProof = mp.checkShardHeaderFinalityBasedOnProofs(shardHdr, shardId)
1996-
// if the header is notarized based on proofs and there is no error, break the loop
1997-
// if there is any error, forward it, header is not final
1998-
if isNotarizedBasedOnProofs {
1999-
if errCheckProof != nil {
2000-
return err
2001-
}
2002-
2003-
break
2004-
}
2005-
20062002
if nextBlocksVerified >= mp.shardBlockFinality {
20072003
break
20082004
}
@@ -2016,6 +2012,15 @@ func (mp *metaProcessor) checkShardHeadersFinality(
20162012
continue
20172013
}
20182014

2015+
isNotarizedBasedOnProofs, errCheckProof = mp.checkShardHeaderFinalityBasedOnProofs(shardHdr, shardId)
2016+
if isNotarizedBasedOnProofs {
2017+
if errCheckProof != nil {
2018+
return errCheckProof
2019+
}
2020+
2021+
break
2022+
}
2023+
20192024
lastVerifiedHdr = shardHdr
20202025
nextBlocksVerified += 1
20212026
}

process/block/shardblock.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -640,15 +640,6 @@ func (sp *shardProcessor) checkMetaHdrFinality(header data.HeaderHandler) error
640640
return nil
641641
}
642642

643-
func (sp *shardProcessor) getHeaderHash(header data.HeaderHandler) ([]byte, error) {
644-
marshalledHeader, errMarshal := sp.marshalizer.Marshal(header)
645-
if errMarshal != nil {
646-
return nil, errMarshal
647-
}
648-
649-
return sp.hasher.Compute(string(marshalledHeader)), nil
650-
}
651-
652643
func (sp *shardProcessor) checkAndRequestIfMetaHeadersMissing() {
653644
orderedMetaBlocks, _ := sp.blockTracker.GetTrackedHeaders(core.MetachainShardId)
654645

process/errors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,5 +1275,5 @@ var ErrInvalidHeaderProof = errors.New("invalid equivalent proof")
12751275
// ErrUnexpectedHeaderProof signals that a header proof has been provided unexpectedly
12761276
var ErrUnexpectedHeaderProof = errors.New("unexpected header proof")
12771277

1278-
// ErrEpochMissmatch signals that the epoch do not match
1279-
var ErrEpochMissmatch = errors.New("epoch missmatch")
1278+
// ErrEpochMismatch signals that the epoch do not match
1279+
var ErrEpochMismatch = errors.New("epoch mismatch")

process/track/blockProcessor.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,11 @@ func (bp *blockProcessor) checkHeaderFinality(
316316

317317
if bp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, header.GetEpoch()) {
318318
// the index in argument is for the next block after header
319-
if bp.proofsPool.HasProof(header.GetShardID(), sortedHeadersHashes[index-1]) {
319+
hashIndex := index
320+
if index > 0 {
321+
hashIndex = index - 1
322+
}
323+
if bp.proofsPool.HasProof(header.GetShardID(), sortedHeadersHashes[hashIndex]) {
320324
return nil
321325
}
322326

@@ -339,7 +343,7 @@ func (bp *blockProcessor) checkHeaderFinality(
339343
// if the currentHeader(the one that should confirm the finality of the prev)
340344
// is the epoch start block of equivalent messages, we must check for its proof as well
341345
if bp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, currHeader.GetEpoch()) {
342-
if bp.proofsPool.HasProof(currHeader.GetShardID(), sortedHeadersHashes[index]) {
346+
if bp.proofsPool.HasProof(currHeader.GetShardID(), sortedHeadersHashes[i]) {
343347
return nil
344348
}
345349

0 commit comments

Comments
 (0)