Fix iteration issue. (#5105)

Add elapsed_time to log statement.
This commit is contained in:
Eugene Kabanov 2023-06-20 19:41:20 +03:00 committed by GitHub
parent d00788ab29
commit e2f7065432
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 17 deletions

View File

@ -1231,3 +1231,7 @@ proc waitForBlock*(
let dur = Moment.now() - startTime
debug "Waiting for block cutoff was interrupted", duration = dur
raise exc
iterator chunks*[T](data: openArray[T], maxCount: Positive): seq[T] =
for i in countup(0, len(data) - 1, maxCount):
yield @(data.toOpenArray(i, min(i + maxCount, len(data)) - 1))

View File

@ -49,21 +49,11 @@ proc pollForValidatorIndices*(service: DutiesServiceRef) {.async.} =
res.add(ValidatorIdent.init(validator.pubkey))
res
let start = Moment.now()
var validators: seq[RestValidator]
var offset = 0
while offset < len(validatorIdents):
let arraySize = min(ClientMaximumValidatorIds, len(validatorIdents))
let idents =
block:
var res = newSeq[ValidatorIdent](arraySize)
var k = 0
for i in offset ..< arraySize:
res[k] = validatorIdents[i]
inc(k)
res
for idents in chunks(validatorIdents, ClientMaximumValidatorIds):
let res =
try:
await vc.getValidators(idents, ApiStrategyKind.First)
@ -78,12 +68,9 @@ proc pollForValidatorIndices*(service: DutiesServiceRef) {.async.} =
error "Unexpected error occurred while getting validator information",
err_name = exc.name, err_msg = exc.msg
return
for item in res:
validators.add(item)
offset += arraySize
var
missing: seq[string]
updated: seq[string]
@ -104,7 +91,8 @@ proc pollForValidatorIndices*(service: DutiesServiceRef) {.async.} =
info "Validator indices updated",
pending = len(validatorIdents) - len(updated),
missing = len(missing),
updated = len(updated)
updated = len(updated),
elapsed_time = (Moment.now() - start)
trace "Validator indices update dump", missing_validators = missing,
updated_validators = updated
vc.indicesAvailable.fire()