Skip to content

Commit

Permalink
fix checkProofsForShardData and shard transition trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
AdoAdoAdo committed Jan 15, 2025
1 parent 6a11dbe commit 0abb837
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 12 additions & 2 deletions process/block/metablock.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,16 @@ func (mp *metaProcessor) checkProofsForShardData(header *block.MetaBlock) error
// TODO: consider the validation of the proof:
// compare the one from proofsPool with what shardData.CurrentSignature and shardData.CurrentPubKeysBitmap hold
// if they are different, verify the proof received on header

shardHeader, ok := mp.hdrsForCurrBlock.hdrHashAndInfo[string(shardData.HeaderHash)]
if !ok {
return fmt.Errorf("%w for header hash %s", process.ErrMissingHeader, hex.EncodeToString(shardData.HeaderHash))
}

if !mp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, shardHeader.hdr.GetEpoch()) {
continue
}

if !mp.proofsPool.HasProof(shardData.ShardID, shardData.HeaderHash) {
return fmt.Errorf("%w for header hash %s", process.ErrMissingHeaderProof, hex.EncodeToString(shardData.HeaderHash))
}
Expand Down Expand Up @@ -2186,11 +2196,11 @@ func (mp *metaProcessor) createShardInfo() ([]data.ShardDataHandler, error) {
continue
}

isBlockAfterEquivalentMessagesFlag := check.IfNil(headerInfo.hdr) &&
isBlockAfterEquivalentMessagesFlag := !check.IfNil(headerInfo.hdr) &&
mp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, headerInfo.hdr.GetEpoch())
hasMissingShardHdrProof := isBlockAfterEquivalentMessagesFlag && !mp.proofsPool.HasProof(headerInfo.hdr.GetShardID(), []byte(hdrHash))
if hasMissingShardHdrProof {
return nil, fmt.Errorf("%w for shard header with hash %s", process.ErrMissingHeaderProof, hdrHash)
return nil, fmt.Errorf("%w for shard header with hash %s", process.ErrMissingHeaderProof, hex.EncodeToString([]byte(hdrHash)))
}

shardHdr, ok := headerInfo.hdr.(data.ShardHeaderHandler)
Expand Down
10 changes: 10 additions & 0 deletions process/block/shardblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ func (sp *shardProcessor) ProcessBlock(
if sp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, header.GetEpoch()) {
// check proofs for cross notarized metablocks
for _, metaBlockHash := range header.GetMetaBlockHashes() {
hInfo, ok := sp.hdrsForCurrBlock.hdrHashAndInfo[string(metaBlockHash)]
if !ok {
return fmt.Errorf("%w for header hash %s", process.ErrMissingHeader, hex.EncodeToString(metaBlockHash))
}

if !sp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, hInfo.hdr.GetEpoch()) {
continue
}

if !sp.proofsPool.HasProof(core.MetachainShardId, metaBlockHash) {
return fmt.Errorf("%w for header hash %s", process.ErrMissingHeaderProof, hex.EncodeToString(metaBlockHash))
}
Expand Down Expand Up @@ -1441,6 +1450,7 @@ func (sp *shardProcessor) CreateNewHeader(round uint64, nonce uint64) (data.Head
}

sp.roundNotifier.CheckRound(header)
sp.epochNotifier.CheckEpoch(header)

err = shardHeader.SetNonce(nonce)
if err != nil {
Expand Down

0 comments on commit 0abb837

Please sign in to comment.