Skip to content

Commit 5ed631c

Browse files
committed
feat: fix update
1 parent f0dddc3 commit 5ed631c

7 files changed

+129
-34
lines changed

.sqlx/query-0393f3408c1802950e39b3ecbcfae3ac4ff99253a4973d18df83d8645ac75cfc.json renamed to .sqlx/query-1074d80ad47f7de09260596f3626dc7cb0072ed9e1f55a56d687a97c196ae5db.json

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-2441d414d03f37f4454c633a95fbf9820e318909116757c2f9aecba629c9bdad.json

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-e803de8899de4d54bb7c40be0459fa53d0cd2798d219947cc6fc8b5b98362794.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tap-agent/src/agent/sender_account.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ impl Actor for SenderAccount {
520520
SenderAccountMessage::UpdateRav(rav) => {
521521
state
522522
.rav_tracker
523-
.update(rav.message.allocationId, rav.message.valueAggregate);
523+
.update(rav.message.allocationId, rav.message.valueAggregate, 0);
524524

525525
PENDING_RAV
526526
.with_label_values(&[
@@ -541,7 +541,7 @@ impl Actor for SenderAccount {
541541

542542
state
543543
.invalid_receipts_tracker
544-
.update(allocation_id, unaggregated_fees.value);
544+
.update(allocation_id, unaggregated_fees.value, 0);
545545

546546
// invalid receipts can't go down
547547
let should_deny = !state.denied && state.deny_condition_reached();
@@ -586,7 +586,7 @@ impl Actor for SenderAccount {
586586

587587
let rav_value = rav.map_or(0, |rav| rav.message.valueAggregate);
588588
// update rav tracker
589-
state.rav_tracker.update(allocation_id, rav_value);
589+
state.rav_tracker.update(allocation_id, rav_value, 0);
590590
PENDING_RAV
591591
.with_label_values(&[
592592
&state.sender.to_string(),
@@ -595,7 +595,11 @@ impl Actor for SenderAccount {
595595
.set(rav_value as f64);
596596

597597
// update sender fee tracker
598-
state.sender_fee_tracker.update(allocation_id, fees.value);
598+
state.sender_fee_tracker.update(
599+
allocation_id,
600+
fees.value,
601+
fees.counter,
602+
);
599603
UNAGGREGATED_FEES
600604
.with_label_values(&[
601605
&state.sender.to_string(),
@@ -615,9 +619,11 @@ impl Actor for SenderAccount {
615619
};
616620
}
617621
ReceiptFees::UpdateValue(unaggregated_fees) => {
618-
state
619-
.sender_fee_tracker
620-
.update(allocation_id, unaggregated_fees.value);
622+
state.sender_fee_tracker.update(
623+
allocation_id,
624+
unaggregated_fees.value,
625+
unaggregated_fees.counter,
626+
);
621627

622628
UNAGGREGATED_FEES
623629
.with_label_values(&[
@@ -768,7 +774,7 @@ impl Actor for SenderAccount {
768774
for allocation_id in tracked_allocation_ids.difference(&active_allocation_ids) {
769775
// if it's being tracked and we didn't receive any update from the non_final_last_ravs
770776
// remove from the tracker
771-
state.rav_tracker.update(*allocation_id, 0);
777+
state.rav_tracker.update(*allocation_id, 0, 0);
772778

773779
let _ = PENDING_RAV.remove_label_values(&[
774780
&state.sender.to_string(),
@@ -777,7 +783,7 @@ impl Actor for SenderAccount {
777783
}
778784

779785
for (allocation_id, value) in non_final_last_ravs {
780-
state.rav_tracker.update(allocation_id, value);
786+
state.rav_tracker.update(allocation_id, value, 0);
781787
PENDING_RAV
782788
.with_label_values(&[&state.sender.to_string(), &allocation_id.to_string()])
783789
.set(value as f64);
@@ -1250,6 +1256,7 @@ pub mod tests {
12501256
UnaggregatedReceipts {
12511257
value: *self.next_unaggregated_fees_value.lock().unwrap(),
12521258
last_id: 0,
1259+
counter: 0,
12531260
},
12541261
Some(signed_rav),
12551262
))),
@@ -1608,6 +1615,7 @@ pub mod tests {
16081615
ReceiptFees::UpdateValue(UnaggregatedReceipts {
16091616
value: $value,
16101617
last_id: 11,
1618+
counter: 0,
16111619
}),
16121620
))
16131621
.unwrap();
@@ -1624,6 +1632,7 @@ pub mod tests {
16241632
UnaggregatedReceipts {
16251633
value: $value,
16261634
last_id: 11,
1635+
counter: 0,
16271636
},
16281637
))
16291638
.unwrap();
@@ -1751,6 +1760,7 @@ pub mod tests {
17511760
ReceiptFees::UpdateValue(UnaggregatedReceipts {
17521761
value: $value,
17531762
last_id: 11,
1763+
counter: 0,
17541764
}),
17551765
))
17561766
.unwrap();

tap-agent/src/agent/sender_allocation.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ impl Actor for SenderAllocation {
249249
);
250250
u128::MAX
251251
});
252+
unaggregated_fees.counter += 1;
252253
// it's fine to crash the actor, could not send a message to its parent
253254
state
254255
.sender_account_ref
@@ -364,7 +365,8 @@ impl SenderAllocationState {
364365
r#"
365366
SELECT
366367
MAX(id),
367-
SUM(value)
368+
SUM(value),
369+
COUNT(*)
368370
FROM
369371
scalar_tap_receipts
370372
WHERE
@@ -398,6 +400,7 @@ impl SenderAllocationState {
398400
.unwrap_or(BigDecimal::from(0))
399401
.to_string()
400402
.parse::<u128>()?,
403+
counter: res.count.unwrap_or(0).to_string().parse::<usize>()?,
401404
})
402405
}
403406

@@ -410,7 +413,8 @@ impl SenderAllocationState {
410413
r#"
411414
SELECT
412415
MAX(id),
413-
SUM(value)
416+
SUM(value),
417+
COUNT(*)
414418
FROM
415419
scalar_tap_receipts_invalid
416420
WHERE
@@ -435,6 +439,7 @@ impl SenderAllocationState {
435439
.unwrap_or(BigDecimal::from(0))
436440
.to_string()
437441
.parse::<u128>()?,
442+
counter: res.count.unwrap_or(0).to_string().parse::<usize>()?,
438443
})
439444
}
440445

@@ -1005,6 +1010,7 @@ pub mod tests {
10051010
ReceiptFees::UpdateValue(UnaggregatedReceipts {
10061011
last_id: 10,
10071012
value: 55u128,
1013+
counter: 10,
10081014
}),
10091015
);
10101016
let last_message_emitted = last_message_emitted.recv().await.unwrap();
@@ -1047,6 +1053,7 @@ pub mod tests {
10471053
UnaggregatedReceipts {
10481054
last_id: 10,
10491055
value: 55u128,
1056+
counter: 10,
10501057
},
10511058
);
10521059
let update_invalid_msg = message_receiver.recv().await.unwrap();
@@ -1116,7 +1123,8 @@ pub mod tests {
11161123
*ALLOCATION_ID_0,
11171124
ReceiptFees::UpdateValue(UnaggregatedReceipts {
11181125
value: 0,
1119-
last_id: 0
1126+
last_id: 0,
1127+
counter: 0,
11201128
})
11211129
)
11221130
);
@@ -1202,7 +1210,8 @@ pub mod tests {
12021210
*ALLOCATION_ID_0,
12031211
ReceiptFees::UpdateValue(UnaggregatedReceipts {
12041212
value: 90,
1205-
last_id: 20
1213+
last_id: 20,
1214+
counter: 20,
12061215
})
12071216
)
12081217
);
@@ -1213,6 +1222,7 @@ pub mod tests {
12131222
UnaggregatedReceipts {
12141223
last_id: 0,
12151224
value: 45u128,
1225+
counter: 0,
12161226
},
12171227
);
12181228
assert_eq!(message_receiver.recv().await.unwrap(), expected_message);
@@ -1542,7 +1552,8 @@ pub mod tests {
15421552
*ALLOCATION_ID_0,
15431553
ReceiptFees::UpdateValue(UnaggregatedReceipts {
15441554
value: 45,
1545-
last_id: 10
1555+
last_id: 10,
1556+
counter: 10,
15461557
})
15471558
)
15481559
);
@@ -1641,7 +1652,8 @@ pub mod tests {
16411652
*ALLOCATION_ID_0,
16421653
ReceiptFees::UpdateValue(UnaggregatedReceipts {
16431654
value: 16220184412847561580,
1644-
last_id: 10
1655+
last_id: 10,
1656+
counter: 10,
16451657
})
16461658
)
16471659
);
@@ -1654,7 +1666,8 @@ pub mod tests {
16541666
*ALLOCATION_ID_0,
16551667
UnaggregatedReceipts {
16561668
value: TOTAL_SUM,
1657-
last_id: 0
1669+
last_id: 0,
1670+
counter: 0,
16581671
}
16591672
)
16601673
);

0 commit comments

Comments
 (0)