mirror of
https://github.com/jwinterm/blockchain-emission-analysis.git
synced 2026-11-02 07:13:58 +01:00
clean up and fix code and add grin
This commit is contained in:
+3
-9
@@ -2,15 +2,9 @@ import blockchain
|
||||
import numpy as np
|
||||
|
||||
class Bitcoin(blockchain.Blockchain):
|
||||
def __init__(self, number_of_blocks=7e6, block_skip=10):
|
||||
super().__init__(number_of_blocks, block_skip)
|
||||
# First generate fully calculated date and reward data
|
||||
self.blocks = np.arange(0, self.number_of_blocks, self.block_skip)
|
||||
self.launch_time = 1231006505
|
||||
self.time = self.blocks*600 + self.launch_time
|
||||
self.date = np.array(self.time, dtype='datetime64[s]')
|
||||
self.reward = np.zeros(len(self.blocks))
|
||||
self.cum_reward = np.zeros(len(self.blocks))
|
||||
def __init__(self, number_of_blocks=7e6, block_skip=100, block_time=600, launch_time=1231006505):
|
||||
super().__init__(number_of_blocks, block_skip, block_time, launch_time)
|
||||
# Calculate Bitcoin emission
|
||||
for i in range(len(self.blocks)):
|
||||
self.reward[i] = ((np.uint(50e8)//2**((i*self.block_skip)//210000))*1e-8) * self.block_skip
|
||||
self.cum_reward[i] = self.cum_reward[i-1] + self.reward[i] if i > 0 else self.reward[i]
|
||||
|
||||
+34
-1
@@ -2,6 +2,39 @@ import numpy as np
|
||||
|
||||
class Blockchain:
|
||||
'''Contains time and reward information for a blockchain'''
|
||||
def __init__(self, number_of_blocks=7e6, block_skip=10):
|
||||
def __init__(self, number_of_blocks=0, block_skip=0, block_time=0, launch_time=0):
|
||||
self.number_of_blocks = int(number_of_blocks) # Number of blocks to calculate
|
||||
self.block_skip = int(block_skip) # Number of blocks to skip to save time
|
||||
self.block_time = int(block_time) # Time between blocks in seconds
|
||||
self.blocks = np.arange(0, self.number_of_blocks, self.block_skip)
|
||||
self.launch_time = int(launch_time) # Launch time of the blockchain in seconds since epoch
|
||||
self.time = self.blocks * self.block_time
|
||||
self.date = np.array(self.time + self.launch_time, dtype='datetime64[s]')
|
||||
self.reward = np.zeros(len(self.blocks))
|
||||
self.cum_reward = np.zeros(len(self.blocks))
|
||||
|
||||
def get_inflation_rate(self):
|
||||
'''Returns the inflation rate at a given block'''
|
||||
inflation_rate = np.zeros(len(self.blocks))
|
||||
for i in range(len(self.blocks)):
|
||||
year_time_cntr = 0
|
||||
year_emission_cntr = self.reward[i]
|
||||
j = 1
|
||||
while year_time_cntr < 86240*365.25:
|
||||
if i+j >= len(self.blocks):
|
||||
year_time_cntr = 1e12
|
||||
continue
|
||||
year_emission_cntr += self.reward[i+j]
|
||||
year_time_cntr += self.time[i+j] - self.time[i+j-1]
|
||||
j += 1
|
||||
inflation_rate[i] = (year_emission_cntr / self.cum_reward[i]) * 100
|
||||
return inflation_rate
|
||||
|
||||
def get_per_block_reward(self):
|
||||
'''Returns the reward per block at a given block'''
|
||||
return self.reward / self.block_skip
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+36
-19
@@ -1,33 +1,50 @@
|
||||
# Importing the required libraries
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import datetime as dt
|
||||
|
||||
# Importing the classes
|
||||
# Importing our classes
|
||||
import bitcoin
|
||||
import monero
|
||||
import wownero
|
||||
# Instance classes with specified number of blocks and block skip
|
||||
btc = bitcoin.Bitcoin(7e6, 10)
|
||||
xmr = monero.Monero(40e6, 100)
|
||||
wow = wownero.Wownero(15e6, 100)
|
||||
import grin
|
||||
|
||||
# Adjusting the date to start at the same time
|
||||
btc.time = (btc.time - btc.time[0])/60/60/24/365
|
||||
xmr.time = (xmr.time - xmr.time[0])/60/60/24/365
|
||||
wow.time = (wow.time - wow.time[0])/60/60/24/365
|
||||
# Normalizing the data by the total number of coins (or 18.132e6 for Monero)
|
||||
btc.cum_reward = btc.cum_reward / btc.cum_reward[-1]
|
||||
xmr.cum_reward = xmr.cum_reward / 18.132e6
|
||||
wow.cum_reward = wow.cum_reward / wow.cum_reward[-1]
|
||||
|
||||
# Plotting the data
|
||||
plt.plot(btc.time, btc.cum_reward, '-', color='orange', label='Bitcoin')
|
||||
plt.plot(xmr.time, xmr.cum_reward, '--', color='grey', label='Monero')
|
||||
plt.plot(wow.time, wow.cum_reward, '-.', color='pink', label='Wownero')
|
||||
# Instance classes with default blocks and block skip etc
|
||||
btc = bitcoin.Bitcoin(number_of_blocks=6.4e6, block_skip=1000, block_time=600, launch_time=1231006505)
|
||||
xmr = monero.Monero(number_of_blocks=2e7, block_skip=1000, block_time=120, launch_time=1397793600)
|
||||
wow = wownero.Wownero(number_of_blocks=1e7, block_skip=1000, block_time=300, launch_time=1521598527)
|
||||
grin = grin.Grin(number_of_blocks=6e7, block_skip=10000, block_time=60, launch_time=1547576904)
|
||||
|
||||
|
||||
# Plotting the rewards data normalized to final supply or pre-tail emission for xmr or 100 years for grin
|
||||
plt.plot(btc.time/(365.25*86400), btc.cum_reward/btc.cum_reward[-1], '-', color='orange', label='Bitcoin')
|
||||
plt.plot(xmr.time/(365.25*86400), xmr.cum_reward/18.13e6, '--', color='grey', label='Monero')
|
||||
plt.plot(wow.time/(365.25*86400), wow.cum_reward/wow.cum_reward[-1], '-.', color='pink', label='Wownero')
|
||||
plt.plot(grin.time/(365.25*86400), grin.cum_reward/(100*365.25*86400), ':', color='black', label='Grin')
|
||||
|
||||
# Adding labels, grid, legend, etc
|
||||
plt.xlabel('Time since launch (years)')
|
||||
plt.ylabel('Total coins emitted (pre-tail emission)')
|
||||
plt.ylabel('Total supply (coins)')
|
||||
plt.grid()
|
||||
plt.legend()
|
||||
|
||||
# Displaying the plot
|
||||
plt.show()
|
||||
|
||||
|
||||
# Plotting the inflation data
|
||||
print("Getting BTC inflation rate and plotting")
|
||||
plt.semilogy(btc.time/(86400*365.25), btc.get_inflation_rate() , '-', color='orange', label='Bitcoin')
|
||||
print("Getting XMR inflation rate and plotting")
|
||||
plt.semilogy(xmr.time/(86400*365.25), xmr.get_inflation_rate() , '--', color='grey', label='Monero')
|
||||
print("Getting WOW inflation rate and plotting")
|
||||
plt.semilogy(wow.time/(86400*365.25), wow.get_inflation_rate() , '-.', color='pink', label='Wownero')
|
||||
print("Getting GRIN inflation rate and plotting")
|
||||
plt.semilogy(grin.time/(86400*365.25), grin.get_inflation_rate() , ':', color='black', label='Grin')
|
||||
|
||||
# Adding labels, grid, legend, etc
|
||||
plt.xlabel('Time since launch (years)')
|
||||
plt.ylabel('Annual inflation rate (%)')
|
||||
plt.grid()
|
||||
plt.legend()
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import blockchain
|
||||
import numpy as np
|
||||
|
||||
class Grin(blockchain.Blockchain):
|
||||
def __init__(self, number_of_blocks=3e7, block_skip=100, block_time=60, launch_time=1547576904):
|
||||
super().__init__(number_of_blocks, block_skip, block_time, launch_time)
|
||||
# Calculate Grin emission
|
||||
self.block_reward = 60 # Grin block reward forever
|
||||
self.already_generated_coins = 0
|
||||
for i in range(len(self.blocks)):
|
||||
self.already_generated_coins += self.block_reward * self.block_skip
|
||||
self.reward[i] = self.block_reward * self.block_skip
|
||||
self.cum_reward[i] = self.already_generated_coins
|
||||
|
||||
@@ -2,38 +2,35 @@ import blockchain
|
||||
import numpy as np
|
||||
|
||||
class Monero(blockchain.Blockchain):
|
||||
def __init__(self, number_of_blocks=3e7, block_skip=100):
|
||||
super().__init__(number_of_blocks, block_skip)
|
||||
def __init__(self, number_of_blocks=2e7, block_skip=100, block_time=120, launch_time=1397793600):
|
||||
super().__init__(number_of_blocks, block_skip, block_time, launch_time)
|
||||
# First generate fully calculated date and reward data
|
||||
self.already_generated_coins = 0
|
||||
self.blocks = np.arange(0, self.number_of_blocks, self.block_skip)
|
||||
self.launch_time = 1397793600
|
||||
self.time = np.zeros(len(self.blocks))
|
||||
self.time[0] = self.launch_time
|
||||
self.reward = np.zeros(len(self.blocks))
|
||||
self.cum_reward = np.zeros(len(self.blocks))
|
||||
self.XMR_DIFFICULTY_TARGET_V2 = 120
|
||||
self.XMR_DIFFICULTY_TARGET_V1 = 60
|
||||
self.MONEY_SUPPLY = 2**64 - 1
|
||||
self.XMR_EMISSION_SPEED_FACTOR_PER_MINUTE = 20
|
||||
self.XMR_FINAL_SUBSIDY_PER_MINUTE = 0.3e12
|
||||
self.v2_START = 1009827
|
||||
# We have to fix the Monero time and date array because the changed difficulty target
|
||||
for i in range(len(self.blocks)):
|
||||
if self.blocks[i] < self.v2_START:
|
||||
target = self.XMR_DIFFICULTY_TARGET_V1
|
||||
target_minutes = target / 60
|
||||
emission_speed_factor = self.XMR_EMISSION_SPEED_FACTOR_PER_MINUTE - (target_minutes - 1)
|
||||
self.time[i] = self.blocks[i] * self.XMR_DIFFICULTY_TARGET_V1
|
||||
self.date[i] = np.datetime64(int(self.time[i] + self.launch_time), 's')
|
||||
else:
|
||||
target = self.XMR_DIFFICULTY_TARGET_V2
|
||||
target_minutes = target / 60
|
||||
emission_speed_factor = self.XMR_EMISSION_SPEED_FACTOR_PER_MINUTE - (target_minutes - 1)
|
||||
self.time[i] = self.time[i-1] + self.block_time * self.block_skip
|
||||
self.date[i] = np.datetime64(int(self.time[i] + self.launch_time), 's')
|
||||
# Calculate Monero emission
|
||||
self.already_generated_coins = 0
|
||||
for i in range(len(self.blocks)):
|
||||
if self.blocks[i] < self.v2_START:
|
||||
target_minutes = self.XMR_DIFFICULTY_TARGET_V1 / 60
|
||||
else:
|
||||
target_minutes = self.XMR_DIFFICULTY_TARGET_V2 / 60
|
||||
emission_speed_factor = self.XMR_EMISSION_SPEED_FACTOR_PER_MINUTE - (target_minutes - 1)
|
||||
reward = (self.MONEY_SUPPLY - int(self.already_generated_coins)) >> int(emission_speed_factor)
|
||||
if reward < self.XMR_FINAL_SUBSIDY_PER_MINUTE * target_minutes:
|
||||
reward = self.XMR_FINAL_SUBSIDY_PER_MINUTE * target_minutes
|
||||
self.already_generated_coins += reward * self.block_skip
|
||||
self.reward[i] = reward*1e-12 * self.block_skip
|
||||
self.cum_reward[i] = self.already_generated_coins*1e-12
|
||||
if i > 0:
|
||||
self.time[i] = self.time[i-1] + target_minutes*60 * self.block_skip
|
||||
self.date = np.array(self.time, dtype='datetime64[s]')
|
||||
|
||||
+5
-12
@@ -2,20 +2,15 @@ import blockchain
|
||||
import numpy as np
|
||||
|
||||
class Wownero(blockchain.Blockchain):
|
||||
def __init__(self, number_of_blocks=15e6, block_skip=100):
|
||||
super().__init__(number_of_blocks, block_skip)
|
||||
def __init__(self, number_of_blocks=15e6, block_skip=100, block_time=300, launch_time=1524223213):
|
||||
super().__init__(number_of_blocks, block_skip, block_time, launch_time)
|
||||
# First generate fully calculated date and reward data
|
||||
self.already_generated_coins = 0
|
||||
self.blocks = np.arange(0, self.number_of_blocks, self.block_skip)
|
||||
self.launch_time = 1524223213
|
||||
self.time = np.zeros(len(self.blocks))
|
||||
self.time[0] = self.launch_time
|
||||
self.reward = np.zeros(len(self.blocks))
|
||||
self.cum_reward = np.zeros(len(self.blocks))
|
||||
self.WOW_DIFFICULTY_TARGET = 300
|
||||
self.MONEY_SUPPLY = 2**64 - 1
|
||||
self.WOW_EMISSION_SPEED_FACTOR_PER_MINUTE = 24
|
||||
self.WOW_FINAL_SUBSIDY_PER_MINUTE = 0
|
||||
# Calculate Wownero emission
|
||||
self.already_generated_coins = 0
|
||||
for i in range(len(self.blocks)):
|
||||
target = self.WOW_DIFFICULTY_TARGET
|
||||
target_minutes = target / 60
|
||||
@@ -25,8 +20,6 @@ class Wownero(blockchain.Blockchain):
|
||||
reward = self.WOW_FINAL_SUBSIDY_PER_MINUTE * target_minutes
|
||||
self.already_generated_coins += reward * self.block_skip
|
||||
self.reward[i] = reward*1e-11 * self.block_skip
|
||||
self.cum_reward[i] = self.already_generated_coins*1e-12
|
||||
if i > 0:
|
||||
self.time[i] = self.time[i-1] + target_minutes*60 * self.block_skip
|
||||
self.cum_reward[i] = self.already_generated_coins*1e-11
|
||||
self.date = np.array(self.time, dtype='datetime64[s]')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user