harmonize percentage members (#5459)
* harmonize percentage members * update tests * update capitalization when burning fees * verify capitalization in fee burn * fixup
This commit is contained in:
@ -21,7 +21,7 @@ pub struct FeeCalculator {
|
||||
pub min_lamports_per_signature: u64,
|
||||
pub max_lamports_per_signature: u64,
|
||||
|
||||
// What portion of collected fees are to be destroyed, percentage-wise
|
||||
// What portion of collected fees are to be destroyed, as a fraction of std::u8::MAX
|
||||
pub burn_percent: u8,
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ pub struct FeeCalculator {
|
||||
pub const DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE: u64 = 42;
|
||||
pub const DEFAULT_TARGET_SIGNATURES_PER_SLOT: usize =
|
||||
710_000 * DEFAULT_TICKS_PER_SLOT as usize / DEFAULT_NUM_TICKS_PER_SECOND as usize;
|
||||
pub const DEFAULT_BURN_PERCENT: u8 = 50;
|
||||
pub const DEFAULT_BURN_PERCENT: u8 = 127;
|
||||
|
||||
impl Default for FeeCalculator {
|
||||
fn default() -> Self {
|
||||
@ -127,9 +127,10 @@ impl FeeCalculator {
|
||||
self.lamports_per_signature * u64::from(message.header.num_required_signatures)
|
||||
}
|
||||
|
||||
/// calculate unburned fee from a fee total
|
||||
pub fn burn(&self, fees: u64) -> u64 {
|
||||
fees * u64::from(100 - self.burn_percent) / 100
|
||||
/// calculate unburned fee from a fee total, returns (unburned, burned)
|
||||
pub fn burn(&self, fees: u64) -> (u64, u64) {
|
||||
let unburned = fees * u64::from(std::u8::MAX - self.burn_percent) / u64::from(std::u8::MAX);
|
||||
(unburned, fees - unburned)
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,13 +144,13 @@ mod tests {
|
||||
fn test_fee_calculator_burn() {
|
||||
let mut fee_calculator = FeeCalculator::default();
|
||||
|
||||
assert_eq!(fee_calculator.burn(2), 1);
|
||||
assert_eq!(fee_calculator.burn(2), (1, 1));
|
||||
|
||||
fee_calculator.burn_percent = 0;
|
||||
|
||||
assert_eq!(fee_calculator.burn(2), 2);
|
||||
fee_calculator.burn_percent = 100;
|
||||
assert_eq!(fee_calculator.burn(2), 0);
|
||||
assert_eq!(fee_calculator.burn(2), (2, 0));
|
||||
fee_calculator.burn_percent = std::u8::MAX;
|
||||
assert_eq!(fee_calculator.burn(2), (0, 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Reference in New Issue
Block a user