@@ -2,6 +2,7 @@ package block
22
33import (
44 "fmt"
5+ "sync"
56
67 "github.com/multiversx/mx-chain-core-go/core/check"
78 "github.com/multiversx/mx-chain-core-go/data"
@@ -15,6 +16,9 @@ import (
1516type executionResultsVerifier struct {
1617 blockChain data.ChainHandler
1718 executionManager process.ExecutionManager
19+
20+ lastVerifiedHeaderWithError data.HeaderHandler
21+ mutLastVerifiedHeaderWithError sync.RWMutex
1822}
1923
2024// NewExecutionResultsVerifier creates a new instance of executionResultsVerifier
@@ -63,11 +67,13 @@ func (erc *executionResultsVerifier) verifyExecutionResults(
6367 }
6468
6569 if len (pendingExecutionResults ) < len (executionResults ) {
66- log .Debug ("verifyExecutionResults" ,
67- "pendingExecutionResults" , len (pendingExecutionResults ),
68- "header executionResults" , len (executionResults ),
69- "header nonce" , header .GetNonce (),
70- )
70+ if erc .setLastVerifiedHeaderWithErrorIfNeeded (header ) {
71+ log .Debug ("verifyExecutionResults" ,
72+ "pendingExecutionResults" , len (pendingExecutionResults ),
73+ "header executionResults" , len (executionResults ),
74+ "header nonce" , header .GetNonce (),
75+ )
76+ }
7177 return process .ErrExecutionResultsNumberMismatch
7278 }
7379
@@ -95,6 +101,23 @@ func (erc *executionResultsVerifier) verifyExecutionResults(
95101 return nil
96102}
97103
104+ func (erc * executionResultsVerifier ) setLastVerifiedHeaderWithErrorIfNeeded (header data.HeaderHandler ) bool {
105+ erc .mutLastVerifiedHeaderWithError .RLock ()
106+ lastVerifiedHeader := erc .lastVerifiedHeaderWithError
107+ erc .mutLastVerifiedHeaderWithError .RUnlock ()
108+
109+ if ! check .IfNil (lastVerifiedHeader ) &&
110+ lastVerifiedHeader .GetNonce () == header .GetNonce () &&
111+ lastVerifiedHeader .GetRound () == header .GetRound () {
112+ return false
113+ }
114+
115+ erc .mutLastVerifiedHeaderWithError .Lock ()
116+ erc .lastVerifiedHeaderWithError = header
117+ erc .mutLastVerifiedHeaderWithError .Unlock ()
118+ return true
119+ }
120+
98121func (erc * executionResultsVerifier ) verifyLastExecutionResultInfoMatchesLastExecutionResult (
99122 header data.HeaderHandler ,
100123) error {
0 commit comments