From 1ba8b22cff4c25d8b4a18650a602901fac75789a Mon Sep 17 00:00:00 2001 From: MariusC Date: Thu, 7 Nov 2024 15:44:19 +0200 Subject: [PATCH] FIX: Delete getBlockFinalityFunc and set variable to 0 --- process/track/blockProcessor.go | 24 +++++++------------ process/track/export_test.go | 8 +++---- process/track/sovereignChainBlockProcessor.go | 10 +------- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/process/track/blockProcessor.go b/process/track/blockProcessor.go index 25e66a54b5b..b602b502ae9 100644 --- a/process/track/blockProcessor.go +++ b/process/track/blockProcessor.go @@ -35,7 +35,6 @@ type blockProcessor struct { highestRoundInReceivedHeaders uint64, shardID uint32, ) - getBlockFinalityFunc func(shardID uint32) uint64 } // NewBlockProcessor creates a block processor object which implements blockProcessorHandler interface @@ -65,7 +64,6 @@ func NewBlockProcessor(arguments ArgBlockProcessor) (*blockProcessor, error) { bp.doJobOnReceivedCrossNotarizedHeaderFunc = bp.doJobOnReceivedCrossNotarizedHeader bp.requestHeaderWithShardAndNonceFunc = bp.requestHeaderWithShardAndNonce bp.requestHeadersIfNothingNewIsReceivedFunc = bp.requestHeadersIfNothingNewIsReceived - bp.getBlockFinalityFunc = bp.getBlockFinality return &bp, nil } @@ -182,7 +180,7 @@ func (bp *blockProcessor) doJobOnReceivedMetachainHeader() { finalMetachainHeaders := make([]data.HeaderHandler, 0) finalMetachainHeadersHashes := make([][]byte, 0) - err = bp.checkHeaderFinality(header, sortedHeaders, 0, core.MetachainShardId) + err = bp.checkHeaderFinality(header, sortedHeaders, 0) if err == nil { finalMetachainHeaders = append(finalMetachainHeaders, header) finalMetachainHeadersHashes = append(finalMetachainHeadersHashes, headerHash) @@ -261,7 +259,7 @@ func (bp *blockProcessor) ComputeLongestChain(shardID uint32, header data.Header longestChainHeadersIndexes := make([]int, 0) headersIndexes := make([]int, 0) - bp.getNextHeader(&longestChainHeadersIndexes, headersIndexes, header, sortedHeaders, 0, shardID) + bp.getNextHeader(&longestChainHeadersIndexes, headersIndexes, header, sortedHeaders, 0) for _, index := range longestChainHeadersIndexes { headers = append(headers, sortedHeaders[index]) @@ -277,7 +275,6 @@ func (bp *blockProcessor) getNextHeader( prevHeader data.HeaderHandler, sortedHeaders []data.HeaderHandler, index int, - shardID uint32, ) { defer func() { if len(headersIndexes) > len(*longestChainHeadersIndexes) { @@ -300,13 +297,13 @@ func (bp *blockProcessor) getNextHeader( continue } - err = bp.checkHeaderFinality(currHeader, sortedHeaders, i+1, shardID) + err = bp.checkHeaderFinality(currHeader, sortedHeaders, i+1) if err != nil { continue } headersIndexes = append(headersIndexes, i) - bp.getNextHeader(longestChainHeadersIndexes, headersIndexes, currHeader, sortedHeaders, i+1, shardID) + bp.getNextHeader(longestChainHeadersIndexes, headersIndexes, currHeader, sortedHeaders, i+1) headersIndexes = headersIndexes[:len(headersIndexes)-1] } } @@ -315,7 +312,6 @@ func (bp *blockProcessor) checkHeaderFinality( header data.HeaderHandler, sortedHeaders []data.HeaderHandler, index int, - shardID uint32, ) error { if check.IfNil(header) { @@ -327,7 +323,7 @@ func (bp *blockProcessor) checkHeaderFinality( for i := index; i < len(sortedHeaders); i++ { currHeader := sortedHeaders[i] - if numFinalityAttestingHeaders >= bp.getBlockFinalityFunc(shardID) || currHeader.GetNonce() > prevHeader.GetNonce()+1 { + if numFinalityAttestingHeaders >= bp.blockFinality || currHeader.GetNonce() > prevHeader.GetNonce()+1 { break } @@ -340,7 +336,7 @@ func (bp *blockProcessor) checkHeaderFinality( numFinalityAttestingHeaders += 1 } - if numFinalityAttestingHeaders < bp.getBlockFinalityFunc(shardID) { + if numFinalityAttestingHeaders < bp.blockFinality { return process.ErrHeaderNotFinal } @@ -379,7 +375,7 @@ func (bp *blockProcessor) requestHeadersIfNeeded( highestNonceInLongestChain = longestChainHeaders[numLongestChainHeaders-1].GetNonce() } - shouldRequestHeaders = highestNonceReceived > highestNonceInLongestChain+bp.getBlockFinalityFunc(shardID) && numLongestChainHeaders == 0 + shouldRequestHeaders = highestNonceReceived > highestNonceInLongestChain+bp.blockFinality && numLongestChainHeaders == 0 if !shouldRequestHeaders { return } @@ -462,7 +458,7 @@ func (bp *blockProcessor) baseRequestHeadersIfNothingNewIsReceived( } func (bp *blockProcessor) requestHeaders(shardID uint32, fromNonce uint64) { - toNonce := fromNonce + bp.getBlockFinalityFunc(shardID) + toNonce := fromNonce + bp.blockFinality for nonce := fromNonce; nonce <= toNonce; nonce++ { log.Trace("requestHeaders.RequestHeaderByNonce", "shard", shardID, @@ -481,10 +477,6 @@ func (bp *blockProcessor) requestHeaderWithShardAndNonce(shardID uint32, nonce u } } -func (bp *blockProcessor) getBlockFinality(_ uint32) uint64 { - return bp.blockFinality -} - // IsInterfaceNil returns true if there is no value under the interface func (bp *blockProcessor) IsInterfaceNil() bool { return bp == nil diff --git a/process/track/export_test.go b/process/track/export_test.go index cb6dca19af1..6a00eb115bb 100644 --- a/process/track/export_test.go +++ b/process/track/export_test.go @@ -237,11 +237,11 @@ func (bp *blockProcessor) ComputeSelfNotarizedHeaders(headers []data.HeaderHandl } func (bp *blockProcessor) GetNextHeader(longestChainHeadersIndexes *[]int, headersIndexes []int, prevHeader data.HeaderHandler, sortedHeaders []data.HeaderHandler, index int) { - bp.getNextHeader(longestChainHeadersIndexes, headersIndexes, prevHeader, sortedHeaders, index, 0) + bp.getNextHeader(longestChainHeadersIndexes, headersIndexes, prevHeader, sortedHeaders, index) } func (bp *blockProcessor) CheckHeaderFinality(header data.HeaderHandler, sortedHeaders []data.HeaderHandler, index int) error { - return bp.checkHeaderFinality(header, sortedHeaders, index, 0) + return bp.checkHeaderFinality(header, sortedHeaders, index) } func (bp *blockProcessor) RequestHeadersIfNeeded(lastNotarizedHeader data.HeaderHandler, sortedHeaders []data.HeaderHandler, longestChainHeaders []data.HeaderHandler, shardID uint32) { @@ -274,8 +274,8 @@ func (scbp *sovereignChainBlockProcessor) ShouldProcessReceivedHeader(headerHand return scbp.shouldProcessReceivedHeaderFunc(headerHandler) } -func (scbp *sovereignChainBlockProcessor) GetBlockFinality(shardID uint32) uint64 { - return scbp.getBlockFinality(shardID) +func (scbp *sovereignChainBlockProcessor) GetBlockFinality() uint64 { + return scbp.blockFinality } // miniBlockTrack diff --git a/process/track/sovereignChainBlockProcessor.go b/process/track/sovereignChainBlockProcessor.go index c03bba38b97..246e8aa342c 100644 --- a/process/track/sovereignChainBlockProcessor.go +++ b/process/track/sovereignChainBlockProcessor.go @@ -34,7 +34,7 @@ func NewSovereignChainBlockProcessor(blockProcessor *blockProcessor) (*sovereign scbp.doJobOnReceivedCrossNotarizedHeaderFunc = scbp.doJobOnReceivedCrossNotarizedHeader scbp.requestHeaderWithShardAndNonceFunc = scbp.requestHeaderWithShardAndNonce scbp.requestHeadersIfNothingNewIsReceivedFunc = scbp.requestHeadersIfNothingNewIsReceived - scbp.getBlockFinalityFunc = scbp.getBlockFinality + scbp.blockFinality = 0 extendedShardHeaderRequester, ok := scbp.requestHandler.(extendedShardHeaderRequestHandler) if !ok { @@ -118,11 +118,3 @@ func (scbp *sovereignChainBlockProcessor) requestHeadersIfNothingNewIsReceived( scbp.baseRequestHeadersIfNothingNewIsReceived(lastNotarizedHeaderNonce, latestValidHeader, highestRoundInReceivedHeaders, shardID) } - -func (scbp *sovereignChainBlockProcessor) getBlockFinality(shardID uint32) uint64 { - if shardID == core.MainChainShardId { - return 0 - } - - return scbp.blockFinality -}