Skip to content

Commit

Permalink
feat: use reportResult instead of reportResultBatch when only 1 batch
Browse files Browse the repository at this point in the history
  • Loading branch information
lrubiorod authored and tmpolaczyk committed Mar 21, 2022
1 parent 0f46bd5 commit 96a58dc
Showing 1 changed file with 63 additions and 11 deletions.
74 changes: 63 additions & 11 deletions bridges/centralized-ethereum/src/actors/dr_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,36 @@ impl Handler<DrReporterMsg> for DrReporter {
.await;

for (batch_results, estimated_gas_limit) in batches {
let receipt_fut = wrb_contract.call_with_confirmations(
"reportResultBatch",
(batch_results, verbose),
eth_account,
contract::Options::with(|opt| {
opt.gas = Some(estimated_gas_limit);
opt.gas_price = Some(max_gas_price);
}),
1,
);
let receipt = tokio::time::timeout(eth_confirmation_timeout, receipt_fut).await;
let only_1_batch = batch_results.len() == 1;
let receipt = if only_1_batch {
let (dr_id, ts, dr_tx_hash, report_result) =
unwrap_batch(batch_results[0].clone());

let receipt_fut = wrb_contract.call_with_confirmations(
"reportResult",
(dr_id, ts, dr_tx_hash, report_result),
eth_account,
contract::Options::with(|opt| {
opt.gas = Some(estimated_gas_limit);
opt.gas_price = Some(max_gas_price);
}),
1,
);
tokio::time::timeout(eth_confirmation_timeout, receipt_fut).await
} else {
let receipt_fut = wrb_contract.call_with_confirmations(
"reportResultBatch",
(batch_results, verbose),
eth_account,
contract::Options::with(|opt| {
opt.gas = Some(estimated_gas_limit);
opt.gas_price = Some(max_gas_price);
}),
1,
);
tokio::time::timeout(eth_confirmation_timeout, receipt_fut).await
};

match receipt {
Ok(Ok(receipt)) => {
log::debug!("Request [{:?}], reportResultBatch: {:?}", dr_ids, receipt);
Expand Down Expand Up @@ -388,6 +407,39 @@ async fn split_by_gas_limit(
v
}

fn unwrap_batch(t: Token) -> (U256, U256, H256, Vec<u8>) {
let dr_id: U256;
let ts: U256;
let dr_tx_hash: H256;
let report_result: Vec<u8>;
if let Token::Tuple(mut token_vec) = t {
if let Token::Uint(x) = token_vec.pop().unwrap() {
dr_id = x
} else {
panic!("Token:Uint not found in unwrap_batch function");
}
if let Token::Uint(x) = token_vec.pop().unwrap() {
ts = x
} else {
panic!("Token:Uint not found in unwrap_batch function");
}
if let Token::FixedBytes(x) = token_vec.pop().unwrap() {
dr_tx_hash = H256::from_slice(x.as_ref());
} else {
panic!("Token:FixedBytes not found in unwrap_batch function");
}
if let Token::Bytes(x) = token_vec.pop().unwrap() {
report_result = x
} else {
panic!("Token:Bytes not found in unwrap_batch function");
}

(dr_id, ts, dr_tx_hash, report_result)
} else {
panic!("Token:Tuple not found in unwrap_batch function");
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 96a58dc

Please sign in to comment.