Skip to content
Snippets Groups Projects
Unverified Commit a77fdf44 authored by Wei Tang's avatar Wei Tang Committed by GitHub
Browse files

Define integer sqrt for reward quotient (#2)

parent 7173ef4d
Branches
No related merge requests found
......@@ -14,19 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use primitives::H256;
use runtime_primitives::traits::{DigestItem as DigestItemT};
use rstd::prelude::*;
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub enum Never { }
impl DigestItemT for Never {
type Hash = H256;
type AuthorityId = Never;
}
pub fn split(list: Vec<usize>, n: usize) -> Vec<Vec<usize>> {
let mut ret = Vec::new();
for i in 0..n {
......@@ -36,3 +25,13 @@ pub fn split(list: Vec<usize>, n: usize) -> Vec<Vec<usize>> {
}
ret
}
pub fn sqrt(n: u128) -> u128 {
let mut x = n;
let mut y = (x + 1) / 2;
while y < x {
x = y;
y = (x + n / x) / 2;
}
x
}
......@@ -22,6 +22,7 @@ use rstd::collections::btree_map::BTreeMap;
use state::{ActiveState, CrystallizedState, BlockVoteInfo, CrosslinkRecord};
use attestation::AttestationRecord;
use consts::{CYCLE_LENGTH, WEI_PER_ETH, BASE_REWARD_QUOTIENT, SQRT_E_DROP_TIME, SLOT_DURATION, MIN_DYNASTY_LENGTH, SHARD_COUNT};
use utils::sqrt;
use ::ShardId;
pub fn validate_block_pre_processing_conditions() { }
......@@ -169,7 +170,7 @@ pub fn calculate_ffg_rewards<BlockHashesBySlot: StorageMap<u64, H256, Query=Opti
let total_deposits = crystallized_state.total_deposits();
let total_deposits_in_eth = total_deposits / WEI_PER_ETH;
let reward_quotient = BASE_REWARD_QUOTIENT * total_deposits_in_eth / 2;
let reward_quotient = BASE_REWARD_QUOTIENT * sqrt(total_deposits_in_eth);
let quadratic_penalty_quotient = (SQRT_E_DROP_TIME / SLOT_DURATION).pow(2);
let last_state_recalc = crystallized_state.last_state_recalc;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment