-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminer.py
66 lines (47 loc) · 1.52 KB
/
miner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import random
class Miner():
def __init__(self, ID):
self.ID = ID
self.pool = None
self.gen_risk_preferences()
assert (self.p_join + self.p_create + self.p_dn + self.p_switch) == 1
self.compute_hash_power()
### Additional attributes to ignore for now
# Initialisation cost - computed based on (discretely) sampled hash power
# Running cost - assume fixed rate in simple model
def gen_risk_preferences(self):
risk_preferences = ["seeking", "neutral", "averse"]
pref = random.choice(risk_preferences)
if pref == "seeking":
self.p_join = 0.
self.p_create = 0.
self.p_dn = 0.95
self.p_switch = 0.05
if pref == "neutral":
self.p_join = 0.25
self.p_create = 0.2
self.p_dn = 0.5
self.p_switch = 0.05
if pref == "averse":
self.p_join = 0.5
self.p_create = 0.45
self.p_dn = 0.
self.p_switch = 0.05
def get_action(self):
r = random.uniform(0,1)
if r <= self.p_join:
return "join"
elif self.p_join < r <= self.p_join + self.p_create:
return "create"
elif self.p_join + self.p_create < r <= self.p_join + self.p_create + self.p_dn:
return "dn"
elif self.p_join + self.p_create + self.p_dn < r <= 1:
return "switch"
def compute_hash_power(self):
"""
Simple model - assume constant, homogeneous hash power
Future iterations of model - Sample a distribution that has a reasonable form
(something like an exponential decay multiplied by a step function - where
the step occurs at the computing power of the typical ASIC.
"""
self.hash_power = 1