@@ -914,6 +914,98 @@ func TestHeadersForBlock_ComputeHeadersForCurrentBlock(t *testing.T) {
914914 })
915915}
916916
917+ func TestHeadersForBlock_RequestMissingFinalityAttestingShardHeaders (t * testing.T ) {
918+ t .Parallel ()
919+
920+ t .Run ("attestation header present but proof missing should request proof" , func (t * testing.T ) {
921+ t .Parallel ()
922+
923+ referencedHeaderHash := []byte ("sh0TestHash1" )
924+ referencedHeader := & block.HeaderV2 {
925+ Header : & block.Header {
926+ ShardID : 0 ,
927+ Round : 100 ,
928+ Nonce : 100 ,
929+ },
930+ }
931+ attestationHeaderHash := []byte ("sh0TestHash2" )
932+ attestationHeader := & block.HeaderV2 {
933+ Header : & block.Header {
934+ ShardID : 0 ,
935+ Round : 101 ,
936+ Nonce : 101 ,
937+ PrevHash : referencedHeaderHash ,
938+ },
939+ }
940+
941+ counter := 0
942+ var requestedShardID uint32
943+ var requestedHash []byte
944+ var mutRequestEquivalentProof sync.Mutex
945+ wg := & sync.WaitGroup {}
946+ wg .Add (1 )
947+
948+ args := createMockArgs ()
949+ args .ShardCoordinator = & testscommon.ShardsCoordinatorMock {
950+ NoShards : 2 ,
951+ }
952+ args .EnableEpochsHandler = & enableEpochsHandlerMock.EnableEpochsHandlerStub {
953+ IsFlagEnabledInEpochCalled : func (flag core.EnableEpochFlag , epoch uint32 ) bool {
954+ return flag == common .AndromedaFlag
955+ },
956+ }
957+ args .RequestHandler = & testscommon.RequestHandlerStub {
958+ RequestEquivalentProofByHashCalled : func (headerShard uint32 , headerHash []byte ) {
959+ mutRequestEquivalentProof .Lock ()
960+ counter ++
961+ requestedShardID = headerShard
962+ requestedHash = append ([]byte (nil ), headerHash ... )
963+ mutRequestEquivalentProof .Unlock ()
964+
965+ wg .Done ()
966+ },
967+ }
968+
969+ poolsHolder , ok := args .DataPool .(* dataRetriever.PoolsHolderMock )
970+ require .True (t , ok )
971+ poolsHolder .SetHeadersPool (createPoolsHolderForHeaderRequests ())
972+ poolsHolder .SetProofsPool (& dataRetriever.ProofsPoolMock {
973+ HasProofCalled : func (shardID uint32 , headerHash []byte ) bool {
974+ return false // no proof available for the attestation header
975+ },
976+ })
977+
978+ args .BlockTracker = & mock.BlockTrackerStub {
979+ GetLastCrossNotarizedHeaderCalled : func (shardID uint32 ) (data.HeaderHandler , []byte , error ) {
980+ return referencedHeader , referencedHeaderHash , nil
981+ },
982+ }
983+
984+ hfb , err := headerForBlock .NewHeadersForBlock (args )
985+ require .NoError (t , err )
986+
987+ hfb .SetShardBlockFinality (1 )
988+ hfb .SetHighestHdrNonceForCurrentBlock (referencedHeader .GetShardID (), referencedHeader .GetNonce ())
989+ hfb .SetLastNotarizedHeaderForShard (
990+ referencedHeader .GetShardID (),
991+ headerForBlock .NewLastNotarizedHeaderInfo (referencedHeader , referencedHeaderHash , false , false ),
992+ )
993+
994+ poolsHolder .Headers ().AddHeader (attestationHeaderHash , attestationHeader )
995+
996+ missingFinalityHeaders := hfb .RequestMissingFinalityAttestingShardHeaders ()
997+ require .Equal (t , uint32 (0 ), missingFinalityHeaders )
998+
999+ wg .Wait ()
1000+
1001+ mutRequestEquivalentProof .Lock ()
1002+ require .Equal (t , 1 , counter )
1003+ require .Equal (t , attestationHeader .GetShardID (), requestedShardID )
1004+ require .Equal (t , attestationHeaderHash , requestedHash )
1005+ mutRequestEquivalentProof .Unlock ()
1006+ })
1007+ }
1008+
9171009type headerData struct {
9181010 header data.HeaderHandler
9191011 headerHash []byte
0 commit comments