Skip to content

Commit

Permalink
ARC42
Browse files Browse the repository at this point in the history
  • Loading branch information
HarukaMa committed Nov 15, 2024
1 parent e09c728 commit a2be540
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
40 changes: 39 additions & 1 deletion aleo_types/vm_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -3772,7 +3772,14 @@ def load(cls, data: BytesIO):
def __str__(self):
return f"Block {self.header.metadata.height} ({str(self.block_hash)[:16]}...)"

def compute_rewards(self, last_coinbase_target: int, last_cumulative_proof_target: int) -> tuple[int, int]:
def compute_rewards(self, time_since_last_block: int, last_coinbase_target: int, last_cumulative_proof_target: int) -> tuple[int, int]:
from node import Network
if self.height < Network.consensus_v2_height:
return self.compute_rewards_v1(last_coinbase_target, last_cumulative_proof_target)
return self.compute_rewards_v2(time_since_last_block, last_coinbase_target, last_cumulative_proof_target)


def compute_rewards_v1(self, last_coinbase_target: int, last_cumulative_proof_target: int) -> tuple[int, int]:
starting_supply = 1_500_000_000_000_000
anchor_time = 25
block_time = 10
Expand All @@ -3796,6 +3803,37 @@ def compute_rewards(self, last_coinbase_target: int, last_cumulative_proof_targe

return block_reward, int(coinbase_reward)

def compute_rewards_v2(self, time_since_last_block: int, last_coinbase_target: int, last_cumulative_proof_target: int) -> tuple[int, int]:
starting_supply = 1_500_000_000_000_000
anchor_time = 25
block_time = 10
anchor_height = anchor_time // block_time
if self.solutions.value is None:
combined_proof_target = 0
else:
combined_proof_target = sum(s.target for s in self.solutions.value.solutions)

remaining_coinbase_target = max(0, last_coinbase_target - last_cumulative_proof_target)
remaining_proof_target = min(combined_proof_target, remaining_coinbase_target)

from node import Network
genesis_timestamp = Network.genesis_block.header.metadata.timestamp
block_timestamp = self.header.metadata.timestamp

number_of_seconds_in_10_years = 31536000 * 10
timestamp_at_year_10 = genesis_timestamp + number_of_seconds_in_10_years
timestamp_at_year_9 = timestamp_at_year_10 - 31536000

num_remaining_seconds_to_year_10 = timestamp_at_year_10 - min(block_timestamp, timestamp_at_year_9)

anchor_block_reward = 2 * starting_supply * anchor_height * num_remaining_seconds_to_year_10 // (number_of_seconds_in_10_years * (number_of_seconds_in_10_years + 1))
coinbase_reward = anchor_block_reward * remaining_proof_target // last_coinbase_target

annual_reward = starting_supply // 20
block_reward = annual_reward * min(time_since_last_block, 60) // 31536000 + coinbase_reward // 3 + self.transactions.total_priority_fee

return block_reward, int(coinbase_reward)

def get_epoch_number(self) -> int:
return self.header.metadata.height // 360

Expand Down
4 changes: 4 additions & 0 deletions db/insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,11 @@ async def _save_block(self, block: Block):

try:
if block.height != 0:
from db import Database
last_block_timestamp = await cast(Database, self).get_latest_block_timestamp()
time_since_last_block = block.header.metadata.timestamp - last_block_timestamp
block_reward, coinbase_reward = block.compute_rewards(
time_since_last_block,
await cast("Database", self).get_latest_coinbase_target(),
await cast("Database", self).get_latest_cumulative_proof_target()
)
Expand Down
4 changes: 3 additions & 1 deletion node/canary/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ class Canary:

ans_registry = "aleo_name_service_registry_v3.aleo"

restrictions_id = Field(7562506206353711030068167991213732850758501012603348777370400520506564970105)
restrictions_id = Field(7562506206353711030068167991213732850758501012603348777370400520506564970105)

consensus_v2_height = 2900000
4 changes: 3 additions & 1 deletion node/mainnet/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ class Mainnet:

ans_registry = "aleo_name_service_registry.aleo"

restrictions_id = Field(7562506206353711030068167991213732850758501012603348777370400520506564970105)
restrictions_id = Field(7562506206353711030068167991213732850758501012603348777370400520506564970105)

consensus_v2_height = 2950000
4 changes: 3 additions & 1 deletion node/testnet/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ class Testnet:

ans_registry = "aleo_name_service_registry_v2.aleo"

restrictions_id = Field(7562506206353711030068167991213732850758501012603348777370400520506564970105)
restrictions_id = Field(7562506206353711030068167991213732850758501012603348777370400520506564970105)

consensus_v2_height = 2800000

0 comments on commit a2be540

Please sign in to comment.