From e5760268942a7f6229d047eb3820562fbbe4f85e Mon Sep 17 00:00:00 2001 From: Ran Mishael <106548467+ranlavanet@users.noreply.github.com> Date: Wed, 4 Sep 2024 11:11:03 +0200 Subject: [PATCH] adding api requested to returned headers (#1669) --- protocol/common/endpoints.go | 1 + protocol/rpcconsumer/rpcconsumer_server.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/protocol/common/endpoints.go b/protocol/common/endpoints.go index afd4fe9256..06c95ba5f9 100644 --- a/protocol/common/endpoints.go +++ b/protocol/common/endpoints.go @@ -27,6 +27,7 @@ const ( ERRORED_PROVIDERS_HEADER_NAME = "Lava-Errored-Providers" NODE_ERRORS_PROVIDERS_HEADER_NAME = "Lava-Node-Errors-providers" REPORTED_PROVIDERS_HEADER_NAME = "Lava-Reported-Providers" + USER_REQUEST_TYPE = "lava-user-request-type" LAVAP_VERSION_HEADER_NAME = "Lavap-Version" LAVA_CONSUMER_PROCESS_GUID = "lava-consumer-process-guid" // these headers need to be lowercase diff --git a/protocol/rpcconsumer/rpcconsumer_server.go b/protocol/rpcconsumer/rpcconsumer_server.go index c301e30764..3dd3cbe0c2 100644 --- a/protocol/rpcconsumer/rpcconsumer_server.go +++ b/protocol/rpcconsumer/rpcconsumer_server.go @@ -394,7 +394,7 @@ func (rpccs *RPCConsumerServer) SendParsedRelay( } returnedResult, err := relayProcessor.ProcessingResult() - rpccs.appendHeadersToRelayResult(ctx, returnedResult, relayProcessor.ProtocolErrors(), relayProcessor, protocolMessage.GetDirectiveHeaders()) + rpccs.appendHeadersToRelayResult(ctx, returnedResult, relayProcessor.ProtocolErrors(), relayProcessor, protocolMessage.GetDirectiveHeaders(), protocolMessage.GetApi().GetName()) if err != nil { return returnedResult, utils.LavaFormatError("failed processing responses from providers", err, utils.Attribute{Key: "GUID", Value: ctx}, utils.LogAttr("endpoint", rpccs.listenEndpoint.Key())) } @@ -1342,7 +1342,7 @@ func (rpccs *RPCConsumerServer) HandleDirectiveHeadersForMessage(chainMessage ch chainMessage.SetForceCacheRefresh(ok) } -func (rpccs *RPCConsumerServer) appendHeadersToRelayResult(ctx context.Context, relayResult *common.RelayResult, protocolErrors uint64, relayProcessor *RelayProcessor, directiveHeaders map[string]string) { +func (rpccs *RPCConsumerServer) appendHeadersToRelayResult(ctx context.Context, relayResult *common.RelayResult, protocolErrors uint64, relayProcessor *RelayProcessor, directiveHeaders map[string]string, apiName string) { if relayResult == nil { return } @@ -1387,6 +1387,13 @@ func (rpccs *RPCConsumerServer) appendHeadersToRelayResult(ctx context.Context, }) } + // add user requested API + metadataReply = append(metadataReply, + pairingtypes.Metadata{ + Name: common.USER_REQUEST_TYPE, + Value: apiName, + }) + // fetch trailer information from the provider by using the provider trailer field. providerNodeExtensions := relayResult.ProviderTrailer.Get(chainlib.RPCProviderNodeExtension) if len(providerNodeExtensions) > 0 {