def build_huffman_tree(self, heap, s, r): newProbability = 0 newNode = Node() while s > 0: s = s - 1 minimumNode = heap.extract_min() newProbability += minimumNode.get_probability() newNode.add_child(minimumNode) newNode.set_character(None) newNode.set_probability(newProbability) heap.insert(newNode) while True: rIndex = r newProbability = 0 newNode = Node() while rIndex > 0: rIndex = rIndex - 1 minimumNode = heap.extract_min() newProbability += minimumNode.get_probability() newNode.add_child(minimumNode) newNode.set_character(None) newNode.set_probability(newProbability) heap.insert(newNode) if heap.get_size() == 1: return heap.get_values()[0]
def test_node(self): node1 = Node() node1.set_character('a') node1.set_probability('1') self.assertEqual(node1.get_character(), 'a') self.assertEqual(node1.get_probability(), '1') self.assertTrue(node1.is_leaf())
def handle_command(self, sender_id: str, sender_ip, sender_port, cmd, payload: str): sender_node = Node(sender_id, sender_ip, sender_port) if cmd == "FIND_NODE": self.routing_table.add_node(sender_node) closest_nodes = self.routing_table.get_closest_nodes( payload, self.k) return json.dumps(closest_nodes, default=lambda x: x.__dict__) if cmd == "STORE": message = Message(sender_node, payload) if self.node.is_public: self.send_broadcast(message) return "ok" self.routing_table.add_node(sender_node) self.messages.append(message) return "ok" if cmd == "PING": return "PONG" if self.node.is_public: if cmd == "SUBSCRIBE": self.routing_table.add_node(sender_node) self.add_subscriber(sender_node) return "ok" if cmd == "UNSUBSCRIBE": self.subscribers.remove(sender_node) self._update_subscribers_file() return "ok"
def _load_table(self, bootstrap_node: Node): self.add_node(bootstrap_node) with open(self._file_path, mode="a+") as f: raw_nodes = f.readlines() raw_nodes = [x.strip() for x in raw_nodes] for raw_node in raw_nodes: node_id, ip, port = raw_node.split(':') self.add_node(Node(node_id, ip, int(port)))
def _load_subscribers(self): subscribers = [] with open(self._subscribers_file, mode="a+") as f: raw_nodes = f.readlines() raw_nodes = [x.strip() for x in raw_nodes] for raw_node in raw_nodes: node_id, ip, port = raw_node.split(':') subscribers.append(Node(node_id, ip, int(port))) return subscribers
def import_file_to_graph(self, inputpath): """ Decodes a text file into a Graph object :param inputpath: path to definition file :return: graph: Imported Graph object """ with open(inputpath, 'r') as file: graph = Graph() entries = 0 lines = file.readlines() # Check if the file has the correct format: # Graph [name] { ... } with // comments allowed contents = "" for line in lines: contents += line # set flag re.DEBUG as additional parameter to debug this regex match = re.match("(\/\/.*)*Graph\s.+\s{[\s\S]*}", contents) if match is None: logging.error("The file format is not valid! Check the import specification for the correct format.") exit(2) # Read the file line by line for line in lines: if entries >= self.MAX_ITEMS: logging.error("File is too long! Aborting import.") exit(2) if line.startswith('//') or line.find(';') == -1: # line is a comment or not a definition continue if line.find('-') == -1: # line is a node definition key = line[0: line.find('=')].strip() value = line[line.find('=') + 1:line.find(';')].strip() graph.nodes.append(Node(value, key)) logging.debug('Node definition found: %s | %s', value, key) elif line.find('-') != -1: # line is an edge definition frm = line[0: line.find('-')].strip() to = line[line.find('-') + 1: line.find(':')].strip() cost = line[line.find(':') + 1:line.find(';')].strip() graph.edges.append(Edge(frm, to, int(cost))) logging.debug('Edge definition found: %s | %s | %s', frm, to, cost) entries += 1 for node in graph.nodes: logging.debug('%s - %s', node.node_id, node.name) for edge in graph.edges: logging.debug('%s - %s: %s', edge.frm, edge.to, edge.cost) file.close() return graph
def _send_find_node(self, node: Node, node_to_search_id: str) -> list: with socketmanager(socket.AF_INET, socket.SOCK_STREAM) as s: print(f"Connecting to {node.ip}:{node.port} (FIND_NODE)") s.connect((node.ip, node.port)) s.send(bytes(f"{self.node.id}:{self.node.port} FIND_NODE {node_to_search_id}", encoding="utf-8")) res = s.recv(1024) lst = [] for str_node in json.loads(res.decode(encoding='utf-8')): lst.append(Node(None, None, None).init_from_dict(str_node)) return lst
def build_heap(self, dictionary): characters = list(dictionary.keys()) probabilities = list(dictionary.values()) queue = PriorityQueue() for index in range(len(characters)): node = Node() node.set_character(characters[index]) node.set_probability(probabilities[index]) queue.insert(node) return queue
def setUp(self): self.command_queues = [] self.output_queues = [] self.client_threads = [] self.server_threads = [] self.locks = [] self.users = [] self.tables = [] self.bucket_limit = 20 self.k = 10 self.alpha = 3 self.connections_count = 20 self.bootstrap_node = Node("bootstrap_node", "127.0.0.1", 5555) self.private_nodes_count = 5 self.public_nodes_count = 2 self._generate_private_nodes(self.private_nodes_count) self._generate_public_nodes(self.public_nodes_count)
def test_node_comparison(self): node1 = Node() node1.set_probability('1') node2 = Node() node2.set_probability('2') self.assertTrue(node1 < node2)
class InputsConfig: """ Seclect the model to be simulated. 0 : The base model 1 : Bitcoin model 2 : Ethereum model 3 : Trias model """ model = 3 ''' Input configurations for the base model ''' if model == 0: ''' Block Parameters ''' Binterval = 600 # Average time (in seconds)for creating a block in the blockchain Bsize = 1.0 # The block size in MB Bdelay = 0.42 # average block propogation delay in seconds, #Ref: https://bitslog.wordpress.com/2016/04/28/uncle-mining-an-ethereum-consensus-protocol-flaw/ Breward = 12.5 # Reward for mining a block ''' Transaction Parameters ''' hasTrans = True # True/False to enable/disable transactions in the simulator Ttechnique = "Light" # Full/Light to specify the way of modelling transactions Tn = 10 # The rate of the number of transactions to be created per second Tdelay = 5.1 # The average transaction propagation delay in seconds (Only if Full technique is used) Tfee = 0.000062 # The average transaction fee Tsize = 0.000546 # The average transaction size in MB ''' Node Parameters ''' Nn = 3 # the total number of nodes in the network NODES = [] from Models.Node import Node NODES = [ Node(id=0), Node(id=1) ] # here as an example we define three nodes by assigning a unique id for each one ''' Simulation Parameters ''' simTime = 1000 # the simulation length (in seconds) Runs = 2 # Number of simulation runs ''' Input configurations for Bitcoin model ''' if model == 1: ''' Block Parameters ''' Binterval = 600 # Average time (in seconds)for creating a block in the blockchain Bsize = 1.0 # The block size in MB Bdelay = 0.42 # average block propogation delay in seconds, #Ref: https://bitslog.wordpress.com/2016/04/28/uncle-mining-an-ethereum-consensus-protocol-flaw/ Breward = 12.5 # Reward for mining a block ''' Transaction Parameters ''' hasTrans = True # True/False to enable/disable transactions in the simulator Ttechnique = "Light" # Full/Light to specify the way of modelling transactions Tn = 10 # The rate of the number of transactions to be created per second Tdelay = 5.1 # The average transaction propagation delay in seconds (Only if Full technique is used) Tfee = 0.000062 # The average transaction fee Tsize = 0.000546 # The average transaction size in MB ''' Node Parameters ''' Nn = 3 # the total number of nodes in the network NODES = [] from Models.Bitcoin.Node import Node NODES = [ Node(id=0, hashPower=50), Node(id=1, hashPower=20), Node(id=2, hashPower=30) ] # here as an example we define three nodes by assigning a unique id for each one + % of hash (computing) power ''' Simulation Parameters ''' simTime = 10000 # the simulation length (in seconds) Runs = 2 # Number of simulation runs ''' Input configurations for Ethereum model ''' if model == 2: ''' Block Parameters ''' Binterval = 12.42 # Average time (in seconds)for creating a block in the blockchain Bsize = 1.0 # The block size in MB Blimit = 8000000 # The block gas limit Bdelay = 6 # average block propogation delay in seconds, #Ref: https://bitslog.wordpress.com/2016/04/28/uncle-mining-an-ethereum-consensus-protocol-flaw/ Breward = 2 # Reward for mining a block ''' Transaction Parameters ''' hasTrans = True # True/False to enable/disable transactions in the simulator Ttechnique = "Light" # Full/Light to specify the way of modelling transactions Tn = 20 # The rate of the number of transactions to be created per second Tdelay = 3 # The average transaction propagation delay in seconds (Only if Full technique is used) # The transaction fee in Ethereum is calculated as: UsedGas X GasPrice Tsize = 0.000546 # The average transaction size in MB ''' Drawing the values for gas related attributes (UsedGas and GasPrice, CPUTime) from fitted distributions ''' ''' Uncles Parameters ''' hasUncles = True # boolean variable to indicate use of uncle mechansim or not Buncles = 2 # maximum number of uncle blocks allowed per block Ugenerations = 7 # the depth in which an uncle can be included in a block Ureward = 0 UIreward = Breward / 32 # Reward for including an uncle ''' Node Parameters ''' Nn = 3 # the total number of nodes in the network NODES = [] from Models.Ethereum.Node import Node NODES = [ Node(id=0, hashPower=50), Node(id=1, hashPower=20), Node(id=2, hashPower=30) ] # here as an example we define three nodes by assigning a unique id for each one + % of hash (computing) power ''' Simulation Parameters ''' simTime = 500 # the simulation length (in seconds) Runs = 2 # Number of simulation runs ''' Input configurations for Trias model ''' if model == 3: ''' Block Parameters ''' Binterval = 600 # Average time (in seconds)for creating a block in the blockchain Bsize = 1.0 # The block size in MB # Bdelay = 0.42 # average block propogation delay in seconds, #Ref: https://bitslog.wordpress.com/2016/04/28/uncle-mining-an-ethereum-consensus-protocol-flaw/ # Bdelay = [ # [ float("inf") , 21.62 , 24.42 , 0.57 , 7.74 , 9.18 , 1.01 , 0.76 , 18.44 , 21.14 , 26.56 , 19.78 , 23.61 , 16.76 , 23.34 , 21.5 , 24.11 , 23.54 ], # [ 21.62 , float("inf") , 19.31 , 21.47 , 28.97 , 21.35 , 21.12 , 20.89 , 3.63 , 0.68 , 6.12 , 8.61 , 3.84 , 13.02 , 17.38 , 23.68 , 13.5 , 18.4 ], # [ 24.42 , 19.31 , float("inf") , 24.4 , 27.85 , 30.31 , 23.88 , 25.03 , 17.9 , 19.61 , 23.9 , 17.96 , 19.91 , 9.17 , 2.22 , 9.85 , 8.51 , 1.12 ], # [ 0.57 , 21.47 , 24.4 , float("inf") , 7.2 , 8.98 , 1.47 , 0.49 , 18.79 , 22.33 , 28.24 , 20.79 , 23.4 , 18.78 , 25.77 , 25.47 , 15.34 , 26.08 ], # [ 7.74 , 28.97 , 27.85 , 7.2 , float("inf") , 16 , 7.99 , 7.57 , 10.47 , 19.58 , 11.97 , 17.15 , 12.21 , 11.71 , 32.15 , 16.72 , 40.13 , 26.01 ], # [ 9.18 , 21.35 , 30.31 , 8.98 , 16 , float("inf") , 9.38 , 9.21 , 16.17 , 25.17 , 6.62 , 37.8 , 15.45 , 11.66 , 26.84 , 12.99 , 34.76 , 30.03 ], # [ 1.01 , 21.12 , 23.88 , 1.47 , 7.99 , 9.38 , float("inf") , 0.52 , 25.82 , 20.5 , 15.36 , 21.77 , 21.49 , 29.29 , 23.51 , 19.49 , 19.35 , 24.02 ], # [ 0.76 , 20.89 , 25.03 , 0.49 , 7.57 , 9.21 , 0.52 , float("inf") , 19.21 , 22.96 , 18.89 , 22.72 , 20.42 , 31.77 , 22.22 , 26.9 , 28.28 , 26.02 ], # [ 18.44 , 3.63 , 17.9 , 18.79 , 10.47 , 16.17 , 25.82 , 19.21 , float("inf") , 3.47 , 6.08 , 7.5 , 7.39 , 18.24 , 22.64 , 19.38 , 27.24 , 14.79 ], # [ 21.14 , 0.68 , 19.61 , 22.33 , 19.58 , 25.17 , 20.5 , 22.96 , 3.47 , float("inf") , 5.55 , 8.7 , 3.93 , 10.25 , 16.57 , 28.24 , 10.8 , 20.63 ], # [ 26.56 , 6.12 , 23.9 , 28.24 , 11.97 , 6.62 , 15.36 , 18.89 , 6.08 , 5.55 , float("inf") , 3.35 , 5.76 , 4.48 , 16.02 , 14.44 , 26.07 , 25.23 ], # [ 19.78 , 8.61 , 17.96 , 20.79 , 17.15 , 37.8 , 21.77 , 22.72 , 7.5 , 8.7 , 3.35 , float("inf") , 9.07 , 9.9 , 24.59 , 37.7 , 6.67 , 13.57 ], # [ 23.61 , 3.84 , 19.91 , 23.4 , 12.21 , 15.45 , 21.49 , 20.42 , 7.39 , 3.93 , 5.76 , 9.07 , float("inf") , 32.04 , 24.7 , 16.57 , 19.08 , 19.81 ], # [ 16.76 , 13.02 , 9.17 , 18.78 , 11.71 , 11.66 , 29.29 , 31.77 , 18.24 , 10.25 , 4.48 , 9.9 , 32.04 , float("inf") , 8.48 , 15.94 , 13.06 , 8.33 ], # [ 23.34 , 17.38 , 2.22 , 25.77 , 32.15 , 26.84 , 23.51 , 22.22 , 22.64 , 16.57 , 16.02 , 24.59 , 24.7 , 8.48 , float("inf") , 7.77 , 9.45 , 1.52 ], # [ 21.5 , 23.68 , 9.85 , 25.47 , 16.72 , 12.99 , 19.49 , 26.9 , 19.38 , 28.24 , 14.44 , 37.7 , 16.57 , 15.94 , 7.77 , float("inf") , 5.75 , 10.64 ], # [ 24.11 , 13.5 , 8.51 , 15.34 , 40.13 , 34.76 , 19.35 , 28.28 , 27.24 , 10.8 , 26.07 , 6.67 , 19.08 , 13.06 , 9.45 , 5.75 , float("inf") , 8.49 ], # [ 23.54 , 18.4 , 1.12 , 26.08 , 26.01 , 30.03 , 24.02 , 26.02 , 14.79 , 20.63 , 25.23 , 13.57 , 19.81 , 8.33 , 1.52 , 10.64 , 8.49 , float("inf") ] # ] # def do_pre_job(delay_matrix): # pass # def calc_delay(delay_matrix): # node_num = len(delay_matrix) # delay_result = [[0 for _ in range(node_num)] for __ in range(node_num)] # path_result = [] # for i in range(node_num): # distance = delay_matrix[i][:] # path = [None for _ in range(node_num)] # while min(distance) != float("inf"): # distance_min = min(distance) # j = distance.index(distance_min) # if distance[j] == delay_matrix[i][j]: # path[j] = i # delay_result[i][j] = distance[j] # distance[j] = float("inf") # for k in range(node_num): # if distance[k] != float("inf") and distance_min + delay_matrix[j][k] < distance[k]: # distance[k] = distance_min + delay_matrix[j][k] # path[k] = j # path_result.append(path) # return delay_result, path_result # Bdelay, _ = calc_delay(Bdelay) Breward = 12.5 # Reward for mining a block ''' Transaction Parameters ''' hasTrans = True # True/False to enable/disable transactions in the simulator Ttechnique = "Light" # Full/Light to specify the way of modelling transactions Tn = 10 # The rate of the number of transactions to be created per second Tdelay = 5.1 # The average transaction propagation delay in seconds (Only if Full technique is used) Tfee = 0.000062 # The average transaction fee Tsize = 0.000546 # The average transaction size in MB ''' Node Parameters ''' Nn = 1000 # the total number of nodes in the network NODES = [] ''' Network Parameters''' BoardcastType = "DBDC" # Gossip / DBDC ''' Security Parameters''' attack = True ''' Simulation Parameters ''' simTime = 10000 # the simulation length (in seconds) Runs = 1 # Number of simulation runs
class InputsConfig: model = model ''' Block Parameters ''' # average time for creating a block in the blockchain Binterval = float(os.getenv('BLOCK_INTERVAL', 596)) # block size in MB Bsize = float(os.getenv('BLOCK_SIZE', 0.83)) # average block propogation delay in seconds, ref: https://bitslog.wordpress.com/2016/04/28/uncle-mining-an-ethereum-consensus-protocol-flaw Bdelay = float(os.getenv('BLOCK_PROPAGATION_DELAY', 0.42)) # reward for mining a block Breward = float(os.getenv('BLOCK_REWARD', 12.5)) ''' Transaction Parameters ''' # whether to enable transactions in the simulator hasTrans = bool(os.getenv('TRANSACTION_ENABLED', True)) # specify the way of modelling transactions {Full, Light} Ttechnique = os.getenv('TRANSACTION_TECHNIQUE', 'Light') # average transaction size in MB Tsize = float(os.getenv('TRANSACTION_SIZE', 0.000546)) # rate of the number of transactions to be created per second Tn = int(os.getenv('TRANSACTION_PER_SECOND', 10)) # average transaction propagation delay in seconds (Only if Full technique is used) Tdelay = float(os.getenv('TRANSACTION_PROPAGATION_DELAY', 5.1)) # average transaction fee Tfee = float(os.getenv('TRANSACTION_FEE', 0.000062)) # time to treat transaction as timeout after it is created but still not mined Ttimeout = float(os.getenv('TRANSACTION_TIMEOUT', 5960)) ''' Node Parameters ''' # total count of nodes in the network NODES = [] Nn = int(os.getenv('NODE_COUNT', 3)) Npower = os.getenv('NODE_HASH_POWER', '50,20,30') node_hash_powers = [ float(node_hash_power) for node_hash_power in Npower.split(',') ] if len(node_hash_powers) != Nn: sys.exit( 'length of node hash powers must be equal to node count %d, but got %d' % (Nn, len(node_hash_powers))) ''' Simulation Parameters ''' # simulation length (in seconds) simTime = int(os.getenv('SIMULATION_TIME', 100000)) # count of simulation runs Runs = int(os.getenv('SIMULATION_RUN', 3)) ''' Base ''' if model == 0: NODES = [Node(id=i) for i in range(Nn)] ''' Bitcoin ''' if model == 1: NODES = [ Node(id=id, hashPower=hash_power) for id, hash_power in enumerate(node_hash_powers) ] ''' Ethereum ''' if model == 2: # The block gas limit Blimit = int(os.getenv('BLOCK_GAS_LIMIT', 7997148)) # whether to enable uncle in the simulator hasUncles = bool(os.getenv('UNCLE_ENABLED', True)) # max count of uncle blocks allowed per block Buncles = int(os.getenv('UNCLE_PER_BLOCK', 2)) # depth in which an uncle can be included in a block Ugenerations = int(os.getenv('UNCLE_DEPTH', 7)) # reward for an uncle block Ureward = int(os.getenv('UNCLE_REWARD', 0)) # reward for including an uncle UIreward = float(os.getenv('UNCLE_INCLUDING_REWARD', Breward / 32)) NODES = [ Node(id=id, hashPower=hash_power) for id, hash_power in enumerate(node_hash_powers) ] ''' B++ ''' if model == 3: Bdmin = int(os.getenv('BLOCK_D_MIN', -2)) TProbability = [ float(tx_probability) for tx_probability in os.getenv( 'TRANSACTION_PROBABILITY', '1,25,74').split(',') ] NODES = [ Node(id=id, hashPower=hash_power) for id, hash_power in enumerate(node_hash_powers) ]
def generate_default_map(self): self.nodes = [ Node(1, 1, (0, 0), 2, 20, -1), Node(2, 2, (10, 10), 2, 20, -1), Node(3, 0, (4, 0), 2, 10), Node(4, 0, (6, 0), 2, 10), Node(5, 0, (5, 2), 2, 10), Node(6, 0, (4, 10), 2, 10), Node(7, 0, (6, 10), 2, 10), Node(8, 0, (5, 8), 2, 10), Node(9, 0, (6, 4), 2, 30), Node(10, 0, (5, 5), 2, 30), Node(11, 0, (4, 6), 2, 30), Node(12, 0, (4, 4), 2, 30), Node(13, 0, (6, 6), 2, 30), ]
def __init__(self, login: str, ip, port, is_public: bool = False): self.login = login self.node = Node( sha1(bytes(login, encoding='utf-8')).hexdigest(), ip, port, is_public)
def test_node_get_probability(self): node = Node() node.set_probability('1') self.assertEqual(node.get_probability(), '1')
def test_node_get_character(self): node = Node() node.set_character('a') self.assertEqual(node.get_character(), 'a')
class InputsConfig: """ Seclect the model to be simulated. 0 : The base model 1 : Bitcoin model 2 : Ethereum model 3 : AppendableBlock model """ model = 3 ''' Input configurations for the base model ''' if model == 0: ''' Block Parameters ''' Binterval = 600 # Average time (in seconds)for creating a block in the blockchain Bsize = 1.0 # The block size in MB Bdelay = 0.42 # average block propogation delay in seconds, #Ref: https://bitslog.wordpress.com/2016/04/28/uncle-mining-an-ethereum-consensus-protocol-flaw/ Breward = 12.5 # Reward for mining a block ''' Transaction Parameters ''' hasTrans = True # True/False to enable/disable transactions in the simulator Ttechnique = "Light" # Full/Light to specify the way of modelling transactions Tn = 10 # The rate of the number of transactions to be created per second # The average transaction propagation delay in seconds (Only if Full technique is used) Tdelay = 5.1 Tfee = 0.000062 # The average transaction fee Tsize = 0.000546 # The average transaction size in MB ''' Node Parameters ''' Nn = 3 # the total number of nodes in the network NODES = [] from Models.Node import Node # here as an example we define three nodes by assigning a unique id for each one NODES = [Node(id=0), Node(id=1)] ''' Simulation Parameters ''' simTime = 1000 # the simulation length (in seconds) Runs = 2 # Number of simulation runs ''' Input configurations for Bitcoin model ''' if model == 1: ''' Block Parameters ''' Binterval = 600 # Average time (in seconds)for creating a block in the blockchain Bsize = 1.0 # The block size in MB Bdelay = 0.42 # average block propogation delay in seconds, #Ref: https://bitslog.wordpress.com/2016/04/28/uncle-mining-an-ethereum-consensus-protocol-flaw/ Breward = 12.5 # Reward for mining a block ''' Transaction Parameters ''' hasTrans = True # True/False to enable/disable transactions in the simulator Ttechnique = "Light" # Full/Light to specify the way of modelling transactions Tn = 10 # The rate of the number of transactions to be created per second # The average transaction propagation delay in seconds (Only if Full technique is used) Tdelay = 5.1 Tfee = 0.000062 # The average transaction fee Tsize = 0.000546 # The average transaction size in MB ''' Node Parameters ''' Nn = 3 # the total number of nodes in the network NODES = [] from Models.Bitcoin.Node import Node # here as an example we define three nodes by assigning a unique id for each one + % of hash (computing) power NODES = [ Node(id=0, hashPower=50), Node(id=1, hashPower=20), Node(id=2, hashPower=30) ] ''' Simulation Parameters ''' simTime = 10000 # the simulation length (in seconds) Runs = 2 # Number of simulation runs ''' Input configurations for Ethereum model ''' if model == 2: ''' Block Parameters ''' Binterval = 12.42 # Average time (in seconds)for creating a block in the blockchain Bsize = 1.0 # The block size in MB Blimit = 8000000 # The block gas limit Bdelay = 6 # average block propogation delay in seconds, #Ref: https://bitslog.wordpress.com/2016/04/28/uncle-mining-an-ethereum-consensus-protocol-flaw/ Breward = 2 # Reward for mining a block ''' Transaction Parameters ''' hasTrans = True # True/False to enable/disable transactions in the simulator Ttechnique = "Light" # Full/Light to specify the way of modelling transactions Tn = 20 # The rate of the number of transactions to be created per second # The average transaction propagation delay in seconds (Only if Full technique is used) Tdelay = 3 # The transaction fee in Ethereum is calculated as: UsedGas X GasPrice Tsize = 0.000546 # The average transaction size in MB ''' Drawing the values for gas related attributes (UsedGas and GasPrice, CPUTime) from fitted distributions ''' ''' Uncles Parameters ''' hasUncles = True # boolean variable to indicate use of uncle mechansim or not Buncles = 2 # maximum number of uncle blocks allowed per block Ugenerations = 7 # the depth in which an uncle can be included in a block Ureward = 0 UIreward = Breward / 32 # Reward for including an uncle ''' Node Parameters ''' Nn = 3 # the total number of nodes in the network NODES = [] from Models.Ethereum.Node import Node # here as an example we define three nodes by assigning a unique id for each one + % of hash (computing) power NODES = [ Node(id=0, hashPower=50), Node(id=1, hashPower=20), Node(id=2, hashPower=30) ] ''' Simulation Parameters ''' simTime = 500 # the simulation length (in seconds) Runs = 2 # Number of simulation runs ''' Input configurations for AppendableBlock model ''' if model == 3: ''' Transaction Parameters ''' hasTrans = True # True/False to enable/disable transactions in the simulator Ttechnique = "Full" # The rate of the number of transactions to be created per second Tn = 10 # The maximum number of transactions that can be added into a transaction list txListSize = 100 ''' Node Parameters ''' # Number of device nodes per gateway in the network Dn = 10 # Number of gateway nodes in the network Gn = 2 # Total number of nodes in the network Nn = Gn + (Gn * Dn) # A list of all the nodes in the network NODES = [] # A list of all the gateway Ids GATEWAYIDS = [chr(x + 97) for x in range(Gn)] from Models.AppendableBlock.Node import Node # Create all the gateways for i in GATEWAYIDS: otherGatewayIds = GATEWAYIDS.copy() otherGatewayIds.remove(i) # Create gateway node NODES.append(Node(i, "g", otherGatewayIds)) # Create the device nodes for each gateway deviceNodeId = 1 for i in GATEWAYIDS: for j in range(Dn): NODES.append(Node(deviceNodeId, "d", i)) deviceNodeId += 1 ''' Simulation Parameters ''' # The average transaction propagation delay in seconds propTxDelay = 0.000690847927 # The average transaction list propagation delay in seconds propTxListDelay = 0.00864894 # The average transaction insertion delay in seconds insertTxDelay = 0.000010367235 # The simulation length (in seconds) simTime = 500 # Number of simulation runs Runs = 5 ''' Verification ''' # Varify the model implementation at the end of first run VerifyImplemetation = True maxTxListSize = 0
def test_node_add_child(self): node = Node() self.assertTrue(node.is_leaf()) node.add_child(Node()) self.assertFalse(node.is_leaf())
class InputsConfig: """ Seclect the model to be simulated. 0 : The base model 1 : Bitcoin model 2 : Ethereum model """ model = 2 ''' Input configurations for the base model ''' if model == 0: ''' Block Parameters ''' Binterval = 600 # Average time (in seconds)for creating a block in the blockchain Bsize = 1.0 # The block size in MB Bdelay = 0.42 # average block propogation delay in seconds, #Ref: https://bitslog.wordpress.com/2016/04/28/uncle-mining-an-ethereum-consensus-protocol-flaw/ Breward = 12.5 # Reward for mining a block ''' Transaction Parameters ''' hasTrans = True # True/False to enable/disable transactions in the simulator Ttechnique = "Light" # Full/Light to specify the way of modelling transactions Tn = 10 # The rate of the number of transactions to be created per second Tdelay = 5.1 # The average transaction propagation delay in seconds (Only if Full technique is used) Tfee = 0.000062 # The average transaction fee Tsize = 0.000546 # The average transaction size in MB ''' Node Parameters ''' Nn = 3 # the total number of nodes in the network NODES = [] from Models.Node import Node NODES = [ Node(id=0), Node(id=1) ] # here as an example we define three nodes by assigning a unique id for each one ''' Simulation Parameters ''' simTime = 1000 # the simulation length (in seconds) Runs = 2 # Number of simulation runs ''' Input configurations for Bitcoin model ''' if model == 1: ''' Block Parameters ''' Binterval = 600 # Average time (in seconds)for creating a block in the blockchain Bsize = 1.0 # The block size in MB Bdelay = 0.42 # average block propogation delay in seconds, #Ref: https://bitslog.wordpress.com/2016/04/28/uncle-mining-an-ethereum-consensus-protocol-flaw/ Breward = 12.5 # Reward for mining a block ''' Transaction Parameters ''' hasTrans = True # True/False to enable/disable transactions in the simulator Ttechnique = "Light" # Full/Light to specify the way of modelling transactions Tn = 10 # The rate of the number of transactions to be created per second Tdelay = 5.1 # The average transaction propagation delay in seconds (Only if Full technique is used) Tfee = 0.000062 # The average transaction fee Tsize = 0.000546 # The average transaction size in MB ''' Node Parameters ''' Nn = 3 # the total number of nodes in the network NODES = [] from Models.Bitcoin.Node import Node NODES = [ Node(id=0, hashPower=50), Node(id=1, hashPower=20), Node(id=2, hashPower=30) ] # here as an example we define three nodes by assigning a unique id for each one + % of hash (computing) power ''' Simulation Parameters ''' simTime = 10000 # the simulation length (in seconds) Runs = 2 # Number of simulation runs ''' Input configurations for Ethereum model ''' if model == 2: ''' Block Parameters ''' Binterval = 12.42 # Average time (in seconds)for creating a block in the blockchain Bsize = 1.0 # The block size in MB Blimit = 8000000 # The block gas limit Bdelay = 6 # average block propogation delay in seconds, #Ref: https://bitslog.wordpress.com/2016/04/28/uncle-mining-an-ethereum-consensus-protocol-flaw/ Breward = 2 # Reward for mining a block ''' Transaction Parameters ''' hasTrans = True # True/False to enable/disable transactions in the simulator Ttechnique = "Light" # Full/Light to specify the way of modelling transactions Tn = 20 # The rate of the number of transactions to be created per second Tdelay = 3 # The average transaction propagation delay in seconds (Only if Full technique is used) # The transaction fee in Ethereum is calculated as: UsedGas X GasPrice Tsize = 0.000546 # The average transaction size in MB ''' Drawing the values for gas related attributes (UsedGas and GasPrice, CPUTime) from fitted distributions ''' ''' Uncles Parameters ''' hasUncles = True # boolean variable to indicate use of uncle mechansim or not Buncles = 2 # maximum number of uncle blocks allowed per block Ugenerations = 7 # the depth in which an uncle can be included in a block Ureward = 0 UIreward = Breward / 32 # Reward for including an uncle ''' Node Parameters ''' Nn = 3 # the total number of nodes in the network NODES = [] from Models.Ethereum.Node import Node NODES = [ Node(id=0, hashPower=50), Node(id=1, hashPower=20), Node(id=2, hashPower=30) ] # here as an example we define three nodes by assigning a unique id for each one + % of hash (computing) power ''' Simulation Parameters ''' simTime = 500 # the simulation length (in seconds) Runs = 2 # Number of simulation runs