Skip to content

Commit

Permalink
feat(bridge): loop on query status batches until head is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
guidiaz committed May 13, 2024
1 parent 9527090 commit 165008f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions bridges/centralized-ethereum/src/actors/eth_poller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,25 @@ impl EthPoller {

let last_dr_id = dr_database_addr.send(GetLastDrId).await;

if let (Ok(mut next_dr_id), Ok(Ok(mut last_dr_id))) = (next_dr_id, last_dr_id) {
if let (Ok(next_dr_id), Ok(Ok(mut last_dr_id))) = (next_dr_id, last_dr_id) {
if last_dr_id < skip_first {
log::debug!(
"Skipping first {} queries as per SKIP_FIRST config param",
skip_first
);
last_dr_id = skip_first;
}
if last_dr_id < next_dr_id {
if next_dr_id > last_dr_id + max_batch_size {
next_dr_id = last_dr_id + max_batch_size;
}
while last_dr_id < next_dr_id {
let init_index = usize::try_from(last_dr_id + 1).unwrap();
let last_index = usize::try_from(next_dr_id).unwrap();
let last_index = match next_dr_id.cmp(&(last_dr_id + max_batch_size)) {
std::cmp::Ordering::Greater => usize::try_from(last_dr_id + max_batch_size).unwrap(),
_ => usize::try_from(next_dr_id).unwrap()
};
let ids = init_index..last_index;
let ids: Vec<Token> = ids.map(|id| Token::Uint(id.into())).collect();

last_dr_id += U256::from(max_batch_size);

let queries_status: Result<Vec<Token>, web3::contract::Error> = wrb_contract
.query(
"getQueryStatusBatch",
Expand Down

0 comments on commit 165008f

Please sign in to comment.