Skip to content

Commit

Permalink
Handle RESERVE_FEE differently with identical spend aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Feb 26, 2025
1 parent 38d4f84 commit 88f08f5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions crates/chia-consensus/src/gen/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,8 @@ pub fn parse_spends<V: SpendVisitor>(
validate_signature(&state, aggregate_signature, flags, bls_cache)?;
ret.validated_signature = (flags & DONT_VALIDATE_SIGNATURE) == 0;

check_deduplication(&mut ret);

ret.cost = max_cost - cost_left;
Ok(ret)
}
Expand Down Expand Up @@ -1540,6 +1542,33 @@ pub fn validate_signature(
Ok(())
}

pub fn check_deduplication(ret: &mut SpendBundleConditions) {
let mut non_dedup_removal_amount = 0;
let mut non_dedup_addition_amount = 0;

for spend in &ret.spends {
if (spend.flags & ELIGIBLE_FOR_DEDUP) == 0 {
continue;
}

non_dedup_removal_amount += spend.coin_amount;
non_dedup_addition_amount += spend
.create_coin
.iter()
.fold(0, |acc, coin| acc + coin.amount);
}

let non_dedup_fees = non_dedup_addition_amount - non_dedup_removal_amount;

if non_dedup_fees >= ret.reserve_fee {
return;
}

ret.spends.iter_mut().for_each(|spend| {
spend.flags &= !ELIGIBLE_FOR_DEDUP;
});
}

#[cfg(test)]
use crate::consensus_constants::TEST_CONSTANTS;
#[cfg(test)]
Expand Down

0 comments on commit 88f08f5

Please sign in to comment.