Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions tap-agent/src/agent/sender_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ type Balance = U256;
pub enum ReceiptFees {
NewReceipt(u128, u64),
UpdateValue(UnaggregatedReceipts),
RavRequestResponse(anyhow::Result<(UnaggregatedReceipts, Option<SignedRAV>)>),
RavRequestResponse(
(
UnaggregatedReceipts,
Option<SignedRAV>,
Result<(), anyhow::Error>,
),
),
Retry,
}

Expand Down Expand Up @@ -285,11 +291,15 @@ impl State {
fn finalize_rav_request(
&mut self,
allocation_id: Address,
rav_result: anyhow::Result<(UnaggregatedReceipts, Option<SignedRAV>)>,
rav_result: (
UnaggregatedReceipts,
Option<SignedRAV>,
Result<(), anyhow::Error>,
),
) {
self.sender_fee_tracker.finish_rav_request(allocation_id);
match rav_result {
Ok((fees, rav)) => {
(fees, rav, Ok(())) => {
self.sender_fee_tracker.ok_rav_request(allocation_id);
self.adaptive_limiter.on_success();

Expand All @@ -299,14 +309,14 @@ impl State {
// update sender fee tracker
self.update_sender_fee(allocation_id, fees);
}
Err(err) => {
// TODO we should update the total value too
(fees, _, Err(err)) => {
self.sender_fee_tracker.failed_rav_backoff(allocation_id);
self.adaptive_limiter.on_failure();
error!(
"Error while requesting RAV for sender {} and allocation {}: {}",
self.sender, allocation_id, err
);
self.update_sender_fee(allocation_id, fees);
}
};
}
Expand Down Expand Up @@ -1079,8 +1089,18 @@ pub mod tests {
ReceiptFees::RavRequestResponse(l),
ReceiptFees::RavRequestResponse(r),
) => match (l, r) {
(Ok(l), Ok(r)) => l == r,
(Err(l), Err(r)) => l.to_string() == r.to_string(),
(l, r) if l.2.is_ok() && r.2.is_ok() => l.0 == r.0 && l.1 == r.1,
(l, r) if l.2.is_err() && r.2.is_err() => {
let l = match &l.2 {
Ok(()) => "Success".to_string(),
Err(e) => e.to_string(),
};
let r = match &r.2 {
Ok(()) => "Success".to_string(),
Err(e) => e.to_string(),
};
l == r
}
_ => false,
},
(ReceiptFees::Retry, ReceiptFees::Retry) => true,
Expand Down Expand Up @@ -1483,14 +1503,15 @@ pub mod tests {
if let Some(sender_account) = self.sender_actor.as_ref() {
sender_account.cast(SenderAccountMessage::UpdateReceiptFees(
*ALLOCATION_ID_0,
ReceiptFees::RavRequestResponse(Ok((
ReceiptFees::RavRequestResponse((
UnaggregatedReceipts {
value: *self.next_unaggregated_fees_value.lock().unwrap(),
last_id: 0,
counter: 0,
},
Some(signed_rav),
))),
Ok(()),
)),
))?;
}
}
Expand Down
18 changes: 10 additions & 8 deletions tap-agent/src/agent/sender_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,21 @@ impl Actor for SenderAllocation {
}
SenderAllocationMessage::TriggerRAVRequest => {
let rav_result = if state.unaggregated_fees.value > 0 {
state
.request_rav()
.await
.map(|_| (state.unaggregated_fees, state.latest_rav.clone()))
state.request_rav().await
} else {
Err(anyhow!("Unaggregated fee equals zero"))
};

let ufees_lrav_rav_result = (
state.unaggregated_fees,
state.latest_rav.clone(),
rav_result,
);
// encapsulate inanother okay, unwrap after and send the result over here
state
.sender_account_ref
.cast(SenderAccountMessage::UpdateReceiptFees(
state.allocation_id,
ReceiptFees::RavRequestResponse(rav_result),
ReceiptFees::RavRequestResponse(ufees_lrav_rav_result),
))?;
}
#[cfg(test)]
Expand Down Expand Up @@ -1619,7 +1621,7 @@ pub mod tests {
_,
ReceiptFees::RavRequestResponse(rav_response),
) => {
assert!(rav_response.is_err());
assert!(rav_response.2.is_err());
}
v => panic!("Expecting RavRequestResponse as last message, found: {v:?}"),
}
Expand Down Expand Up @@ -1734,7 +1736,7 @@ pub mod tests {
_,
ReceiptFees::RavRequestResponse(rav_response),
) => {
assert!(rav_response.is_err());
assert!(rav_response.2.is_err());
}
v => panic!("Expecting RavRequestResponse as last message, found: {v:?}"),
}
Expand Down
Loading