Skip to content

Commit

Permalink
[protected event dist] fixing issue on bps commission f64 calculation (
Browse files Browse the repository at this point in the history
…#86)

* [protected event dist] fixing issue on bps commission f64 calculation

* use bps function for f64
  • Loading branch information
ochaloup authored Aug 13, 2024
1 parent 064253a commit 4dc8365
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
1 change: 1 addition & 0 deletions .buildkite/prepare-protected-events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ steps:

- label: ":scales: Evaluate Marinade Protected Events"
env:
RUST_LOG: info,protected_event_distribution=debug
WHITELIST_STAKE_AUTHORITY: stWirqFCf2Uts1JBL1Jsd3r6VBWhgnpdPxCTe1MFjrq,4bZ6o3eUUNXhKuqjdCnCoPAoLgWiuLYixKaxoa8PpiKk,ex9CfkBZZd6Nv9XdnoDmmB45ymbu4arXVk7g5pWnt3N
commands:
- 'buildkite-agent artifact download --include-retried-jobs validators.json .'
Expand Down
12 changes: 7 additions & 5 deletions protected-event-distribution/src/protected_events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::revenue_expectation_meta::{RevenueExpectationMeta, RevenueExpectationMetaCollection};
use crate::utils::bps_f64;

use {
crate::utils::{bps, bps_to_fraction},
log::{debug, info},
Expand Down Expand Up @@ -107,7 +109,7 @@ pub fn collect_commission_increase_events(
if let Some(revenue_expectation) = revenue_expectation {
if revenue_expectation.actual_non_bid_pmpe < revenue_expectation.expected_non_bid_pmpe {
debug!(
"Validator {vote_account} commission increase. Expected non bid PMPE: {}, actual non bid PMPE: {}",
"Validator {vote_account} increased commission, expected non bid PMPE: {}, actual non bid PMPE: {}",
revenue_expectation.expected_non_bid_pmpe,
revenue_expectation.actual_non_bid_pmpe
);
Expand All @@ -120,12 +122,12 @@ pub fn collect_commission_increase_events(
expected_mev_commission: revenue_expectation.expected_mev_commission,
actual_mev_commission: revenue_expectation.actual_mev_commission,
// expected_non_bid_pmpe is what how many SOLs was expected to gain per 1000 of staked SOLs
// expected_epr is how many lamports per 1 staked lamport was expected to be paid by validator
// expected_epr is ratio of how many SOLS to pay for 1 staked SOL (it does not matter if in loampors or SOLs when ratio)
expected_epr: revenue_expectation.expected_non_bid_pmpe / 1000.0,
actual_epr: revenue_expectation.actual_non_bid_pmpe / 1000.0,
epr_loss_bps: bps(
(revenue_expectation.expected_non_bid_pmpe - revenue_expectation.actual_non_bid_pmpe).round() as u64,
revenue_expectation.expected_non_bid_pmpe.round() as u64
epr_loss_bps: bps_f64(
revenue_expectation.expected_non_bid_pmpe - revenue_expectation.actual_non_bid_pmpe,
revenue_expectation.expected_non_bid_pmpe
),
stake,
},
Expand Down
9 changes: 8 additions & 1 deletion protected-event-distribution/src/settlement_claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
settlement_config::{build_protected_event_matcher, SettlementConfig},
stake_meta_index::StakeMetaIndex,
};
use log::info;
use log::{debug, info};
use solana_sdk::pubkey::Pubkey;

use {
Expand Down Expand Up @@ -129,6 +129,13 @@ pub fn generate_settlements(
claims_amount,
claims,
});
} else {
debug!(
"Skipping protected-event Settlement for vote account {} as claim amount {} is less than min settlement lamports {}",
protected_event.vote_account(),
claims_amount,
settlement_config.min_settlement_lamports()
);
}
}
}
Expand Down
29 changes: 27 additions & 2 deletions protected-event-distribution/src/settlement_config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{protected_events::ProtectedEvent, settlement_claims::SettlementMeta};
use log::debug;
use serde::{Deserialize, Serialize};
use solana_sdk::pubkey::Pubkey;
use std::collections::HashSet;
Expand Down Expand Up @@ -65,13 +66,37 @@ pub fn build_protected_event_matcher(
grace_downtime_bps, ..
},
ProtectedEvent::DowntimeRevenueImpact { epr_loss_bps, .. },
) => *epr_loss_bps > grace_downtime_bps.unwrap_or_default(),
) => {
if *epr_loss_bps > grace_downtime_bps.unwrap_or_default() {
true
} else {
debug!(
"DowntimeRevenueImpact event vote account {} with epr_loss_bps: {} is under grace period: {}",
protected_event.vote_account(),
epr_loss_bps,
grace_downtime_bps.unwrap_or_default()
);
false
}
}
(
SettlementConfig::CommissionIncreaseSettlement {
grace_increase_bps, ..
},
ProtectedEvent::CommissionIncrease { epr_loss_bps, .. },
) => *epr_loss_bps > grace_increase_bps.unwrap_or_default(),
) => {
if *epr_loss_bps > grace_increase_bps.unwrap_or_default() {
true
} else {
debug!(
"CommissionIncrease event vote account {} with epr_loss_bps: {} is under grace period: {}",
protected_event.vote_account(),
epr_loss_bps,
grace_increase_bps.unwrap_or_default()
);
false
}
}
_ => false,
},
)
Expand Down
8 changes: 8 additions & 0 deletions protected-event-distribution/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ pub fn bps(value: u64, max: u64) -> u64 {
10000 * value / max
}

pub fn bps_f64(value: f64, max: f64) -> u64 {
assert!(
max > 0.0,
"Cannot calculute bps from values: {value}, {max}"
);
(10000.0 * value / max).round() as u64
}

pub fn bps_to_fraction(value: u64) -> f64 {
value as f64 / 10000.0
}
Expand Down

0 comments on commit 4dc8365

Please sign in to comment.