3 class ExtranonceCounter(object):
4 '''Implementation of a counter producing
5 unique extranonce across all pool instances.
6 This is just dumb "quick&dirty" solution,
7 but it can be changed at any time without breaking anything.'''
9 def __init__(self, instance_id):
10 if instance_id < 0 or instance_id > 31:
11 raise Exception("Current ExtranonceCounter implementation needs an instance_id in <0, 31>.")
13 # Last 5 most-significant bits represents instance_id
14 # The rest is just an iterator of jobs.
15 self.counter = instance_id << 27
16 self.size = struct.calcsize('>L')
19 '''Return expected size of generated extranonce in bytes'''
22 def get_new_bin(self):
24 return struct.pack('>L', self.counter)