Skip to content

Commit

Permalink
fixes & debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
AdoAdoAdo committed Dec 23, 2024
1 parent a8fb6f1 commit df47f28
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
5 changes: 5 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ func IsFlagEnabledAfterEpochsStartBlock(header data.HeaderHandler, enableEpochsH
isEpochStartBlock := IsEpochChangeBlockForFlagActivation(header, enableEpochsHandler, flag)
return isFlagEnabled && !isEpochStartBlock
}

// ShouldBlockHavePrevProof returns true if the block should have a proof
func ShouldBlockHavePrevProof(header data.HeaderHandler, enableEpochsHandler EnableEpochsHandler, flag core.EnableEpochFlag) bool {
return IsFlagEnabledAfterEpochsStartBlock(header, enableEpochsHandler, flag) && header.GetNonce() > 1
}
3 changes: 3 additions & 0 deletions integrationTests/sync/basicSync/basicSync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,14 @@ func TestSyncWorksInShard_EmptyBlocksNoForks_With_EquivalentProofs(t *testing.T)

_ = logger.SetLogLevel("*:DEBUG,process:TRACE,consensus:TRACE")

// 3 shard nodes and 1 metachain node
maxShards := uint32(1)
shardId := uint32(0)
numNodesPerShard := 3

enableEpochs := integrationTests.CreateEnableEpochsConfig()
enableEpochs.EquivalentMessagesEnableEpoch = uint32(0)
enableEpochs.FixedOrderInConsensusEnableEpoch = uint32(0)

nodes := make([]*integrationTests.TestProcessorNode, numNodesPerShard+1)
connectableNodes := make([]integrationTests.Connectable, 0)
Expand All @@ -230,6 +232,7 @@ func TestSyncWorksInShard_EmptyBlocksNoForks_With_EquivalentProofs(t *testing.T)
NodeShardId: core.MetachainShardId,
TxSignPrivKeyShardId: shardId,
WithSync: true,
EpochsConfig: &enableEpochs,
})
idxProposerMeta := numNodesPerShard
nodes[idxProposerMeta] = metachainNode
Expand Down
20 changes: 8 additions & 12 deletions process/block/interceptedBlocks/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,20 @@ func checkHeaderHandler(hdr data.HeaderHandler, enableEpochsHandler common.Enabl
}

func checkProofIntegrity(hdr data.HeaderHandler, enableEpochsHandler common.EnableEpochsHandler) error {
equivalentMessagesEnabled := enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, hdr.GetEpoch())
epochChangeBlockForActivation := common.IsEpochChangeBlockForFlagActivation(hdr, enableEpochsHandler, common.EquivalentMessagesFlag)

prevHeaderNonce := hdr.GetNonce() - 1
prevHeaderProof := hdr.GetPreviousProof()
nilPreviousProof := check.IfNilReflect(prevHeaderProof)
shouldConsiderPrevProof := prevHeaderNonce > 0 && !epochChangeBlockForActivation
missingProof := nilPreviousProof && equivalentMessagesEnabled && shouldConsiderPrevProof
unexpectedProof := !nilPreviousProof && !equivalentMessagesEnabled
hasProof := !nilPreviousProof && !missingProof
shouldHavePrevProof := common.ShouldBlockHavePrevProof(hdr, enableEpochsHandler, common.EquivalentMessagesFlag)
missingPrevProof := nilPreviousProof && shouldHavePrevProof
unexpectedPrevProof := !nilPreviousProof && !shouldHavePrevProof
hasPrevProof := !nilPreviousProof && !missingPrevProof

if missingProof {
return process.ErrMissingHeaderProof
if missingPrevProof {
return process.ErrMissingPrevHeaderProof
}
if unexpectedProof {
if unexpectedPrevProof {
return process.ErrUnexpectedHeaderProof
}
if hasProof && isIncompleteProof(prevHeaderProof) {
if hasPrevProof && isIncompleteProof(prevHeaderProof) {
return process.ErrInvalidHeaderProof
}

Expand Down
2 changes: 2 additions & 0 deletions process/block/interceptedBlocks/interceptedMetaBlockHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (imh *InterceptedMetaHeader) HeaderHandler() data.HeaderHandler {

// CheckValidity checks if the received meta header is valid (not nil fields, valid sig and so on)
func (imh *InterceptedMetaHeader) CheckValidity() error {
log.Debug("CheckValidity for header with", "epoch", imh.hdr.GetEpoch(), "hash", logger.DisplayByteSlice(imh.hash))

err := imh.integrity()
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions process/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,9 @@ var ErrInvalidInterceptedData = errors.New("invalid intercepted data")
// ErrMissingHeaderProof signals that the proof for the header is missing
var ErrMissingHeaderProof = errors.New("missing header proof")

// ErrMissingPrevHeaderProof signals that the proof for the previous header is missing
var ErrMissingPrevHeaderProof = errors.New("missing previous header proof")

// ErrInvalidHeaderProof signals that an invalid equivalent proof has been provided
var ErrInvalidHeaderProof = errors.New("invalid equivalent proof")

Expand Down
3 changes: 2 additions & 1 deletion process/interceptors/processor/hdrInterceptorProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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/dataRetriever"
"github.com/multiversx/mx-chain-go/process"
Expand Down Expand Up @@ -80,7 +81,7 @@ func (hip *HdrInterceptorProcessor) Save(data process.InterceptedData, _ core.Pe

hip.headers.AddHeader(interceptedHdr.Hash(), interceptedHdr.HeaderHandler())

if common.IsFlagEnabledAfterEpochsStartBlock(interceptedHdr.HeaderHandler(), hip.enableEpochsHandler, common.EquivalentMessagesFlag) {
if common.ShouldBlockHavePrevProof(interceptedHdr.HeaderHandler(), hip.enableEpochsHandler, common.EquivalentMessagesFlag) {
err := hip.proofs.AddProof(interceptedHdr.HeaderHandler().GetPreviousProof())
if err != nil {
log.Error("failed to add proof", "error", err, "intercepted header hash", interceptedHdr.Hash(), "header type", reflect.TypeOf(interceptedHdr.HeaderHandler()))
Expand Down

0 comments on commit df47f28

Please sign in to comment.