Skip to content

Commit

Permalink
PRT-1153: Consumer sometimes get non archive provider even though it …
Browse files Browse the repository at this point in the history
…specifically asked only for archive (lavanet#1261)

* Fix a small bug in the rest message

* Fix the bug that caused the consumer to use non archive provider on archive relay
  • Loading branch information
shleikes authored Feb 28, 2024
1 parent 6ff6638 commit d8d1eb4
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 6 deletions.
7 changes: 6 additions & 1 deletion protocol/chainlib/base_chain_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ func (bcp *BaseChainParser) GetVerifications(supported []string) (retVerificatio
return
}

func (bcp *BaseChainParser) Construct(spec spectypes.Spec, taggedApis map[spectypes.FUNCTION_TAG]TaggedContainer, serverApis map[ApiKey]ApiContainer, apiCollections map[CollectionKey]*spectypes.ApiCollection, headers map[ApiKey]*spectypes.Header, verifications map[VerificationKey][]VerificationContainer) {
func (bcp *BaseChainParser) Construct(spec spectypes.Spec, taggedApis map[spectypes.FUNCTION_TAG]TaggedContainer,
serverApis map[ApiKey]ApiContainer, apiCollections map[CollectionKey]*spectypes.ApiCollection, headers map[ApiKey]*spectypes.Header,
verifications map[VerificationKey][]VerificationContainer, extensionParser extensionslib.ExtensionParser,
) {
bcp.spec = spec
bcp.serverApis = serverApis
bcp.taggedApis = taggedApis
Expand All @@ -241,7 +244,9 @@ func (bcp *BaseChainParser) Construct(spec spectypes.Spec, taggedApis map[specty
allowedAddons[apoCollection.CollectionData.AddOn] = false
}
bcp.allowedAddons = allowedAddons

bcp.extensionParser = extensionslib.ExtensionParser{AllowedExtensions: allowedExtensions}
bcp.extensionParser.SetConfiguredExtensions(extensionParser.GetConfiguredExtensions())
}

func (bcp *BaseChainParser) GetParsingByTag(tag spectypes.FUNCTION_TAG) (parsing *spectypes.ParseDirective, collectionData *spectypes.CollectionData, existed bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (jm RestMessage) CheckResponseError(data []byte, httpStatusCode int) (hasEr
}
// make sure we have both message and code for an error message.
if errMsg, okMessage := result["message"].(string); okMessage {
if _, okCode := result["code"].(string); okCode {
if _, okCode := result["code"]; okCode {
return true, errMsg
}
utils.LavaFormatWarning("found only message without code in returned result", nil, utils.LogAttr("result", result))
Expand Down
4 changes: 4 additions & 0 deletions protocol/chainlib/extensionslib/extension_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func (ep *ExtensionParser) GetExtension(extension ExtensionKey) *spectypes.Exten
return nil
}

func (ep *ExtensionParser) GetConfiguredExtensions() map[ExtensionKey]*spectypes.Extension {
return ep.configuredExtensions
}

func (ep *ExtensionParser) AllowedExtension(extension string) bool {
if extension == "" {
return true
Expand Down
2 changes: 1 addition & 1 deletion protocol/chainlib/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (apip *GrpcChainParser) SetSpec(spec spectypes.Spec) {

// extract server and tagged apis from spec
serverApis, taggedApis, apiCollections, headers, verifications := getServiceApis(spec, spectypes.APIInterfaceGrpc)
apip.BaseChainParser.Construct(spec, taggedApis, serverApis, apiCollections, headers, verifications)
apip.BaseChainParser.Construct(spec, taggedApis, serverApis, apiCollections, headers, verifications, apip.BaseChainParser.extensionParser)
}

// DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)
Expand Down
2 changes: 1 addition & 1 deletion protocol/chainlib/jsonRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (apip *JsonRPCChainParser) SetSpec(spec spectypes.Spec) {

// extract server and tagged apis from spec
serverApis, taggedApis, apiCollections, headers, verifications := getServiceApis(spec, spectypes.APIInterfaceJsonRPC)
apip.BaseChainParser.Construct(spec, taggedApis, serverApis, apiCollections, headers, verifications)
apip.BaseChainParser.Construct(spec, taggedApis, serverApis, apiCollections, headers, verifications, apip.BaseChainParser.extensionParser)
}

func (apip *JsonRPCChainParser) GetInternalPaths() map[string]struct{} {
Expand Down
2 changes: 1 addition & 1 deletion protocol/chainlib/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (apip *RestChainParser) SetSpec(spec spectypes.Spec) {

// extract server and tagged apis from spec
serverApis, taggedApis, apiCollections, headers, verifications := getServiceApis(spec, spectypes.APIInterfaceRest)
apip.BaseChainParser.Construct(spec, taggedApis, serverApis, apiCollections, headers, verifications)
apip.BaseChainParser.Construct(spec, taggedApis, serverApis, apiCollections, headers, verifications, apip.BaseChainParser.extensionParser)
}

// DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)
Expand Down
2 changes: 1 addition & 1 deletion protocol/chainlib/tendermintRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (apip *TendermintChainParser) SetSpec(spec spectypes.Spec) {

// extract server and tagged apis from spec
serverApis, taggedApis, apiCollections, headers, verifications := getServiceApis(spec, spectypes.APIInterfaceTendermintRPC)
apip.BaseChainParser.Construct(spec, taggedApis, serverApis, apiCollections, headers, verifications)
apip.BaseChainParser.Construct(spec, taggedApis, serverApis, apiCollections, headers, verifications, apip.BaseChainParser.extensionParser)
}

// DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)
Expand Down

0 comments on commit d8d1eb4

Please sign in to comment.