|
3 | 3 |
|
4 | 4 | use alloy::hex::ToHexExt; |
5 | 5 | use alloy::primitives::U256; |
| 6 | + |
6 | 7 | use bigdecimal::num_bigint::ToBigInt; |
7 | 8 | use bigdecimal::ToPrimitive; |
| 9 | + |
8 | 10 | use graphql_client::GraphQLQuery; |
9 | 11 | use jsonrpsee::http_client::HttpClientBuilder; |
10 | 12 | use prometheus::{register_gauge_vec, register_int_gauge_vec, GaugeVec, IntGaugeVec}; |
@@ -197,25 +199,30 @@ impl State { |
197 | 199 | sender_allocation_id |
198 | 200 | } |
199 | 201 |
|
200 | | - async fn rav_requester_single(&mut self) -> Result<()> { |
201 | | - let Some(allocation_id) = self.sender_fee_tracker.get_heaviest_allocation_id() else { |
202 | | - anyhow::bail!( |
203 | | - "Error while getting the heaviest allocation, \ |
204 | | - this is due one of the following reasons: \n |
205 | | - 1. allocations have too much fees under their buffer\n |
206 | | - 2. allocations are blocked to be redeemed due to ongoing last rav. \n |
207 | | - If you keep seeing this message try to increase your `amount_willing_to_lose` \ |
208 | | - and restart your `tap-agent`\n |
209 | | - If this doesn't work, open an issue on our Github." |
210 | | - ); |
211 | | - }; |
| 202 | + async fn rav_request_for_heaviest_allocation(&mut self) -> Result<()> { |
| 203 | + let allocation_id = self |
| 204 | + .sender_fee_tracker |
| 205 | + .get_heaviest_allocation_id() |
| 206 | + .ok_or_else(|| { |
| 207 | + anyhow::anyhow!( |
| 208 | + "Error while getting the heaviest allocation, \ |
| 209 | + this is due one of the following reasons: \n |
| 210 | + 1. allocations have too much fees under their buffer\n |
| 211 | + 2. allocations are blocked to be redeemed due to ongoing last rav. \n |
| 212 | + If you keep seeing this message try to increase your `amount_willing_to_lose` \ |
| 213 | + and restart your `tap-agent`\n |
| 214 | + If this doesn't work, open an issue on our Github." |
| 215 | + ) |
| 216 | + })?; |
| 217 | + self.rav_request_for_allocation(allocation_id).await |
| 218 | + } |
| 219 | + |
| 220 | + async fn rav_request_for_allocation(&mut self, allocation_id: Address) -> Result<()> { |
212 | 221 | let sender_allocation_id = self.format_sender_allocation(&allocation_id); |
213 | 222 | let allocation = ActorRef::<SenderAllocationMessage>::where_is(sender_allocation_id); |
214 | 223 |
|
215 | 224 | let Some(allocation) = allocation else { |
216 | | - anyhow::bail!( |
217 | | - "Error while getting allocation actor {allocation_id} with most unaggregated fees" |
218 | | - ); |
| 225 | + anyhow::bail!("Error while getting allocation actor {allocation_id}"); |
219 | 226 | }; |
220 | 227 |
|
221 | 228 | allocation |
@@ -630,22 +637,47 @@ impl Actor for SenderAccount { |
630 | 637 | if should_deny { |
631 | 638 | state.add_to_denylist().await; |
632 | 639 | } |
| 640 | + let total_counter_for_allocation = state |
| 641 | + .sender_fee_tracker |
| 642 | + .get_total_counter_outside_buffer_for_allocation(&allocation_id) |
| 643 | + as u64; |
| 644 | + let counter_greater_receipt_limit = |
| 645 | + total_counter_for_allocation >= state.config.tap.rav_request_receipt_limit; |
| 646 | + let total_fee_outside_buffer = |
| 647 | + state.sender_fee_tracker.get_total_fee_outside_buffer(); |
| 648 | + let total_fee_greater_trigger_value = |
| 649 | + total_fee_outside_buffer >= state.config.tap.rav_request_trigger_value; |
| 650 | + |
| 651 | + let rav_result = match ( |
| 652 | + counter_greater_receipt_limit, |
| 653 | + total_fee_greater_trigger_value, |
| 654 | + ) { |
| 655 | + (true, _) => { |
| 656 | + tracing::debug!( |
| 657 | + total_counter_for_allocation, |
| 658 | + rav_request_receipt_limit = state.config.tap.rav_request_receipt_limit, |
| 659 | + %allocation_id, |
| 660 | + "Total counter greater than the receipt limit per rav. Triggering RAV request" |
| 661 | + ); |
633 | 662 |
|
634 | | - if state.sender_fee_tracker.get_total_fee_outside_buffer() |
635 | | - >= state.config.tap.rav_request_trigger_value |
636 | | - { |
637 | | - tracing::debug!( |
638 | | - total_fee = state.sender_fee_tracker.get_total_fee(), |
639 | | - trigger_value = state.config.tap.rav_request_trigger_value, |
640 | | - "Total fee greater than the trigger value. Triggering RAV request" |
641 | | - ); |
642 | | - // In case we fail, we want our actor to keep running |
643 | | - if let Err(err) = state.rav_requester_single().await { |
644 | | - tracing::error!( |
645 | | - error = %err, |
646 | | - "There was an error while requesting a RAV." |
| 663 | + state.rav_request_for_allocation(allocation_id).await |
| 664 | + } |
| 665 | + (_, true) => { |
| 666 | + tracing::debug!( |
| 667 | + total_fee_outside_buffer, |
| 668 | + trigger_value = state.config.tap.rav_request_trigger_value, |
| 669 | + "Total fee greater than the trigger value. Triggering RAV request" |
647 | 670 | ); |
| 671 | + state.rav_request_for_heaviest_allocation().await |
648 | 672 | } |
| 673 | + _ => Ok(()), |
| 674 | + }; |
| 675 | + // In case we fail, we want our actor to keep running |
| 676 | + if let Err(err) = rav_result { |
| 677 | + tracing::error!( |
| 678 | + error = %err, |
| 679 | + "There was an error while requesting a RAV." |
| 680 | + ); |
649 | 681 | } |
650 | 682 |
|
651 | 683 | match (state.denied, state.deny_condition_reached()) { |
|
0 commit comments