From 946287be0202822a10d5c033c9a97b6623ef1d24 Mon Sep 17 00:00:00 2001 From: Igor Goldobin Date: Tue, 26 Mar 2019 02:44:37 +1000 Subject: [PATCH] [RPC] Rpc batching id fix (#3429) * 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 --- src/Stratis.Bitcoin.Features.RPC/RPCClient.cs | 7 ++----- src/Stratis.Bitcoin.Features.RPC/RPCMiddleware.cs | 6 ++++-- src/Stratis.Bitcoin.Features.RPC/RPCRequest.cs | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Stratis.Bitcoin.Features.RPC/RPCClient.cs b/src/Stratis.Bitcoin.Features.RPC/RPCClient.cs index 6f43f631f60..ae61b8901e9 100644 --- a/src/Stratis.Bitcoin.Features.RPC/RPCClient.cs +++ b/src/Stratis.Bitcoin.Features.RPC/RPCClient.cs @@ -445,7 +445,7 @@ public void CancelBatch() (RPCRequest request, TaskCompletionSource task) req; while (batches.TryDequeue(out req)) - req.Item2.TrySetCanceled(); + req.task.TrySetCanceled(); } /// Send all commands in one batch. @@ -493,7 +493,6 @@ private async Task SendBatchAsyncCoreAsync(List<(RPCRequest request, TaskComplet writer.Write("["); bool first = true; - var i = 1; foreach ((RPCRequest request, TaskCompletionSource task) item in requests) { if (!first) @@ -501,9 +500,7 @@ private async Task SendBatchAsyncCoreAsync(List<(RPCRequest request, TaskComplet else first = false; - item.Item1.Id = i; - item.Item1.WriteJSON(writer); - i++; + item.request.WriteJSON(writer); } writer.Write("]"); diff --git a/src/Stratis.Bitcoin.Features.RPC/RPCMiddleware.cs b/src/Stratis.Bitcoin.Features.RPC/RPCMiddleware.cs index 56239b60410..3355eb7bacb 100644 --- a/src/Stratis.Bitcoin.Features.RPC/RPCMiddleware.cs +++ b/src/Stratis.Bitcoin.Features.RPC/RPCMiddleware.cs @@ -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++; diff --git a/src/Stratis.Bitcoin.Features.RPC/RPCRequest.cs b/src/Stratis.Bitcoin.Features.RPC/RPCRequest.cs index 4a5da974adf..111642319d6 100644 --- a/src/Stratis.Bitcoin.Features.RPC/RPCRequest.cs +++ b/src/Stratis.Bitcoin.Features.RPC/RPCRequest.cs @@ -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;