mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-17 01:17:36 +00:00
Don't call get_height every block
This commit is contained in:
parent
249f7b904f
commit
93fe8a52dd
1 changed files with 26 additions and 17 deletions
|
@ -118,24 +118,33 @@ async fn main() {
|
||||||
|
|
||||||
let mut rpc_i = 0;
|
let mut rpc_i = 0;
|
||||||
let mut handles: Vec<JoinHandle<()>> = vec![];
|
let mut handles: Vec<JoinHandle<()>> = vec![];
|
||||||
while block_i < main_rpc.get_height().await.expect("couldn't call get_height") {
|
let mut height = 0;
|
||||||
if handles.len() >= async_parallelism {
|
loop {
|
||||||
// Guarantee one handle is complete
|
let new_height = main_rpc.get_height().await.expect("couldn't call get_height");
|
||||||
handles.swap_remove(0).await.unwrap();
|
if new_height == height {
|
||||||
|
break;
|
||||||
// Remove all of the finished handles
|
|
||||||
let mut i = 0;
|
|
||||||
while i < handles.len() {
|
|
||||||
if handles[i].is_finished() {
|
|
||||||
handles.swap_remove(i).await.unwrap();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
height = new_height;
|
||||||
|
|
||||||
handles.push(tokio::spawn(check_block(rpcs[rpc_i].clone(), block_i)));
|
while block_i < height {
|
||||||
rpc_i = (rpc_i + 1) % rpcs.len();
|
if handles.len() >= async_parallelism {
|
||||||
block_i += 1;
|
// Guarantee one handle is complete
|
||||||
|
handles.swap_remove(0).await.unwrap();
|
||||||
|
|
||||||
|
// Remove all of the finished handles
|
||||||
|
let mut i = 0;
|
||||||
|
while i < handles.len() {
|
||||||
|
if handles[i].is_finished() {
|
||||||
|
handles.swap_remove(i).await.unwrap();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handles.push(tokio::spawn(check_block(rpcs[rpc_i].clone(), block_i)));
|
||||||
|
rpc_i = (rpc_i + 1) % rpcs.len();
|
||||||
|
block_i += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue