Do not cache resolved hostnames in REST client. (#6570)

This commit is contained in:
Eugene Kabanov 2024-09-24 07:23:38 +03:00 committed by GitHub
parent 77e835153c
commit 841904bd53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 41 additions and 17 deletions

View File

@ -151,8 +151,11 @@ proc getPayloadBuilderClient*(
if payloadBuilderAddress.isNone:
return err "Payload builder disabled"
let res = RestClientRef.new(payloadBuilderAddress.get)
if res.isOk and res.get.isNil:
err "Got nil payload builder REST client reference"
else:
res
let
flags = {RestClientFlag.CommaSeparatedArray,
RestClientFlag.ResolveAlways}
socketFlags = {SocketFlags.TcpNoDelay}
RestClientRef.new(payloadBuilderAddress.get, flags = flags,
socketFlags = socketFlags)

View File

@ -149,8 +149,16 @@ func getIdent*(storage: ValidatorStorage): ValidatorIdent =
proc restValidatorExit(config: BeaconNodeConf) {.async.} =
let
client = RestClientRef.new(config.restUrlForExit).valueOr:
raise (ref RestError)(msg: $error)
client =
block:
let
flags = {RestClientFlag.CommaSeparatedArray,
RestClientFlag.ResolveAlways}
socketFlags = {SocketFlags.TcpNoDelay}
RestClientRef.new(config.restUrlForExit, flags = flags,
socketFlags = socketFlags).valueOr:
raise (ref RestError)(msg: $error)
stateIdHead = StateIdent(kind: StateQueryKind.Named,
value: StateIdentType.Head)

View File

@ -61,6 +61,13 @@ func shortLog*(v: TrustedNodeSyncTarget): auto =
chronicles.formatIt(TrustedNodeSyncTarget): shortLog(it)
proc createNewRestClient(url: string): Result[RestClientRef, cstring] =
let
flags = {RestClientFlag.CommaSeparatedArray,
RestClientFlag.ResolveAlways}
socketFlags = {SocketFlags.TcpNoDelay}
RestClientRef.new(url, flags = flags, socketFlags = socketFlags)
proc doTrustedNodeSync*(
db: BeaconChainDB,
cfg: RuntimeConfig,
@ -80,8 +87,8 @@ proc doTrustedNodeSync*(
databaseDir, backfill, reindex
var
client = RestClientRef.new(restUrl).valueOr:
error "Cannot connect to server", error = error
client = createNewRestClient(restUrl).valueOr:
error "Cannot connect to server", reason = error
quit 1
# If possible, we'll store the genesis state in the database - this is not
@ -440,8 +447,8 @@ proc doTrustedNodeSync*(
lastError = exc
warn "Retrying download of block", slot, err = exc.msg
client = RestClientRef.new(restUrl).valueOr:
error "Cannot connect to server", url = restUrl, error = error
client = createNewRestClient(restUrl).valueOr:
error "Cannot connect to server", url = restUrl, reason = error
quit 1
raise lastError

View File

@ -1718,11 +1718,16 @@ proc registerValidatorsPerBuilder(
BUILDER_VALIDATOR_REGISTRATION_DELAY_TOLERANCE = 6.seconds
let payloadBuilderClient =
RestClientRef.new(payloadBuilderAddress).valueOr:
debug "Unable to initialize payload builder client while registering validators",
payloadBuilderAddress, epoch,
err = error
return
block:
let
flags = {RestClientFlag.CommaSeparatedArray,
RestClientFlag.ResolveAlways}
socketFlags = {SocketFlags.TcpNoDelay}
RestClientRef.new(payloadBuilderAddress, flags = flags,
socketFlags = socketFlags).valueOr:
debug "Unable to initialize payload builder client while registering validators",
payloadBuilderAddress, epoch, reason = error
return
if payloadBuilderClient.isNil:
debug "registerValidatorsPerBuilder: got nil payload builder REST client reference",

View File

@ -183,7 +183,8 @@ proc addRemoteValidator(pool: var ValidatorPool,
{HttpClientFlag.NoVerifyHost, HttpClientFlag.NoVerifyServerName}
else:
{}
prestoFlags = {RestClientFlag.CommaSeparatedArray}
prestoFlags = {RestClientFlag.CommaSeparatedArray,
RestClientFlag.ResolveAlways}
socketFlags = {SocketFlags.TcpNoDelay}
clients =
block: