From 4029d4fcc2a3a8b7c22ea4c8cde43cc4fcaa8cb4 Mon Sep 17 00:00:00 2001 From: FiveMovesAhead Date: Thu, 16 Jan 2025 13:54:57 +0000 Subject: [PATCH] Fix set_coinbase not exported. --- tig-protocol/src/contracts/players.rs | 14 +++++++++----- tig-protocol/src/contracts/rewards.rs | 5 +++++ tig-protocol/src/lib.rs | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tig-protocol/src/contracts/players.rs b/tig-protocol/src/contracts/players.rs index 37f5d405..487f8868 100644 --- a/tig-protocol/src/contracts/players.rs +++ b/tig-protocol/src/contracts/players.rs @@ -34,8 +34,10 @@ pub async fn set_coinbase( } } - if coinbase.values().any(|&v| v <= 0.0) { - return Err(anyhow!("Fraction cannot be zero or negative")); + if coinbase.values().any(|&v| v <= 0.0 || v > 1.0) { + return Err(anyhow!( + "Fraction must be greater than 0.0 and less than or equal to 1.0" + )); } if coinbase.values().cloned().sum::() > 1.0 { @@ -82,12 +84,14 @@ pub async fn set_delegatees( } } - if delegatees.values().any(|&v| v <= 0.0) { - return Err(anyhow!("Fraction to delegate cannot be zero or negative")); + if delegatees.values().any(|&v| v <= 0.0 || v > 1.0) { + return Err(anyhow!( + "Fraction must be greater than 0.0 and less than or equal to 1.0" + )); } if delegatees.values().cloned().sum::() > 1.0 { - return Err(anyhow!("Total fraction to delegate cannot exceed 1.0")); + return Err(anyhow!("Total fraction cannot exceed 1.0")); } for delegatee in delegatees.keys() { diff --git a/tig-protocol/src/contracts/rewards.rs b/tig-protocol/src/contracts/rewards.rs index 22e4d409..6c542774 100644 --- a/tig-protocol/src/contracts/rewards.rs +++ b/tig-protocol/src/contracts/rewards.rs @@ -149,12 +149,17 @@ pub(crate) async fn update(cache: &mut AddBlockCache) { |x| x.value.clone(), ); + if opow_data.reward == zero { + continue; + } + let shared_amount = if opow_data.delegated_weighted_deposit == zero { zero.clone() } else { opow_data.reward * PreciseNumber::from_f64(opow_data.reward_share) }; let coinbase_amount = opow_data.reward - shared_amount; + for (output, fraction) in opow_data.coinbase.iter() { let player_data = active_players_block_data.get_mut(output).unwrap(); let fraction = PreciseNumber::from_f64(*fraction); diff --git a/tig-protocol/src/lib.rs b/tig-protocol/src/lib.rs index 43ed7b72..937944da 100644 --- a/tig-protocol/src/lib.rs +++ b/tig-protocol/src/lib.rs @@ -5,7 +5,7 @@ use context::*; pub use contracts::{ algorithms::{submit_algorithm, submit_binary, submit_breakthrough}, benchmarks::{submit_benchmark, submit_fraud, submit_precommit, submit_proof}, - players::{set_delegatees, set_reward_share, set_vote}, + players::{set_coinbase, set_delegatees, set_reward_share, set_vote}, }; pub async fn add_block(ctx: &T) {