Skip to content

Commit

Permalink
Impose a delegation minimum (offset floating point errors)
Browse files Browse the repository at this point in the history
  • Loading branch information
LadyChristina committed Nov 19, 2021
1 parent be28c94 commit 7f8f9f3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions logic/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

TOTAL_EPOCH_REWARDS_R = 1
MAX_NUM_POOLS = 1000
MIN_STAKE_UNIT = 2.2e-17


def generate_stake_distr(num_agents, total_stake=1, pareto_param=None, seed=156):
Expand Down
3 changes: 2 additions & 1 deletion logic/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@author: chris
"""
import logic.helper as hlp
from logic.helper import MIN_STAKE_UNIT


class Pool:
Expand All @@ -30,7 +31,7 @@ def update_delegation(self, stake, delegator_id):
self.delegators[delegator_id] += stake
else:
self.delegators[delegator_id] = stake
if self.delegators[delegator_id] <= 0:
if self.delegators[delegator_id] <= MIN_STAKE_UNIT:
self.delegators.pop(delegator_id)

# todo shouldn't a pool's desirability decrease in the case that it gets oversaturated??
Expand Down
4 changes: 2 additions & 2 deletions logic/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ def __init__(
"MeanAbsDiff": get_controlled_stake_mean_abs_diff,
"StatisticalDistance": get_controlled_stake_distr_stat_dist,
"NakamotoCoefficient": get_nakamoto_coefficient,
"NCR": get_NCR,
# "NCR": get_NCR,
# "MinAggregatePledge": get_min_aggregate_pledge,
"PledgeRate": get_pledge_rate,
# "PledgeRate": get_pledge_rate,
"AreaCoverage": get_homogeneity_factor,
"MarginChanges": get_margin_changes,
"AvgMargin": get_avg_margin,
Expand Down
7 changes: 4 additions & 3 deletions logic/stakeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from logic.strategy import Strategy
from logic.strategy import STARTING_MARGIN
from logic.strategy import MARGIN_INCREMENT
from logic.helper import MIN_STAKE_UNIT
from logic.custom_exceptions import PoolNotFoundError, NonPositiveAllocationError


Expand Down Expand Up @@ -487,10 +488,10 @@ def find_delegation_move_desirability(self, stake_to_delegate=None):
# the first non-saturated pool(s).
pool_ranking = hlp.calculate_ranks(desirability_dict, pp_dict, stake_dict, rank_ids=True)
allow_oversaturation = False
while stake_to_delegate > 0:
while stake_to_delegate >= MIN_STAKE_UNIT:
for pool_id, rank in sorted(pool_ranking.items(), key=operator.itemgetter(1)):
if stake_dict[pool_id] < saturation_point or allow_oversaturation:
stake_to_saturation = saturation_point - stake_dict[pool_id]
stake_to_saturation = saturation_point - stake_dict[pool_id]
if stake_to_saturation >= MIN_STAKE_UNIT or allow_oversaturation:
allocation = stake_to_delegate if allow_oversaturation else min(stake_to_delegate,
stake_to_saturation)
stake_to_delegate -= allocation
Expand Down

0 comments on commit 7f8f9f3

Please sign in to comment.