Skip to content

Commit

Permalink
Feature: Apply scores in rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Apr 28, 2023
1 parent 7194955 commit dc57f80
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 42 deletions.
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ package_dir =
setup_requires = pyscaffold>=3.2a0,<3.3a0
# Add here dependencies of your project (semicolon/line-separated), e.g.
install_requires =
web3
web3<6.0.0
pydantic
click
aleph-client
# The usage of test_requires is discouraged, see `Dependency Management` docs
# tests_require = pytest; pytest-cov
# Require a specific Python version, e.g. Python 2.7 or >= 3.4
Expand All @@ -52,6 +53,7 @@ exclude =
testing =
pytest
pytest-cov
pytest-asyncio

[options.entry_points]
# Add here console scripts like:
Expand Down
47 changes: 41 additions & 6 deletions src/aleph_nodestatus/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
LOGGER = logging.getLogger(__name__)


def compute_score_multiplier(score: float) -> float:
"""
Compute the score multiplier
"""
if score < 0.2:
# The score is zero below 20%
return 0
elif score >= 0.8:
# The score is 1 above 80%
return 1
else:
# The score is normalized between 20% and 80%
assert 0.2 <= score <= 0.8
return (score - 0.2) / 0.6


async def create_distribution_tx_post(distribution):
print(f"Preparing pending TX post {distribution}")
post = await create_post(
Expand Down Expand Up @@ -75,7 +91,14 @@ async def prepare_distribution(start_height, end_height):
[settings.node_post_type, 'amend'],
settings.aleph_api_server,
yield_unconfirmed=False,
request_count=100000))
request_count=100000)),
prepare_items('score-update', process_message_history(
[settings.filter_tag],
[settings.scores_post_type],
message_type="POST",
addresses=settings.scores_senders,
api_server=settings.aleph_api_server,
request_count=50))
]
nodes = None
# TODO: handle decay
Expand Down Expand Up @@ -134,16 +157,28 @@ def process_distribution(nodes, resource_nodes, since, current):
rnode_reward_address = rtaddress
except Exception:
LOGGER.debug("Bad reward address, defaulting to owner")


crn_multiplier = compute_score_multiplier(rnode['score'])
crn_max_rewards = (500 + rnode['decentralization'] * 2500)

per_resource_node = crn_max_rewards * crn_multiplier

rewards[rnode_reward_address] = rewards.get(rnode_reward_address, 0) + per_resource_node

paid_node_count += 1
if crn_multiplier > 0:
paid_node_count += 1

if paid_node_count > settings.node_max_paid:
paid_node_count = settings.node_max_paid

this_node_modifier = (0.7 + (0.1*paid_node_count))


score_multiplier = compute_score_multiplier(node['score'])
assert 0 <= score_multiplier <= 1, "Invalid value of the score multiplier"

linkage = (0.7 + (0.1 * paid_node_count))
assert 0.7 <= linkage <= 1, "Invalid value of the linkage"

this_node_modifier = linkage * score_multiplier

this_node = this_node * this_node_modifier

try:
Expand Down
3 changes: 3 additions & 0 deletions src/aleph_nodestatus/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Settings(BaseSettings):
balances_platforms: List[str] = ["ALEPH_ETH_SABLIER", "ALEPH_SOL"]
balances_senders: List[str] = ["0xa1B3bb7d2332383D96b7796B908fB7f7F3c2Be10"]

scores_senders: List[str] = ["0x4D52380D3191274a04846c89c069E6C3F2Ed94e4"]
scores_post_type: str = "aleph-scoring-scores"

reward_start_height: int = 11519440
reward_nodes_daily: int = 15000
reward_stakers_daily_base: int = 15000
Expand Down
Loading

0 comments on commit dc57f80

Please sign in to comment.