11package transactionAPI
22
33import (
4+ "bytes"
45 "encoding/hex"
56 "errors"
67 "fmt"
@@ -748,20 +749,53 @@ func (atp *apiTransactionProcessor) computeTimestampForRoundAsMs(round uint64) i
748749 return timestamp .UnixMilli ()
749750}
750751
751- func (atp * apiTransactionProcessor ) checkExecutionResult (miniblockMetadata * dblookupext.MiniblockMetadata ) error {
752+ func (atp * apiTransactionProcessor ) checkExecutionResultAndTx (miniblockMetadata * dblookupext.MiniblockMetadata ) ( bool , error ) {
752753 isSupernovaEnabled := atp .enableRoundsHandler .IsFlagEnabledInRound (common .SupernovaRoundFlag , miniblockMetadata .Round )
753754 if ! isSupernovaEnabled {
754- return nil
755+ return true , nil
755756 }
756757
757758 headerHash := miniblockMetadata .GetHeaderHash ()
758759 executionResultsStorer , errG := atp .storageService .GetStorer (dataRetriever .ExecutionResultsUnit )
759760 if errG != nil {
760- return errG
761+ return false , errG
762+ }
763+
764+ executionResultsBytes , err := executionResultsStorer .GetFromEpoch (headerHash , miniblockMetadata .GetEpoch ())
765+ if err != nil {
766+ return false , err
767+ }
768+
769+ if atp .shardCoordinator .SelfId () == core .MetachainShardId {
770+ // we cannot have unexecutable txs on metachain
771+ return true , nil
772+ }
773+ mbHeaders , err := atp .getMbHeadersFromExecutionResultBytes (executionResultsBytes )
774+ if err != nil {
775+ return false , err
761776 }
762777
763- _ , err := executionResultsStorer .GetFromEpoch (headerHash , miniblockMetadata .GetEpoch ())
764- return err
778+ // check if the transaction miniblock metadata has a mb header on execution result
779+ // if yes - the transaction was executed
780+ // if no - the transaction was proposed but not executed
781+ currentTxIsExecuted := false
782+ for _ , mbHeader := range mbHeaders {
783+ if bytes .Equal (mbHeader .Hash , miniblockMetadata .MiniblockHash ) {
784+ currentTxIsExecuted = true
785+ break
786+ }
787+ }
788+ return currentTxIsExecuted , nil
789+ }
790+
791+ func (atp * apiTransactionProcessor ) getMbHeadersFromExecutionResultBytes (executionResultBytes []byte ) ([]block.MiniBlockHeader , error ) {
792+ executResult := & block.ExecutionResult {}
793+ err := atp .marshalizer .Unmarshal (executResult , executionResultBytes )
794+ if err != nil {
795+ return nil , err
796+ }
797+
798+ return executResult .GetMiniBlockHeaders (), nil
765799}
766800
767801func (atp * apiTransactionProcessor ) lookupHistoricalTransaction (hash []byte , withResults bool ) (* transaction.ApiTransactionResult , error ) {
@@ -770,7 +804,7 @@ func (atp *apiTransactionProcessor) lookupHistoricalTransaction(hash []byte, wit
770804 return nil , fmt .Errorf ("%s: %w" , ErrTransactionNotFound .Error (), err )
771805 }
772806
773- err = atp .checkExecutionResult (miniblockMetadata )
807+ isExecuted , err : = atp .checkExecutionResultAndTx (miniblockMetadata )
774808 if err != nil {
775809 return nil , fmt .Errorf ("%s: %w" , ErrTransactionNotFound .Error (), err )
776810 }
@@ -802,6 +836,11 @@ func (atp *apiTransactionProcessor) lookupHistoricalTransaction(hash []byte, wit
802836 return nil , fmt .Errorf ("%s: %w" , ErrNilStatusComputer .Error (), err )
803837 }
804838
839+ if ! isExecuted {
840+ tx .Status = transaction .TxStatusNotExecutable
841+ return tx , nil
842+ }
843+
805844 if ok , _ := statusComputer .SetStatusIfIsRewardReverted (
806845 tx ,
807846 block .Type (miniblockMetadata .Type ),
0 commit comments