Skip to content

Commit

Permalink
Backwards-compatible handling of Engine URLs that don't include a spe…
Browse files Browse the repository at this point in the history
…cified protocol
  • Loading branch information
zah committed Mar 14, 2023
1 parent 2ee15a3 commit 3a35809
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions beacon_chain/eth1/el_conf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ proc parseCmdArg*(T: type EngineApiUrlConfigValue, input: string): T
jwtSecretFile: jwtSecretFile,
roles: roles)

proc fixupWeb3Urls*(web3Url: var string) =
var normalizedUrl = toLowerAscii(web3Url)
if not (normalizedUrl.startsWith("https://") or
normalizedUrl.startsWith("http://") or
normalizedUrl.startsWith("wss://") or
normalizedUrl.startsWith("ws://")):
warn "The Web3 URL does not specify a protocol. Assuming a WebSocket server", web3Url
web3Url = "ws://" & web3Url

proc toFinalUrl*(confValue: EngineApiUrlConfigValue,
confJwtSecret: Option[seq[byte]]): Result[EngineApiUrl, cstring] =
if confValue.jwtSecret.isSome and confValue.jwtSecretFile.isSome:
Expand All @@ -138,8 +147,11 @@ proc toFinalUrl*(confValue: EngineApiUrlConfigValue,
else:
confJwtSecret

var url = confValue.url
fixupWeb3Urls(url)

ok EngineApiUrl.init(
url = confValue.url,
url = url,
jwtSecret = jwtSecret,
roles = confValue.roles.get(defaultEngineApiRoles))

Expand All @@ -163,12 +175,3 @@ proc toFinalEngineApiUrls*(elUrls: seq[EngineApiUrlConfigValue],
fatal "Invalid EL configuration", err = error
quit 1
result.add engineApiUrl

proc fixupWeb3Urls*(web3Url: var string) =
var normalizedUrl = toLowerAscii(web3Url)
if not (normalizedUrl.startsWith("https://") or
normalizedUrl.startsWith("http://") or
normalizedUrl.startsWith("wss://") or
normalizedUrl.startsWith("ws://")):
warn "The Web3 URL does not specify a protocol. Assuming a WebSocket server", web3Url
web3Url = "ws://" & web3Url

0 comments on commit 3a35809

Please sign in to comment.