protected override async Task Dispatch(PeerInfo peerInfo, WitnessBlockSyncBatch request, CancellationToken cancellationToken) { ISyncPeer peer = peerInfo.SyncPeer; if (peer.TryGetSatelliteProtocol <IWitnessPeer>("wit", out var witnessProtocolHandler) && witnessProtocolHandler != null) { var getNodeDataTask = witnessProtocolHandler.GetBlockWitnessHashes(request.BlockHash, cancellationToken); await getNodeDataTask.ContinueWith( (t, state) => { if (t.IsFaulted) { if (Logger.IsTrace) { Logger.Error("DEBUG/ERROR Error after dispatching the state sync request", t.Exception); } } WitnessBlockSyncBatch batchLocal = (WitnessBlockSyncBatch)state !; if (t.IsCompletedSuccessfully) { batchLocal.Response = t.Result; } }, request, cancellationToken); } else { if (Logger.IsError) { Logger.Error($"Couldn't get witness protocol from {peer.Node}."); } } }
protected override async Task Dispatch(PeerInfo peerInfo, SnapSyncBatch batch, CancellationToken cancellationToken) { ISyncPeer peer = peerInfo.SyncPeer; //TODO: replace with a constant "snap" if (peer.TryGetSatelliteProtocol <ISnapSyncPeer>("snap", out var handler)) { if (batch.AccountRangeRequest is not null) { Task <AccountsAndProofs> task = handler.GetAccountRange(batch.AccountRangeRequest, cancellationToken); await task.ContinueWith( (t, state) => { if (t.IsFaulted) { if (Logger.IsTrace) { Logger.Error("DEBUG/ERROR Error after dispatching the snap sync request", t.Exception); } } SnapSyncBatch batchLocal = (SnapSyncBatch)state !; if (t.IsCompletedSuccessfully) { batchLocal.AccountRangeResponse = t.Result; } }, batch); } else if (batch.StorageRangeRequest is not null) { Task <SlotsAndProofs> task = handler.GetStorageRange(batch.StorageRangeRequest, cancellationToken); await task.ContinueWith( (t, state) => { if (t.IsFaulted) { if (Logger.IsTrace) { Logger.Error("DEBUG/ERROR Error after dispatching the snap sync request", t.Exception); } } SnapSyncBatch batchLocal = (SnapSyncBatch)state !; if (t.IsCompletedSuccessfully) { batchLocal.StorageRangeResponse = t.Result; } }, batch); } else if (batch.CodesRequest is not null) { Task <byte[][]> task = handler.GetByteCodes(batch.CodesRequest, cancellationToken); await task.ContinueWith( (t, state) => { if (t.IsFaulted) { if (Logger.IsTrace) { Logger.Error("DEBUG/ERROR Error after dispatching the snap sync request", t.Exception); } } SnapSyncBatch batchLocal = (SnapSyncBatch)state !; if (t.IsCompletedSuccessfully) { batchLocal.CodesResponse = t.Result; } }, batch); } else if (batch.AccountsToRefreshRequest is not null) { Task <byte[][]> task = handler.GetTrieNodes(batch.AccountsToRefreshRequest, cancellationToken); await task.ContinueWith( (t, state) => { if (t.IsFaulted) { if (Logger.IsTrace) { Logger.Error("DEBUG/ERROR Error after dispatching the snap sync request", t.Exception); } } SnapSyncBatch batchLocal = (SnapSyncBatch)state !; if (t.IsCompletedSuccessfully) { batchLocal.AccountsToRefreshResponse = t.Result; } }, batch); } } await Task.CompletedTask; }