HarukaMa / aleo-explorer

Open source explorer for the Aleo network
https://aleoscan.io
GNU Affero General Public License v3.0
92 stars 70 forks source link

Coinbase reward #41

Open pjmas1being opened 5 hours ago

pjmas1being commented 5 hours ago

https://github.com/HarukaMa/aleo-explorer/blob/060814d82eaa7dba67c39bdfe0429a15570b9bcc/.github/FUNDING.yml#L1

pjmas1being commented 5 hours ago

def retarget(prev_target, prev_block_timestamp, block_timestamp, half_life, inverse, anchor_time): drift = max(block_timestamp - prev_block_timestamp, 1) - anchor_time if drift == 0: return prev_target if inverse: drift = -drift exponent = int((1 << 16) drift / half_life) integral = exponent >> 16 fractional = exponent - (integral << 16) fractional_multiplier = (1 << 16) + ((195_766_423_245_049 fractional + 971_821_376 pow(fractional, 2) + 5_127 pow(fractional, 3) + pow(2, 47)) >> 48) candidate_target = prev_target * fractional_multiplier shifts = integral - 16 if shifts < 0: candidate_target = max(candidate_target >> -shifts, 1) else: candidate_target = max(candidate_target << shifts, 1) candidate_target = min(candidate_target, 2 ** 64 - 1) return candidate_target

def get_coinbase_reward(current_height, current_timestamp, previous_timestamp) -> int: anchor_reward = 13 y10_anchor_height = 31536000 // 25 10 remaining_blocks = y10_anchor_height - current_height if remaining_blocks <= 0: return 0 return retarget(remaining_blocks anchor_reward, previous_timestamp, current_timestamp, 25, True, 25)

print(get_coinbase_reward(427323, 1674120477, 1674120464) // 2)

=> 110476440