Fix snode pool updating bug

This commit is contained in:
nielsandriesse 2021-05-12 09:13:53 +10:00
parent 428a61f9f9
commit b694777a71
1 changed files with 6 additions and 2 deletions

View File

@ -184,10 +184,12 @@ public final class SnodeAPI : NSObject {
}
let snodePoolPromises: [Promise<Set<Snode>>] = snodes.map { snode in
return attempt(maxRetryCount: 4, recoveringOn: Threading.workQueue) {
// Don't specify a limit in the request. Service nodes return a shuffled
// list of nodes so if we specify a limit the 3 responses we get might have
// very little overlap.
let parameters: JSON = [
"endpoint" : "get_service_nodes",
"params" : [
"limit" : 256,
"active_only" : true,
"fields" : [
"public_ip" : true, "storage_port" : true, "pubkey_ed25519" : true, "pubkey_x25519" : true
@ -214,7 +216,9 @@ public final class SnodeAPI : NSObject {
var result: Set<Snode> = results[0]
results.forEach { result = result.union($0) }
if result.count > 24 { // We want the snodes to agree on at least this many snodes
return result
// Limit the snode pool size to 256 so that we don't go too long without
// refreshing it
return (result.count > 256) ? result[..<256] : result
} else {
throw Error.inconsistentSnodePools
}