From df47f28dd12c4848d56f4254d267964d054ef5c0 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Mon, 23 Dec 2024 17:54:51 +0200 Subject: [PATCH] fixes & debug logs --- common/common.go | 5 +++++ .../sync/basicSync/basicSync_test.go | 3 +++ process/block/interceptedBlocks/common.go | 20 ++++++++----------- .../interceptedMetaBlockHeader.go | 2 ++ process/errors.go | 3 +++ .../processor/hdrInterceptorProcessor.go | 3 ++- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/common/common.go b/common/common.go index d5624d7777..c3364fa608 100644 --- a/common/common.go +++ b/common/common.go @@ -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 +} diff --git a/integrationTests/sync/basicSync/basicSync_test.go b/integrationTests/sync/basicSync/basicSync_test.go index 19dfc7afe5..727f26c57d 100644 --- a/integrationTests/sync/basicSync/basicSync_test.go +++ b/integrationTests/sync/basicSync/basicSync_test.go @@ -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) @@ -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 diff --git a/process/block/interceptedBlocks/common.go b/process/block/interceptedBlocks/common.go index c1c1fdc1c8..b70e48e942 100644 --- a/process/block/interceptedBlocks/common.go +++ b/process/block/interceptedBlocks/common.go @@ -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 } diff --git a/process/block/interceptedBlocks/interceptedMetaBlockHeader.go b/process/block/interceptedBlocks/interceptedMetaBlockHeader.go index c3f92781e7..d57732f56f 100644 --- a/process/block/interceptedBlocks/interceptedMetaBlockHeader.go +++ b/process/block/interceptedBlocks/interceptedMetaBlockHeader.go @@ -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 diff --git a/process/errors.go b/process/errors.go index 395ebf1762..52d5981ab0 100644 --- a/process/errors.go +++ b/process/errors.go @@ -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") diff --git a/process/interceptors/processor/hdrInterceptorProcessor.go b/process/interceptors/processor/hdrInterceptorProcessor.go index e60489c2ae..c49f2bb970 100644 --- a/process/interceptors/processor/hdrInterceptorProcessor.go +++ b/process/interceptors/processor/hdrInterceptorProcessor.go @@ -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" @@ -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()))