From f751fde417860ba62ba14e795032c45942aad7d2 Mon Sep 17 00:00:00 2001 From: Eugene Kabanov Date: Mon, 15 Jul 2024 05:27:23 +0300 Subject: [PATCH] Use Nimbus specific agent string instead of nim-presto defaults. (#6424) * Use Nimbus specific agent string instead of nim-presto defaults. Use response(code) overload. * Fix REST API test. --- beacon_chain/nimbus_beacon_node.nim | 1 + beacon_chain/nimbus_binary_common.nim | 4 ++++ beacon_chain/rpc/rest_node_api.nim | 4 ++-- beacon_chain/rpc/rest_validator_api.nim | 4 ++-- beacon_chain/version.nim | 2 ++ ncli/resttest-rules.json | 3 +-- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 6fc2187e8..c78489c7a 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -826,6 +826,7 @@ proc init*(T: type BeaconNode, RestServerRef.init(config.restAddress, config.restPort, config.restAllowedOrigin, validateBeaconApiQueries, + nimbusAgentStr, config) else: nil diff --git a/beacon_chain/nimbus_binary_common.nim b/beacon_chain/nimbus_binary_common.nim index 51d6a3d35..6c896118b 100644 --- a/beacon_chain/nimbus_binary_common.nim +++ b/beacon_chain/nimbus_binary_common.nim @@ -357,6 +357,7 @@ proc init*(T: type RestServerRef, port: Port, allowedOrigin: Option[string], validateFn: PatternCallback, + ident: string, config: AnyConf): T = let address = initTAddress(ip, port) @@ -375,6 +376,7 @@ proc init*(T: type RestServerRef, let res = RestServerRef.new(RestRouter.init(validateFn, allowedOrigin), address, serverFlags = serverFlags, + serverIdent = ident, httpHeadersTimeout = headersTimeout, maxHeadersSize = maxHeadersSize, maxRequestBodySize = maxRequestBodySize, @@ -428,11 +430,13 @@ proc initKeymanagerServer*( RestServerRef.init(config.keymanagerAddress, config.keymanagerPort, config.keymanagerAllowedOrigin, validateKeymanagerApiQueries, + nimbusAgentStr, config) else: RestServerRef.init(config.keymanagerAddress, config.keymanagerPort, config.keymanagerAllowedOrigin, validateKeymanagerApiQueries, + nimbusAgentStr, config) else: nil diff --git a/beacon_chain/rpc/rest_node_api.nim b/beacon_chain/rpc/rest_node_api.nim index a9a5a114e..b96e0724b 100644 --- a/beacon_chain/rpc/rest_node_api.nim +++ b/beacon_chain/rpc/rest_node_api.nim @@ -141,7 +141,7 @@ proc getP2PAddresses(node: BeaconNode): seq[string] = proc installNodeApiHandlers*(router: var RestRouter, node: BeaconNode) = let cachedVersion = - RestApiResponse.prepareJsonResponse((version: "Nimbus/" & fullVersionStr)) + RestApiResponse.prepareJsonResponse((version: nimbusAgentStr)) # https://ethereum.github.io/beacon-APIs/#/Node/getNetworkIdentity router.api2(MethodGet, "/eth/v1/node/identity") do () -> RestApiResponse: @@ -283,4 +283,4 @@ proc installNodeApiHandlers*(router: var RestRouter, node: BeaconNode) = Http206 else: Http200 - RestApiResponse.response("", status, contentType = "") + RestApiResponse.response(status) diff --git a/beacon_chain/rpc/rest_validator_api.nim b/beacon_chain/rpc/rest_validator_api.nim index 81429df51..6e477f238 100644 --- a/beacon_chain/rpc/rest_validator_api.nim +++ b/beacon_chain/rpc/rest_validator_api.nim @@ -1102,7 +1102,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) = numUpdatedFeeRecipients = numUpdated, numRefreshedFeeRecipients = numRefreshed - RestApiResponse.response("", Http200, "text/plain") + RestApiResponse.response(Http200) # https://ethereum.github.io/beacon-APIs/#/Validator/registerValidator # https://github.com/ethereum/beacon-APIs/blob/v2.3.0/apis/validator/register_validator.yaml @@ -1129,7 +1129,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) = node.externalBuilderRegistrations[signedValidatorRegistration.message.pubkey] = signedValidatorRegistration - RestApiResponse.response("", Http200, "text/plain") + RestApiResponse.response(Http200) # https://ethereum.github.io/beacon-APIs/#/Validator/getLiveness router.api2(MethodPost, "/eth/v1/validator/liveness/{epoch}") do ( diff --git a/beacon_chain/version.nim b/beacon_chain/version.nim index 7d199a5e7..99d2a5c47 100644 --- a/beacon_chain/version.nim +++ b/beacon_chain/version.nim @@ -51,6 +51,8 @@ const fullVersionStr* = "v" & versionAsStr & "-" & gitRevision & "-" & versionBlob + nimbusAgentStr* = "Nimbus/" & fullVersionStr + func getNimGitHash*(): string = const gitPrefix = "git hash: " let tmp = splitLines(nimFullBanner) diff --git a/ncli/resttest-rules.json b/ncli/resttest-rules.json index 42c1b375d..7650f66ca 100644 --- a/ncli/resttest-rules.json +++ b/ncli/resttest-rules.json @@ -4748,8 +4748,7 @@ "body": {"content-type": "application/json", "data": "[{\"message\":{\"fee_recipient\":\"0xb943c2c22b1b186a34f47c4dbe2fe367de9ec180\",\"gas_limit\":\"40000000\",\"timestamp\":\"1661879190\",\"pubkey\":\"0xa37b7bb9c412b8cc318fabf7b1fec33eb9634680687f07b977393180ce99889dbcfda81900f3afb9f2281930cf49f5d8\"},\"signature\":\"0xa493085fab365d13bea2376434abc3dbfba00a576276c853acabd7b9cb2f2b4b0a90738dd9baeaef75d0f42fa94119a70a09b0ed38fbebb6dde92c9ca062447018821f36c19d6fe34eb8c357d62e5d33e5c1d35035472ef7dd22a7425cdba0c5\"}]"} }, "response": { - "status": {"operator": "equals", "value": "200"}, - "headers": [{"key": "Content-Type", "value": "text/plain", "operator": "equals"}] + "status": {"operator": "equals", "value": "200"} } }, {