예제 #1
0
def main():
    target_interval_sec = 5
    diff_calc = diff.MADifficultyCalculator(
        ma_samples=32, target_interval_sec=target_interval_sec)
    hash_power = 100

    cTime = 0.0
    chain = [Block(0, 0.002)]
    usedTimeList = []
    p = proof_of_work.PoW(hash_power)

    for i in range(1000):
        required_diff = diff_calc.calculate_diff(chain)
        cTime = cTime + p.mine(required_diff)
        block = Block(cTime, required_diff)
        used_time = block.n_time - chain[-1].n_time
        chain.append(block)
        usedTimeList.append(used_time)
        print("Time %.2f, block %d, requiredWork %.2f, used_time %.2f" %
              (block.n_time, i + 1, 1 / block.required_diff, used_time))

    print("Max: %.2f, min: %.2f, avg: %.2f, std: %.2f" % (
        max(usedTimeList),
        min(usedTimeList),
        stat.mean(usedTimeList),
        stat.stdev(usedTimeList),
    ))
예제 #2
0
    def __init__(self,
                 hash_power=NODE_DEFAULT_HASH_POWER,
                 chain_selector=DynamicChainSelector):
        self.node_id = Node.get_next_node_id()
        self.peers = []
        self.major_chain = MajorBlockChain(SHARD_SIZE, 0)
        self.chain_selector = chain_selector

        # Create a list of minor blockchains
        minor_chain_list = []
        for i in range(SHARD_SIZE):
            minor_chain_list.append(MinorBlockChain(SHARD_SIZE, i, hash=i + 1))
        self.minor_chain_list = minor_chain_list
        print("node %d created" % self.node_id)
        self.hash_power = hash_power
        self.pow = proof_of_work.PoW(self.hash_power)
        self.rewards = 0