def _can_endorse(self): self.log.warning("starting _can_endorse()") connect_nodes(self.nodes[0], 1) self.sync_all() disconnect_nodes(self.nodes[1], 0) mine_until_pop_active(self.nodes[0]) lastblock = self.nodes[0].getblockcount() # endorse block 200 (fork A tip) addr0 = self.nodes[0].getnewaddress() txid = endorse_block(self.nodes[0], self.apm, lastblock, addr0) self.log.info("node0 endorsed block {} (fork A tip)".format(lastblock)) # mine pop tx on node0 self.nodes[0].generate(nblocks=1) tip = self.get_best_block(self.nodes[0]) self.log.info("node0 tip is {}".format(tip['height'])) self.nodes[1].generate(nblocks=250) tip2 = self.get_best_block(self.nodes[1]) self.log.info("node1 tip is {}".format(tip2['height'])) connect_nodes(self.nodes[0], 1) self.sync_all() bestblocks = [self.get_best_block(x) for x in self.nodes] assert_equal(bestblocks[0]['hash'], bestblocks[1]['hash']) self.log.info("all nodes switched to common block") for i in range(len(bestblocks)): assert bestblocks[i]['height'] == tip['height'], \ "node[{}] expected to select shorter chain ({}) with higher pop score\n" \ "but selected longer chain ({})".format(i, tip['height'], bestblocks[i]['height']) self.log.info("all nodes selected fork A as best chain") self.log.warning("_can_endorse() succeeded!")
def setup_network(self): self.setup_nodes() mine_until_pop_active(self.nodes[0]) for i in range(self.num_nodes - 1): connect_nodes(self.nodes[i + 1], i) self.sync_all()
def run_test(self): """Main test logic""" from pypoptools.pypopminer import MockMiner self.apm = MockMiner() node = self.nodes[0] addr = node.getnewaddress() # stop 1 block behind activation self.log.info("Mining blocks until activation -5 blocks") self.log.info("Current node[0] height {}".format(node.getblockcount())) mine_until_pop_active(node, addr, delta=-5) self.log.info("Current node[0] height {}".format(node.getblockcount())) # check that getblocktemplate does NOT have pop-related fields before POP activation self.log.info("Check that getblocktemplate does not have POP fields") resp = self.getblocktemplate() assert_no_field(resp, 'pop_data') assert_no_field(resp, 'pop_data_root') assert_no_field(resp, 'pop_first_previous_keystone') assert_no_field(resp, 'pop_second_previous_keystone') assert_no_field(resp, 'pop_rewards') self.log.info("Mining blocks until activation +5 blocks") self.log.info("Current node[0] height {}".format(node.getblockcount())) mine_until_pop_active(node, addr, delta=+5) self.log.info("Current node[0] height {}".format(node.getblockcount())) self.log.info("Mine chain of {} consecutive endorsed blocks".format( POP_PAYOUT_DELAY)) create_endorsed_chain(node, self.apm, POP_PAYOUT_DELAY, addr) self.log.info("Current node[0] height {}".format(node.getblockcount())) endorse_block(self.nodes[0], self.apm, node.getblockcount() - 5, addr) self.log.info("Current node[0] height {}".format(node.getblockcount())) self.log.info("Check that getblocktemplate does have POP fields") resp = self.getblocktemplate() is_dict = lambda x: isinstance(x, dict) is_list = lambda x: isinstance(x, list) is_int = lambda x: isinstance(x, int) is_hex = lambda x: bytes.fromhex(x) is_payload = lambda x: is_dict(x) and "id" in x and "serialized" in x is_payload_list = lambda x: is_list(x) and all( is_payload(p) for p in x) assert_field_exists(resp, 'pop_data', type=is_dict) assert_field_exists(resp['pop_data'], 'atvs', type=is_payload_list) assert_field_exists(resp['pop_data'], 'vtbs', type=is_payload_list) assert_field_exists(resp['pop_data'], 'vbkblocks', type=is_payload_list) assert_field_exists(resp['pop_data'], 'version', type=is_int) assert_field_exists(resp, 'pop_data_root', type=is_hex) assert_field_exists(resp, 'pop_first_previous_keystone', type=is_hex) assert_field_exists(resp, 'pop_second_previous_keystone', type=is_hex) assert_field_exists(resp, 'pop_rewards', type=is_list) for reward in resp['pop_rewards']: assert_field_exists(reward, 'amount', type=is_int) assert_field_exists(reward, 'payout_info', type=is_hex) self.log.info("Current node[0] height {}".format(node.getblockcount()))
def setup_network(self): self.setup_nodes() mine_until_pop_active(self.nodes[0]) # all nodes connected and synced for i in range(self.num_nodes - 1): connect_nodes(self.nodes[i + 1], i) self.sync_all() self.keystoneInterval = get_keystone_interval(self.nodes[0])
def setup_network(self): self.setup_nodes() mine_until_pop_active(self.nodes[0]) # nodes[0,1] will be restarted # node[2] is a control node # all nodes connected and synced for i in range(self.num_nodes - 1): connect_nodes(self.nodes[i + 1], i) self.sync_all(self.nodes, timeout=60)
def run_test(self): mine_until_pop_active(self.nodes[0]) node = self.nodes[0] # alias self.popctx = PopMiningContext(self.nodes[0]) node.add_p2p_connection(P2PStoreTxInvs()) self.log.info("Create a new transaction and wait until it's broadcast") txid = int(node.sendtoaddress(node.getnewaddress(), 1), 16) # Wallet rebroadcast is first scheduled 1 sec after startup (see # nNextResend in ResendWalletTransactions()). Sleep for just over a # second to be certain that it has been called before the first # setmocktime call below. time.sleep(1.1) # Can take a few seconds due to transaction trickling wait_until(lambda: node.p2p.tx_invs_received[txid] >= 1, lock=mininode_lock) # Add a second peer since txs aren't rebroadcast to the same peer (see filterInventoryKnown) node.add_p2p_connection(P2PStoreTxInvs()) self.log.info("Create a block") # Create and submit a block without the transaction. # Transactions are only rebroadcast if there has been a block at least five minutes # after the last time we tried to broadcast. Use mocktime and give an extra minute to be sure. assert self.nodes[0].getblockchaininfo( )['softforks']['pop_security']['active'], "POP is not activated" block_time = int(time.time()) + 6 * 60 node.setmocktime(block_time) block = create_block(self.popctx, int(node.getbestblockhash(), 16), create_coinbase(node.getblockcount() + 1), block_time) block.rehash() block.solve() node.submitblock(ToHex(block)) # Transaction should not be rebroadcast node.p2ps[1].sync_with_ping() assert_equal(node.p2ps[1].tx_invs_received[txid], 0) self.log.info("Transaction should be rebroadcast after 30 minutes") # Use mocktime and give an extra 5 minutes to be sure. rebroadcast_time = int(time.time()) + 41 * 60 node.setmocktime(rebroadcast_time) wait_until(lambda: node.p2ps[1].tx_invs_received[txid] >= 1, lock=mininode_lock)
def setup_network(self): self.setup_nodes() mine_until_pop_active(self.nodes[0]) self.sync_all()
def setup_network(self): self.setup_nodes() mine_until_pop_active(self.nodes[0]) connect_nodes(self.nodes[0], 1) self.sync_all(self.nodes)
def setup_network(self): self.add_nodes(self.num_nodes) self.start_node(0) # POP should be enabled because merkle root calculation differs for non-POP blocks mine_until_pop_active(self.nodes[0]) self.popctx = PopMiningContext(self.nodes[0])
def setup_network(self): self.setup_nodes() mine_until_pop_active(self.nodes[0]) self.popctx = PopMiningContext(self.nodes[0])