Skip to content

Commit 3d6efdc

Browse files
committed
feat(c-bridge): loop on query status batches until head is reached
1 parent ce8e041 commit 3d6efdc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

bridges/centralized-ethereum/src/actors/eth_poller.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,27 @@ impl EthPoller {
105105

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

108-
if let (Ok(mut next_dr_id), Ok(Ok(mut last_dr_id))) = (next_dr_id, last_dr_id) {
108+
if let (Ok(next_dr_id), Ok(Ok(mut last_dr_id))) = (next_dr_id, last_dr_id) {
109109
if last_dr_id < skip_first {
110110
log::debug!(
111111
"Skipping first {} queries as per SKIP_FIRST config param",
112112
skip_first
113113
);
114114
last_dr_id = skip_first;
115115
}
116-
if last_dr_id < next_dr_id {
117-
if next_dr_id > last_dr_id + max_batch_size {
118-
next_dr_id = last_dr_id + max_batch_size;
119-
}
116+
while last_dr_id < next_dr_id {
120117
let init_index = usize::try_from(last_dr_id + 1).unwrap();
121-
let last_index = usize::try_from(next_dr_id).unwrap();
118+
let last_index = match next_dr_id.cmp(&(last_dr_id + max_batch_size)) {
119+
std::cmp::Ordering::Greater => {
120+
usize::try_from(last_dr_id + max_batch_size).unwrap()
121+
}
122+
_ => usize::try_from(next_dr_id).unwrap(),
123+
};
122124
let ids = init_index..last_index;
123125
let ids: Vec<Token> = ids.map(|id| Token::Uint(id.into())).collect();
124126

127+
last_dr_id += U256::from(max_batch_size);
128+
125129
let queries_status: Result<Vec<Token>, web3::contract::Error> = wrb_contract
126130
.query(
127131
"getQueryStatusBatch",

0 commit comments

Comments
 (0)