-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metachain notarizez based on equivalent proofs #6513
base: feat/equivalent-messages
Are you sure you want to change the base?
Conversation
process/block/baseProcess.go
Outdated
@@ -639,7 +642,7 @@ func (bp *baseProcessor) sortHeaderHashesForCurrentBlockByNonce(usedInBlock bool | |||
|
|||
bp.hdrsForCurrBlock.mutHdrsForBlock.RLock() | |||
for metaBlockHash, headerInfo := range bp.hdrsForCurrBlock.hdrHashAndInfo { | |||
if headerInfo.usedInBlock != usedInBlock { | |||
if headerInfo.usedInBlock != usedInBlock || !headerInfo.hasProof { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that if a header is used in block but has no valid proof, then this is an error case
Could you add the condition separately and log an error for that?
in case we end up in this case we need to find out how it happened and fix.
When picking up a header to notarize it, and adding it to usedInBlock then it should have already been checked that there is a valid proof for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usedInBlock
field is set to true also when shard headers are requested.. it is basically set in advance to true, even though the header is missing.. so maybe the proof would be received later.. not sure if this is possible though
@@ -1081,8 +1089,18 @@ func (mp *metaProcessor) createAndProcessCrossMiniBlocksDstMe( | |||
continue | |||
} | |||
|
|||
shouldCheckProof := mp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, currShardHdr.GetEpoch()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the computeLongestChainFromLastNotarized would return I think the chain of headers without the last one (which is considered the confirmation for the last returned one).
Was computeLongestChainFromLastNotarized updated for equivalent proofs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the blockProcessor as well
isBlockAfterEquivalentMessagesFlag := !check.IfNil(lastMetaBlock) && | ||
mp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, lastMetaBlock.GetEpoch()) | ||
if isBlockAfterEquivalentMessagesFlag { | ||
// for the first block we need to update both the state of the previous one and for current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and for all future blocks, updateState should be done only for current, not lastMetaBlock.
I would use a different variable e.g finalMetaBlock and not overwrite the lastMetaBlock (that should still point to the last committed meta block not the one currently being committed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should work as described, updated the variable name for clarity
process/block/metablock.go
Outdated
@@ -1838,6 +1867,20 @@ func (mp *metaProcessor) checkShardHeadersFinality( | |||
continue | |||
} | |||
|
|||
if mp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, lastVerifiedHdr.GetEpoch()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this loop is correct, as it does not get to iterate over all shard headers and verify.
it returns either a nil or an error in the first iteration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, moved this if into the next for loop and switched the return nil
into a break
process/block/metablock.go
Outdated
hasProof := mp.proofsPool.HasProof(shardHeader.GetShardID(), shardHeaderHash) | ||
hdrInfoForHash.hasProof = hasProof | ||
if hasProof { | ||
mp.hdrsForCurrBlock.missingHdrsProofs-- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missingHdrsProofs should be decreased if that proof was missing previously and still missing at this step only
e.g you receive a shard hdr which is not part of the metablock (an older block maybe), so here you would end up decreasing the missing headers proofs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the condition, it was not working as expected
@@ -1994,13 +2059,24 @@ func (mp *metaProcessor) computeExistingAndRequestMissingShardHeaders(metaBlock | |||
if hdr.GetNonce() > mp.hdrsForCurrBlock.highestHdrNonce[shardData.ShardID] { | |||
mp.hdrsForCurrBlock.highestHdrNonce[shardData.ShardID] = hdr.GetNonce() | |||
} | |||
|
|||
if mp.shouldConsiderProofsForNotarization(hdr) { | |||
notarizedShardHdrsBasedOnProofs++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of incrementing the missing headers proofs, maybe use a map for the missing header proofs, with key the header hash
then you could correctly check which proofs are still missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
process/block/metablock.go
Outdated
mp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, headerInfo.hdr.GetEpoch()) | ||
hasMissingProof := isBlockAfterEquivalentMessagesFlag && !headerInfo.hasProof | ||
if hasMissingProof { | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an error if a header was used in block but has no proof, should not continue but return an error.
If we get such errors, then we need to fix in the place where the headers are notarized, as there should be the check that the notarized headers have the proper proof.
Please check that the shardInfo (createShardInfo) contains the proof for the shard header itself, along with the proof for the previous block.
This means that the shardInfo would change as well to include 2 proofs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to return error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated also to use both proofs
process/block/shardblock.go
Outdated
core.MetachainShardId, | ||
sp.metaBlockFinality, | ||
) | ||
if !sp.shouldConsiderProofsForNotarization(metaBlock) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on the else, you should at least check that there is a valid proof for this metablock, otherwise add it to the missing proofs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
process/block/metablock.go
Outdated
if mp.hdrsForCurrBlock.missingHdrs == 0 { | ||
mp.hdrsForCurrBlock.missingFinalityAttestingHdrs = mp.requestMissingFinalityAttestingShardHeaders() | ||
if !mp.shouldConsiderProofsForNotarization(shardHeader) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on the else, you should check that there is a valid proof for this header, otherwise add it to the missing proofs.
process/block/shardblock.go
Outdated
hasProofForShardHdr := sp.proofsPool.HasProof(core.MetachainShardId, metaBlockHashes[i]) | ||
sp.hdrsForCurrBlock.hdrHashAndInfo[string(metaBlockHashes[i])].hasProof = hasProofForShardHdr | ||
if !hasProofForShardHdr { | ||
sp.hdrsForCurrBlock.missingHdrsProofs++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add the header hash in a map for missing proofs instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved the logic to be based on hasProof field, which is part of a map too
process/block/hdrForBlock.go
Outdated
@@ -9,6 +9,7 @@ import ( | |||
type hdrForBlock struct { | |||
missingHdrs uint32 | |||
missingFinalityAttestingHdrs uint32 | |||
missingHdrsProofs uint32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i might help to rename here to indicate that it's num missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed it
process/block/metablock.go
Outdated
if len(currShardHdr.GetMiniBlockHeadersWithDst(mp.shardCoordinator.SelfId())) == 0 { | ||
mp.hdrsForCurrBlock.hdrHashAndInfo[string(orderedHdrsHashes[i])] = &hdrInfo{hdr: currShardHdr, usedInBlock: true} | ||
mp.hdrsForCurrBlock.hdrHashAndInfo[string(orderedHdrsHashes[i])] = &hdrInfo{hdr: currShardHdr, usedInBlock: true, hasProof: true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split on multiple lines for better visibility? same below
process/block/metablock.go
Outdated
@@ -1081,8 +1089,18 @@ func (mp *metaProcessor) createAndProcessCrossMiniBlocksDstMe( | |||
continue | |||
} | |||
|
|||
shouldCheckProof := mp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, currShardHdr.GetEpoch()) | |||
hasProofForHdr := mp.proofsPool.HasProof(currShardHdr.GetShardID(), orderedHdrsHashes[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think here we should check if HasProof
only if shouldCheckProof
is true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, optimization.. implemented it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adapt also sortHeadersForCurrentBlockByNonce
to have hasProof check?
process/block/baseProcess.go
Outdated
@@ -639,7 +642,7 @@ func (bp *baseProcessor) sortHeaderHashesForCurrentBlockByNonce(usedInBlock bool | |||
|
|||
bp.hdrsForCurrBlock.mutHdrsForBlock.RLock() | |||
for metaBlockHash, headerInfo := range bp.hdrsForCurrBlock.hdrHashAndInfo { | |||
if headerInfo.usedInBlock != usedInBlock { | |||
if headerInfo.usedInBlock != usedInBlock || !headerInfo.hasProof { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check for enabled flag here?
process/block/metablock.go
Outdated
@@ -1838,6 +1867,20 @@ func (mp *metaProcessor) checkShardHeadersFinality( | |||
continue | |||
} | |||
|
|||
if mp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, lastVerifiedHdr.GetEpoch()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it fits better to check proof in checkShardHeadersValidity
which is called just before instead of here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should stay here, as here is the place where we check for finality
process/block/shardblock.go
Outdated
|
||
headerHash := sp.hasher.Compute(string(marshalledHeader)) | ||
if !sp.proofsPool.HasProof(header.GetShardID(), headerHash) { | ||
return process.ErrHeaderNotFinal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return a composed error here to indicate also that the proof is missing?
process/block/shardblock.go
Outdated
createAndProcessInfo.currMetaHdrHash = orderedMetaBlocksHashes[i] | ||
if len(createAndProcessInfo.currMetaHdr.GetMiniBlockHeadersWithDst(sp.shardCoordinator.SelfId())) == 0 { | ||
sp.hdrsForCurrBlock.hdrHashAndInfo[string(createAndProcessInfo.currMetaHdrHash)] = &hdrInfo{hdr: createAndProcessInfo.currMetaHdr, usedInBlock: true} | ||
sp.hdrsForCurrBlock.hdrHashAndInfo[string(createAndProcessInfo.currMetaHdrHash)] = &hdrInfo{hdr: createAndProcessInfo.currMetaHdr, usedInBlock: true, hasProof: true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion to expand on multiple lines
…rsx/mx-chain-go into adapt_notarization # Conflicts: # process/block/baseProcess.go
…rsx/mx-chain-go into adapt_notarization # Conflicts: # integrationTests/multiShard/endOfEpoch/startInEpoch/startInEpoch_test.go # integrationTests/multiShard/hardFork/hardFork_test.go # process/block/shardblock.go
…more with the new flow
process/block/metablock.go
Outdated
// check proofs for shard data | ||
for _, shardData := range header.ShardInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think here we should do this only if equivalent messages flag is activated
process/block/metablock.go
Outdated
// if there is an entry for the missing proof, it means that proofsPool did not have it while scanning shardData | ||
// thus header epoch was not available at that time | ||
incompleteProof, hasMissingProof := mp.hdrsForCurrBlock.missingProofs[string(shardHeaderHash)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think here also
} | ||
|
||
if mp.hdrsForCurrBlock.missingHdrs == 0 { | ||
shouldRequestMissingFinalityAttestingShardHeaders := notarizedShardHdrsBasedOnProofs != len(metaBlock.ShardInfo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check this only if equivalent flag enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed, here notarizedShardHdrsBasedOnProofs would be 0, thus the second condition will always be true
process/block/shardblock.go
Outdated
// check proofs for shard data | ||
for _, metaBlockHash := range header.GetMetaBlockHashes() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check if proofs activated?
} | ||
|
||
if sp.hdrsForCurrBlock.missingHdrs == 0 { | ||
shouldRequestMissingFinalityAttestingMetaHeaders := notarizedMetaHdrsBasedOnProofs != len(metaBlockHashes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add this only if flag activated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be ok too
Reasoning behind the pull request
Proposed changes
Testing procedure
Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
feat
branch created?feat
branch merging, do all satellite projects have a proper tag insidego.mod
?