Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving NPR App #1083

Merged
merged 16 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions rs/dre-canisters/node-provider-rewards-lib/src/v1_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,35 @@ pub enum LogEntry {
coeff: Decimal,
base_rewards: Decimal,
},
AvgType3Rewards(String, Decimal),
AvgType3Rewards {
region: String,
rewards_avg: Decimal,
coefficients_avg: Decimal,
region_rewards_avg: Decimal,
},
UnassignedMultiplier(Decimal),
}

impl fmt::Display for LogEntry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
LogEntry::Execute { reason, operation, result } => {
write!(f, "ExecuteOperation | reason={}, operation={}, result={}", reason, operation, result)
}
LogEntry::RewardsForNodeProvider(principal, node_count) => {
write!(
f,
"RewardsForNodeProvider | node_provider_principal: {} rewardable nodes in period: {}",
principal, node_count
"ExecuteOperation | reason={}, operation={}, result={}",
reason,
operation,
result.round_dp(2)
)
}
LogEntry::RewardsForNodeProvider(principal, node_count) => {
write!(f, "Node Provider: {} rewardable nodes in period: {}", principal, node_count)
}
LogEntry::RewardMultiplierForNode(principal, multiplier) => {
write!(f, "Rewards Multiplier for node: {} is {}", principal, multiplier)
write!(f, "Rewards Multiplier for node: {} is {}", principal, multiplier.round_dp(2))
}
LogEntry::RewardsXDRTotal(rewards_xdr_total) => {
write!(f, "Total rewards XDR permyriad: {}", rewards_xdr_total)
write!(f, "Total rewards XDR permyriad: {}", rewards_xdr_total.round_dp(2))
}
LogEntry::RateNotFoundInRewardTable { node_type, region } => {
write!(f, "RateNotFoundInRewardTable | node_type={}, region={}", node_type, region)
Expand All @@ -127,11 +135,27 @@ impl fmt::Display for LogEntry {
write!(
f,
"Region {} with type: {} | Rewardable Nodes: {} Assigned Multipliers: {:?} Unassigned Multipliers: {:?}",
region, node_type, count, assigned_multiplier, unassigned_multiplier
region,
node_type,
count,
assigned_multiplier.iter().map(|dec| dec.round_dp(2)),
unassigned_multiplier.iter().map(|dec| dec.round_dp(2))
)
}
LogEntry::AvgType3Rewards {
region,
rewards_avg,
coefficients_avg,
region_rewards_avg,
} => {
write!(
f,
"Avg. rewards for nodes with type: type3* in region: {} is {}\nRegion rewards average: {}\nReduction coefficient average:{}",
region, rewards_avg, region_rewards_avg, coefficients_avg
)
}
LogEntry::AvgType3Rewards(region, avg_rewards) => {
write!(f, "Avg. rewards for nodes with type: type3* in region: {} is {}", region, avg_rewards)
LogEntry::UnassignedMultiplier(unassigned_multiplier) => {
write!(f, "Unassigned Nodes Multiplier: {}", unassigned_multiplier.round_dp(2))
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions rs/dre-canisters/node-provider-rewards-lib/src/v1_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ fn base_rewards_region_nodetype(
}

// Computes node rewards for type3* nodes in all regions and add it to region_nodetype_rewards
for (region_key, (coefficients, rewards)) in type3_coefficients_rewards {
for (key, (coefficients, rewards)) in type3_coefficients_rewards {
let rewards_len = rewards.len();
let mut running_coefficient = dec!(1);
let mut region_rewards = Vec::new();
Expand All @@ -211,9 +211,15 @@ fn base_rewards_region_nodetype(
Operation::Divide(region_rewards, Decimal::from(rewards_len)),
);

logger().add_entry(LogEntry::AvgType3Rewards(region_key.0.clone(), region_rewards_avg));
logger().add_entry(LogEntry::AvgType3Rewards{
region: key.0.clone(),
rewards_avg,
coefficients_avg,
region_rewards_avg
}
);

region_nodetype_rewards.insert(region_key, region_rewards_avg);
region_nodetype_rewards.insert(key, region_rewards_avg);
}

region_nodetype_rewards
Expand All @@ -231,6 +237,7 @@ fn node_provider_rewards(
// Computes the rewards multiplier for unassigned nodes as the average of the multipliers of the assigned nodes.
let assigned_multipliers_v = assigned_multipliers.values().flatten().cloned().collect_vec();
let unassigned_multiplier = logger().execute("Unassigned Nodes Multiplier", Operation::Avg(assigned_multipliers_v));
logger().add_entry(LogEntry::UnassignedMultiplier(unassigned_multiplier));

// Compute total rewards with/without performance penalty
for ((region, node_type), node_count) in rewardable_nodes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const NodeRewardsChart: React.FC<NodeRewardsChartProps> = ({ node }) => {
</Grid>
<Grid item xs={12} md={6}>
<NodePerformanceStats
rewardMultiplier={rewardsMultiplier.toString().concat("%")}
rewardMultiplier={latestNodeRewards.daily_node_metrics.length > 0 ? rewardsMultiplier.toString().concat("%") : "Unassigned"}
baseRewardsXDR={(Number(latestNodeRewards.node_rate.xdr_permyriad_per_node_per_month) / 10000).toString()} />
</Grid>
<Grid item xs={12} md={6}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const NodeProvidersRewardExplanation = () => {
</Grid>
<Grid item xs={12} md={6}>
<Typography variant="body2" gutterBottom>
Nodes not registered:
Nodes Unregistered:
</Typography>
<Typography variant="body2" color="textSecondary" gutterBottom>
Nodes which are not registered in the period get no rewards (0%).
Expand All @@ -135,6 +135,15 @@ export const NodeProvidersRewardExplanation = () => {
</Typography>
</Grid>
<Grid item xs={12} md={6}>
<Typography variant="body2" gutterBottom>
No Node Assigned:
</Typography>
<Typography variant="body2" color="textSecondary" gutterBottom>
- For Node Provider with less than 4 nodes no penalty is applied
</Typography>
<Typography variant="body2" color="textSecondary" gutterBottom>
- For Node Provider with more than 4 nodes 80% penalty is applied
</Typography>
<Typography variant="body2" gutterBottom>
Final Node Provider rewards:
</Typography>
Expand Down
Loading