Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Commit

Permalink
[RPC] Rpc batching id fix (#3429)
Browse files Browse the repository at this point in the history
* New retry logic

* New retry logic

* Removed default

* Changed default for exception types

* Added a backoff strategy type

* Removed unused code

* Removed retry from ProvenBlockHeaderRepository

* Removed unused using

* Removed unused using

* Removed unused using

* Formatting fix

* Changes for cancellation token in NetworkPeer

* Fix for batch response id and content type

* Reverted network peer changes

* Reverted network peer connection changes

* Reverted network peer connection changes

* Reverted network peer connection changes

* Fixed rpc middleware to match requests-response ids

* Removed unused i
  • Loading branch information
fenix2222 authored and dangershony committed Mar 25, 2019
1 parent 2ebb905 commit 946287b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/Stratis.Bitcoin.Features.RPC/RPCClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public void CancelBatch()

(RPCRequest request, TaskCompletionSource<RPCResponse> task) req;
while (batches.TryDequeue(out req))
req.Item2.TrySetCanceled();
req.task.TrySetCanceled();
}

/// <summary>Send all commands in one batch.</summary>
Expand Down Expand Up @@ -493,17 +493,14 @@ private async Task SendBatchAsyncCoreAsync(List<(RPCRequest request, TaskComplet
writer.Write("[");

bool first = true;
var i = 1;
foreach ((RPCRequest request, TaskCompletionSource<RPCResponse> task) item in requests)
{
if (!first)
writer.Write(",");
else
first = false;

item.Item1.Id = i;
item.Item1.WriteJSON(writer);
i++;
item.request.WriteJSON(writer);
}

writer.Write("]");
Expand Down
6 changes: 4 additions & 2 deletions src/Stratis.Bitcoin.Features.RPC/RPCMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ private async Task InvokeAsyncBatchAsync(HttpContext httpContext, JArray request

var response = (responseMemoryStream.Length == 0) ? CreateError(RPCErrorCode.RPC_METHOD_NOT_FOUND, "Method not found") : await JObject.LoadAsync(new JsonTextReader(new StreamReader(responseMemoryStream)));

if (response.ContainsKey("id"))
response["id"] = i;
if (requestObj.ContainsKey("id"))
response["id"] = requestObj["id"];
else
response.Remove("id");

responses.Add(response);
i++;
Expand Down
3 changes: 1 addition & 2 deletions src/Stratis.Bitcoin.Features.RPC/RPCRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ public RPCRequest(string method, object[] parameters)
public RPCRequest()
{
this.JsonRpc = "1.0";
this.Id = 1;
}
public string JsonRpc
{
get;
set;
}
public int Id
public string Id
{
get;
set;
Expand Down

0 comments on commit 946287b

Please sign in to comment.