def __init__(self, pos, network): # Map from height to {node_id: latest_bet} self.received_signatures = [] # List of received blocks self.received_blocks = [] # Own probability estimates self.probs = [] # All objects that this validator has received; basically a database self.received_objects = {} # Time when the object was received self.time_received = {} # The validator's ID, and its position in the queue self.pos = self.id = pos # The offset of this validator's clock vs. real time self.time_offset = normal_distribution(0, 100)() # The highest height that this validator has seen self.max_height = 0 # The validator's hash chain self.finalized_hashes = [] # Finalized states self.finalized_states = [] # The highest height that the validator has finalized self.max_finalized_height = -1 # The network object self.network = network # Last time signed self.last_time_signed = 0 # Next height to mine self.next_height = self.pos
def independenceTest(self, num_random_list, alpha): sign = [] Xn = num_random_list[0] for i in range(1, len(num_random_list)): if num_random_list[i] < Xn: sign.append("-") else: if num_random_list[i] > Xn: sign.append("+") else: sign.append(sign[i - 1]) Xn = num_random_list[i] h = 0 for i in range(1, len(sign)): if sign[i] != sign[i - 1]: h += 1 e = (2 * len(num_random_list) - 1) / float(3) v = (16 * len(num_random_list) - 29) / float(90) Zc = (h - e) / math.sqrt(v) return Zc > distributions.normal_distribution(alpha / 2)
def __init__(self): self.agents = [] self.latency_distribution_sample = transform(normal_distribution(50, 20), lambda x: max(x, 0)) self.time = 0 self.objqueue = {} self.peers = {} self.reliability = 0.9
def change_input_data(switch, par_size=10, par_scale=5): if switch == 'normal': data = distributions.normal_distribution(par_size, par_scale) max_dim = len(data) if switch == 'logistic': data = distributions.logistic_distribution(par_size, par_scale) max_dim = len(data) if switch == "daily-test": df = pd.read_csv("daily-min-temperatures-01.csv", names=['Date', 'MinTemp']) data = df.to_numpy() max_dim = sum( 1 for my_line in open("daily-min-temperatures-01.csv", 'r')) if switch == "daily-10": df = pd.read_csv("daily-min-temperatures-02.csv", names=['Date', 'MinTemp']) data = df.to_numpy() max_dim = sum( 1 for my_line in open("daily-min-temperatures-02.csv", 'r')) if switch == "daily-30": df = pd.read_csv("daily-min-temperatures-03.csv", names=['Date', 'MinTemp']) data = df.to_numpy() max_dim = sum( 1 for my_line in open("daily-min-temperatures-03.csv", 'r')) # max_dim = len(data_list) return data, max_dim
def __init__(self, pos, network): # Map from height to {node_id: latest_bet} self.received_signatures = [] # List of received blocks self.received_blocks = [] # Own probability estimates self.probs = [] # All objects that this validator has received; basically a database self.received_objects = {} # Time when the object was received self.time_received = {} # The validator's ID, and its position in the queue self.pos = self.id = pos # The offset of this validator's clock vs. real time self.time_offset = normal_distribution(0, CLOCK_DISPARITY)() # The highest height that this validator has seen self.max_height = 0 # The validator's hash chain self.finalized_hashes = [] # Finalized states self.states = [] # The highest height that the validator has finalized self.max_finalized_height = -1 # The network object self.network = network # Last time signed self.last_time_signed = 0 # Next height to mine self.next_height = self.pos # Own most recent signature self.most_recent_sig = None # Most recent signatures of other self.most_recent_sigs = {}
def __init__(self): self.agents = [] self.latency_distribution_sample = transform(normal_distribution(50, 20), lambda x: max(x, 0)) self.time = 0 self.objqueue = {} self.peers = {} self.reliability = 0.9
def independenceTest(self, num_random_list, alpha): sign = [] Xn = num_random_list[0] for i in range(1, len(num_random_list)): if num_random_list[i] < Xn: sign.append("-") else: if num_random_list[i] > Xn: sign.append("+") else: sign.append(sign[i - 1]) Xn = num_random_list[i] h = 0 for i in range(1, len(sign)): if sign[i] != sign[i - 1]: h += 1 e = (2 * len(num_random_list) - 1) / float(3) v = (16 * len(num_random_list) - 29) / float(90) Zc = (h - e) / math.sqrt(v) return Zc > distributions.normal_distribution(alpha / 2)
def midTest(self, num_random_list, a, alpha): inter_conf = [] desv_tipic = float(1 / 12) x_media_value = self.x_media(num_random_list) z = distributions.normal_distribution(1 - (alpha / 2)) inter_conf.append(x_media_value - desv_tipic / math.sqrt(len(num_random_list)) * z) inter_conf.append(x_media_value + desv_tipic / math.sqrt(len(num_random_list)) * z) return inter_conf[0] < x_media_value < inter_conf[1]
def midTest(self, num_random_list, a, alpha): inter_conf = [] desv_tipic = float(1 / 12) x_media_value = self.x_media(num_random_list) z = distributions.normal_distribution(1 - (alpha / 2)) inter_conf.append(x_media_value - desv_tipic / math.sqrt(len(num_random_list)) * z) inter_conf.append(x_media_value + desv_tipic / math.sqrt(len(num_random_list)) * z) return inter_conf[0] < x_media_value < inter_conf[1]
def __init__(self, pos, network, default_vote=voting_strategy.default_vote, vote=voting_strategy.vote): # Map from height to {node_id: latest_bet} self.received_signatures = [] # List of received blocks self.received_blocks = [] # Own probability estimates self.probs = [] # All objects that this validator has received; basically a database self.received_objects = {} # Time when the object was received self.time_received = {} # The validator's ID, and its position in the queue self.pos = self.id = pos # The offset of this validator's clock vs. real time self.time_offset = normal_distribution(0, CLOCK_DISPARITY)() # The highest height that this validator has seen self.max_height = 0 # The validator's hash chain self.finalized_hashes = [] # Finalized states self.states = [] # The highest height that the validator has finalized self.max_finalized_height = -1 # The network object self.network = network # Last time signed self.last_time_signed = 0 # Next height to mine self.next_height = self.pos # Own most recent signature self.most_recent_sig = None # Most recent signatures of other validators self.most_recent_sigs = {} # Voting methods self.vote = vote self.default_vote = default_vote
def __distribution(self, time, size): mu, sigma2 = self.__parameters(time, size) return abs(normal_distribution(mu, sigma2 ** 0.5))
from networksim import NetworkSimulator from lmd_node import Node, NOTARIES, Block, Sig, genesis, SLOT_SIZE from distributions import normal_distribution net = NetworkSimulator(latency=300) notaries = [ Node(i, net, ts=max(normal_distribution(3, 3)(), 0) * 0.1, sleepy=False) for i in range(NOTARIES) ] net.agents = notaries net.generate_peers() for i in range(12000): net.tick() for n in notaries: print("Local timestamp: %.1f, timequeue len %d" % (n.ts, len(n.timequeue))) print("Main chain head: %d" % n.compute_lmd_head().height) print("Total main chain blocks received: %d" % (len([b for b in n.blocks.values() if isinstance(b, Block)]) - 1)) import matplotlib.pyplot as plt import networkx as nx import random G = nx.Graph() #positions = {genesis.hash: 0, beacon_genesis.hash: 0} #queue = [ for b in n.blocks.values(): if b.height > 0: if isinstance(b, Block):
from networksim import NetworkSimulator from ghost_node import Node, NOTARIES, Block, genesis from distributions import normal_distribution net = NetworkSimulator(latency=22) notaries = [ Node(i, net, ts=max(normal_distribution(300, 300)(), 0) * 0.1, sleepy=i % 4 == 0) for i in range(NOTARIES) ] net.agents = notaries net.generate_peers() for i in range(100000): net.tick() for n in notaries: print("Local timestamp: %.1f, timequeue len %d" % (n.ts, len(n.timequeue))) print("Main chain head: %d" % n.blocks[n.main_chain[-1]].number) print("Total main chain blocks received: %d" % (len([b for b in n.blocks.values() if isinstance(b, Block)]) - 1)) print("Notarized main chain blocks received: %d" % (len([ b for b in n.blocks.values() if isinstance(b, Block) and n.is_notarized(b) ]) - 1)) import matplotlib.pyplot as plt import networkx as nx import random G = nx.Graph()
from networksim import NetworkSimulator from node import Node, NOTARIES, MainChainBlock, main_genesis from distributions import normal_distribution net = NetworkSimulator(latency=12) notaries = [Node(i, net, ts=max(normal_distribution(50, 50)(), 0)) for i in range(NOTARIES)] net.agents = notaries net.generate_peers() for i in range(4000): net.tick() for n in notaries: print("Main chain head: %d" % n.blocks[n.main_chain[-1]].number) print("Total main chain blocks received: %d" % (len([b for b in n.blocks.values() if isinstance(b, MainChainBlock)]) - 1)) import matplotlib.pyplot as plt import networkx as nx import random G=nx.Graph() #positions = {main_genesis.hash: 0, beacon_genesis.hash: 0} #queue = [ for b in n.blocks.values(): if b.number > 0: if isinstance(b, MainChainBlock): G.add_edge(b.hash, b.parent_hash, color='b') cache = {main_genesis.hash: 0} def mkoffset(b):
from networksim import NetworkSimulator from lmd_node import Node, NOTARIES, Block, Sig, genesis, SLOT_SIZE from distributions import normal_distribution net = NetworkSimulator(latency=20) notaries = [ Node(i, net, ts=max(normal_distribution(1000, 1000)(), 0) * 0.1, sleepy=False) for i in range(NOTARIES) ] net.agents = notaries net.generate_peers() for i in range(12000): net.tick() for n in notaries: print("Local timestamp: %.1f, timequeue len %d" % (n.ts, len(n.timequeue))) print("Main chain head: %d" % n.compute_lmd_head().height) print("Total main chain blocks received: %d" % (len([b for b in n.blocks.values() if isinstance(b, Block)]) - 1)) import matplotlib.pyplot as plt import networkx as nx import random G = nx.Graph() #positions = {genesis.hash: 0, beacon_genesis.hash: 0} #queue = [ for b in n.blocks.values():