From 3c787e005f3dc5c1502e326173d8409ad79f3b71 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Tue, 3 Sep 2024 01:04:43 -0400 Subject: [PATCH] Fix bug in the scanner regarding forwarded output amounts We'd report the amount originally received, minus 2x the cost to aggregate, regardless the amount successfully forwarded. We should've reduced to the amount successfully forwarded, if it was smaller, in case the cost to forward exceeded the aggregation cost. --- processor/scanner/src/eventuality/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/processor/scanner/src/eventuality/mod.rs b/processor/scanner/src/eventuality/mod.rs index 98d278d9..5a7b4cca 100644 --- a/processor/scanner/src/eventuality/mod.rs +++ b/processor/scanner/src/eventuality/mod.rs @@ -361,7 +361,7 @@ impl> ContinuallyRan for EventualityTas continue; }; - let Some((return_address, in_instruction)) = + let Some((return_address, mut in_instruction)) = ScannerGlobalDb::::return_address_and_in_instruction_for_forwarded_output( &txn, &forwarded, ) @@ -370,6 +370,14 @@ impl> ContinuallyRan for EventualityTas // forwarding an output continue; }; + + // We use the original amount, minus twice the cost to aggregate + // If the fees we paid to forward this now (less than the cost to aggregate now, yet not + // necessarily the cost to aggregate historically) caused this amount to be less, reduce + // it accordingly + in_instruction.balance.amount.0 = + in_instruction.balance.amount.0.min(output.balance().amount.0); + queue_output_until_block::( &mut txn, b + S::WINDOW_LENGTH,