Created
December 2, 2022 15:47
-
-
Save riemannulus/a246864e0f755e82d1d61d80176b2ba2 to your computer and use it in GitHub Desktop.
WaitForUntilLeast23NodeAlive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task WaitForUntilLeast23NodeAlive(CancellationToken ctx) | |
{ | |
async Task<bool> PongResponse(BoundPeer peer) | |
{ | |
try | |
{ | |
var result = await _transport.SendMessageAsync( | |
peer, | |
new PingMsg(), | |
TimeSpan.FromSeconds(1), | |
ctx); | |
return result is PongMsg; | |
} | |
catch (CommunicationFailException) | |
{ | |
return false; | |
} | |
} | |
while (true) | |
{ | |
var tasks = new List<Task<bool>>(); | |
foreach (var boundPeer in _peers) | |
{ | |
tasks.Add(PongResponse(boundPeer)); | |
} | |
var result = await Task.WhenAll(tasks); | |
if (result.Count(x => x) + 1 >= (_peers.Count() + 1) * 2 / 3) | |
{ | |
break; | |
} | |
_logger.Debug( | |
"Bootstrapped validators are not reached +2/3 yet," + | |
" current: {BootstrappedValidatorCount}", | |
result.Count(x => x)); | |
} | |
_logger.Debug( | |
"Bootstrapped validators are reached +2/3"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment