-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshare_cache.py
More file actions
67 lines (54 loc) · 2.15 KB
/
share_cache.py
File metadata and controls
67 lines (54 loc) · 2.15 KB
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
64
65
66
67
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 17 16:46:43 2019
@author: jordip
"""
import time
import ConfigParser
config_data = ConfigParser.RawConfigParser()
config_data.read('chain_config.cfg')
NUM_BLOCKS_CLEAR = config_data.getint('Cache','num_blocks_clear')
BLOCK_TIME = config_data.getint('General','block_time')
class Share_Cache():
def __init__(self):
self.dkg_share_cache = []
self.bls_share_cache = []
self.bls_future_shares = {}
config_data = ConfigParser.RawConfigParser()
config_data.read('chain_config.cfg')
self.last_time_clear = time.time()
self.clearing_interval = 100000
#self.clearing_interval = NUM_BLOCKS_CLEAR * BLOCK_TIME
def in_dkg_cache(self, share):
return share.secret_share_contrib in self.dkg_share_cache
def in_bls_cache(self, share):
return share.signature in self.bls_share_cache
def store_dkg(self, share):
if time.time() > (self.last_time_clear + self.clearing_interval):
self.bls_share_cache = []
self.dkg_share_cache = []
self.last_time_clear = time.time()
self.dkg_share_cache.append(share.secret_share_contrib)
def store_bls(self, share):
if time.time() > (self.last_time_clear + self.clearing_interval):
self.bls_share_cache = []
self.dkg_share_cache = []
self.last_time_clear = time.time()
self.bls_share_cache.append(share.signature)
def store_future_bls(self, share):
try:
self.bls_future_shares[share.block_number].append(share)
except KeyError:
self.bls_future_shares[share.block_number] = []
self.bls_future_shares[share.block_number].append(share)
def pending_future_bls(self, block_num):
try:
if len(self.bls_future_shares[block_num]) > 0:
return True
else:
return False
except KeyError:
return False
def get_future_bls(self, block_num):
return self.bls_future_shares[block_num].pop()