Skip to content

Commit

Permalink
add consensus header interceptor check for v1
Browse files Browse the repository at this point in the history
  • Loading branch information
AdoAdoAdo committed Dec 16, 2024
1 parent ca5f851 commit 9724125
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 19 additions & 2 deletions consensus/spos/bls/v1/subroundBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,14 @@ func (sr *subroundBlock) receivedBlockBodyAndHeader(ctx context.Context, cnsDta
return false
}

header := sr.BlockProcessor().DecodeBlockHeader(cnsDta.Header)
if headerHasProof(header) {
return false
}

sr.SetData(cnsDta.BlockHeaderHash)
sr.SetBody(sr.BlockProcessor().DecodeBlockBody(cnsDta.Body))
sr.SetHeader(sr.BlockProcessor().DecodeBlockHeader(cnsDta.Header))
sr.SetHeader(header)

isInvalidData := check.IfNil(sr.GetBody()) || sr.isInvalidHeaderOrData()
if isInvalidData {
Expand Down Expand Up @@ -514,8 +519,13 @@ func (sr *subroundBlock) receivedBlockHeader(ctx context.Context, cnsDta *consen
return false
}

header := sr.BlockProcessor().DecodeBlockHeader(cnsDta.Header)
if headerHasProof(header) {
return false
}

sr.SetData(cnsDta.BlockHeaderHash)
sr.SetHeader(sr.BlockProcessor().DecodeBlockHeader(cnsDta.Header))
sr.SetHeader(header)

if sr.isInvalidHeaderOrData() {
return false
Expand All @@ -535,6 +545,13 @@ func (sr *subroundBlock) receivedBlockHeader(ctx context.Context, cnsDta *consen
return blockProcessedWithSuccess
}

func headerHasProof(headerHandler data.HeaderHandler) bool {
if check.IfNil(headerHandler) {
return true
}
return headerHandler.GetPreviousProof() != nil
}

func (sr *subroundBlock) processReceivedBlock(ctx context.Context, cnsDta *consensus.Message) bool {
if check.IfNil(sr.GetBody()) {
return false
Expand Down
4 changes: 2 additions & 2 deletions consensus/spos/bls/v2/subroundBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/data"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/consensus"
"github.com/multiversx/mx-chain-go/consensus/spos"
Expand Down Expand Up @@ -110,7 +111,6 @@ func (sr *subroundBlock) doBlockJob(ctx context.Context) bool {
return false
}

// todo: check again the block proof verification & leader signature verification
// block proof verification should be done over the header that contains the leader signature
leaderSignature, err := sr.signBlockHeader(header)
if err != nil {
Expand Down Expand Up @@ -177,7 +177,7 @@ func printLogMessage(ctx context.Context, baseMessage string, err error) {
log.Debug(baseMessage, "error", err.Error())
}

func (sr *subroundBlock) sendBlock(header data.HeaderHandler, body data.BodyHandler, leader string) bool {
func (sr *subroundBlock) sendBlock(header data.HeaderHandler, body data.BodyHandler, _ string) bool {
marshalledBody, err := sr.Marshalizer().Marshal(body)
if err != nil {
log.Debug("sendBlock.Marshal: body", "error", err.Error())
Expand Down

0 comments on commit 9724125

Please sign in to comment.