Skip to content

Commit

Permalink
FIX: Delete getBlockFinalityFunc and set variable to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmihaic committed Nov 7, 2024
1 parent a8ac19e commit 1ba8b22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 29 deletions.
24 changes: 8 additions & 16 deletions process/track/blockProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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])
Expand All @@ -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) {
Expand All @@ -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]
}
}
Expand All @@ -315,7 +312,6 @@ func (bp *blockProcessor) checkHeaderFinality(
header data.HeaderHandler,
sortedHeaders []data.HeaderHandler,
index int,
shardID uint32,
) error {

if check.IfNil(header) {
Expand All @@ -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
}

Expand All @@ -340,7 +336,7 @@ func (bp *blockProcessor) checkHeaderFinality(
numFinalityAttestingHeaders += 1
}

if numFinalityAttestingHeaders < bp.getBlockFinalityFunc(shardID) {
if numFinalityAttestingHeaders < bp.blockFinality {
return process.ErrHeaderNotFinal
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions process/track/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions process/track/sovereignChainBlockProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 1ba8b22

Please sign in to comment.