internal static Task <TResponse> ExecuteSignedRequestWithRetryImplementationAsync <TRequest, TResponse>(this GossipContextStack context, TRequest request, Func <Channel, Func <TRequest, Metadata?, DateTime?, CancellationToken, AsyncUnaryCall <TResponse> > > instantiateRequestMethod, Func <TResponse, ResponseCodeEnum> getResponseCode) where TRequest : IMessage where TResponse : IMessage
        {
            var trackTimeDrift  = context.AdjustForLocalClockDrift && context.Transaction is null;
            var startingInstant = trackTimeDrift ? Epoch.UniqueClockNanos() : 0;

            return(ExecuteNetworkRequestWithRetryAsync(context, request, instantiateRequestMethod, shouldRetryRequest));

            bool shouldRetryRequest(TResponse response)
            {
                var code = getResponseCode(response);

                if (trackTimeDrift && code == ResponseCodeEnum.InvalidTransactionStart)
                {
                    Epoch.AddToClockDrift(Epoch.UniqueClockNanos() - startingInstant);
                }
                return
                    (code == ResponseCodeEnum.Busy ||
                     code == ResponseCodeEnum.InvalidTransactionStart);
            }
        }