Skip to content

Commit 32d0088

Browse files
committed
feat: return rav result to sender
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent f179e61 commit 32d0088

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

tap-agent/src/agent/sender_account.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,24 @@ impl State {
217217
);
218218
};
219219
// we call and wait for the response so we don't process anymore update
220-
let Ok((fees, rav)) = call!(allocation, SenderAllocationMessage::TriggerRAVRequest) else {
220+
let Ok(rav_result) = call!(allocation, SenderAllocationMessage::TriggerRAVRequest) else {
221221
anyhow::bail!("Error while sending and waiting message for actor {allocation_id}");
222222
};
223+
let (fees, rav) = match rav_result {
224+
Ok(ok_value) => {
225+
self.rav_tracker.ok_rav_request(allocation_id);
226+
ok_value
227+
}
228+
Err(err) => {
229+
self.rav_tracker.failed_rav_backoff(allocation_id);
230+
anyhow::bail!(
231+
"Error while requesting RAV for sender {} and allocation {}: {}",
232+
self.sender,
233+
allocation_id,
234+
err
235+
);
236+
}
237+
};
223238

224239
let rav_value = rav.map_or(0, |rav| rav.message.valueAggregate);
225240
// update rav tracker

tap-agent/src/agent/sender_allocation.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ pub struct SenderAllocationState {
105105
domain_separator: Eip712Domain,
106106
sender_account_ref: ActorRef<SenderAccountMessage>,
107107

108-
failed_ravs_count: u32,
109-
failed_rav_backoff: Instant,
110-
111108
http_client: jsonrpsee::http_client::HttpClient,
112109
}
113110

@@ -127,7 +124,7 @@ pub struct SenderAllocationArgs {
127124
#[derive(Debug)]
128125
pub enum SenderAllocationMessage {
129126
NewReceipt(NewReceiptNotification),
130-
TriggerRAVRequest(RpcReplyPort<(UnaggregatedReceipts, Option<SignedRAV>)>),
127+
TriggerRAVRequest(RpcReplyPort<anyhow::Result<(UnaggregatedReceipts, Option<SignedRAV>)>>),
131128
#[cfg(test)]
132129
GetUnaggregatedReceipts(RpcReplyPort<UnaggregatedReceipts>),
133130
}
@@ -255,13 +252,17 @@ impl Actor for SenderAllocation {
255252
}
256253
// we use a blocking call here to ensure that only one RAV request is running at a time.
257254
SenderAllocationMessage::TriggerRAVRequest(reply) => {
258-
if state.unaggregated_fees.value > 0 {
259-
if let Err(err) = state.request_rav().await {
260-
error!(error = %err, "Error while requesting rav.");
261-
}
262-
}
255+
let rav_result = if state.unaggregated_fees.value > 0 {
256+
state
257+
.request_rav()
258+
.await
259+
.map(|_| (state.unaggregated_fees.clone(), state.latest_rav.clone()))
260+
} else {
261+
Err(anyhow!("Unaggregated fee equals zero"))
262+
};
263+
263264
if !reply.is_closed() {
264-
let _ = reply.send((state.unaggregated_fees.clone(), state.latest_rav.clone()));
265+
let _ = reply.send(rav_result);
265266
}
266267
}
267268
#[cfg(test)]
@@ -332,8 +333,6 @@ impl SenderAllocationState {
332333
sender_account_ref: sender_account_ref.clone(),
333334
unaggregated_fees: UnaggregatedReceipts::default(),
334335
invalid_receipts_fees: UnaggregatedReceipts::default(),
335-
failed_rav_backoff: Instant::now(),
336-
failed_ravs_count: 0,
337336
latest_rav,
338337
http_client,
339338
})
@@ -446,14 +445,9 @@ impl SenderAllocationState {
446445
RAVS_CREATED
447446
.with_label_values(&[&self.sender.to_string(), &self.allocation_id.to_string()])
448447
.inc();
449-
self.failed_ravs_count = 0;
450448
Ok(())
451449
}
452450
Err(e) => {
453-
error!(
454-
"Error while requesting RAV for sender {} and allocation {}: {}",
455-
self.sender, self.allocation_id, e
456-
);
457451
if let RavError::AllReceiptsInvalid = e {
458452
self.unaggregated_fees = self.calculate_unaggregated_fee().await?;
459453
}

0 commit comments

Comments
 (0)