public async Task ResponseParentChainBlockData_WithoutBlock_Test() { var chainId = ChainHelper.GetChainId(1); var height = 5; var res = await _chainResponseService.ResponseParentChainBlockDataAsync(height, chainId); Assert.Null(res); }
public override async Task RequestIndexingFromParentChain(CrossChainRequest crossChainRequest, IServerStreamWriter <ParentChainBlockData> responseStream, ServerCallContext context) { Logger.LogTrace( $"Parent Chain Server received IndexedInfo message from chain {ChainHelper.ConvertChainIdToBase58(crossChainRequest.FromChainId)}."); var requestedHeight = crossChainRequest.NextHeight; var remoteChainId = crossChainRequest.FromChainId; while (requestedHeight - crossChainRequest.NextHeight < CrossChainCommunicationConstants.MaximalIndexingCount) { var parentChainBlockData = await _crossChainResponseService.ResponseParentChainBlockDataAsync(requestedHeight, remoteChainId); if (parentChainBlockData == null) { break; } if (context.Status.StatusCode != Status.DefaultSuccess.StatusCode) { Logger.LogTrace( $"Disconnected with side chain {ChainHelper.ConvertChainIdToBase58(crossChainRequest.FromChainId)} node."); return; } Logger.LogTrace($"Response parent chain data {parentChainBlockData.Height}"); await responseStream.WriteAsync(parentChainBlockData); requestedHeight++; } }
public override async Task RequestIndexingFromParentChain(CrossChainRequest crossChainRequest, IServerStreamWriter <ParentChainBlockData> responseStream, ServerCallContext context) { Logger.LogDebug( $"Parent Chain Server received IndexedInfo message from chain {ChainHelper.ConvertChainIdToBase58(crossChainRequest.ChainId)}."); var requestedHeight = crossChainRequest.NextHeight; var remoteChainId = crossChainRequest.ChainId; while (requestedHeight - crossChainRequest.NextHeight < GrpcCrossChainConstants.MaximalIndexingCount) { var parentChainBlockData = await _crossChainResponseService.ResponseParentChainBlockDataAsync(requestedHeight, remoteChainId); if (parentChainBlockData == null) { break; } if (context.Status.StatusCode != Status.DefaultSuccess.StatusCode) { Logger.LogTrace( $"Disconnected with side chain {ChainHelper.ConvertChainIdToBase58(crossChainRequest.ChainId)} node."); return; } try { await responseStream.WriteAsync(parentChainBlockData); requestedHeight++; } catch (InvalidOperationException) { Logger.LogWarning("Failed to write into server side stream."); return; } } }