def run_test(self): num_blocks = 200 checkpoint_epoch = 100 # Generate checkpoint on node[0] client = RpcClient(self.nodes[0]) self.genesis_nonce = client.get_nonce(client.GENESIS_ADDR) for _ in range(num_blocks): txs = self._generate_txs(0, random.randint(5, 10)) client.generate_block_with_fake_txs(txs) # Start node[1] as full node to sync checkpoint # Change phase from CatchUpSyncBlockHeader to CatchUpCheckpoint # only when there is at least one connected peer. self.start_node(1, ["--full"], phase_to_wait=None) connect_nodes(self.nodes, 1, 0) # FIXME full node issue that hang at phase CatchUpRecoverBlockFromDbPhase self.nodes[1].wait_for_phase(["NormalSyncPhase"], wait_time=30) sync_blocks(self.nodes, sync_count=False) client = RpcClient(self.nodes[1]) # At epoch 1, block header exists while body not synchronized try: print(client.block_by_epoch(client.EPOCH_NUM(1))) except ReceivedErrorResponseError as e: assert 'Internal error' == e.response.message # There is no state from epoch 1 to checkpoint_epoch # Note, state of genesis epoch always exists assert client.epoch_number() >= checkpoint_epoch # FIXME: we minus REWARD_EPOCH_COUNT here as a workaround. # FIXME: after the state boundary is implemented in consensus, # FIXME: this workaround should be removed. for i in range(1, checkpoint_epoch - 11): try: client.get_balance(client.GENESIS_ADDR, client.EPOCH_NUM(i)) raise AssertionError( "should not have state for epoch {}".format(i)) except ReceivedErrorResponseError as e: assert "State for epoch" in e.response.message assert "does not exist" in e.response.message # State should exist at checkpoint client.get_balance(client.GENESIS_ADDR, client.EPOCH_NUM(checkpoint_epoch)) # There should be states after checkpoint for i in range(checkpoint_epoch, client.epoch_number() - 3): client.get_balance(client.GENESIS_ADDR, client.EPOCH_NUM(i))
def run_test(self): num_blocks = 200 snapshot_epoch = 150 # Generate checkpoint on node[0] archive_node_client = RpcClient(self.nodes[0]) self.genesis_nonce = archive_node_client.get_nonce( archive_node_client.GENESIS_ADDR) blocks_in_era = [] for i in range(num_blocks): txs = self._generate_txs(0, random.randint(50, 100)) block_hash = archive_node_client.generate_block_with_fake_txs(txs) if i >= snapshot_epoch: blocks_in_era.append(block_hash) sync_blocks(self.nodes[:-1]) self.log.info("All archive nodes synced") # Start node[full_node_index] as full node to sync checkpoint # Change phase from CatchUpSyncBlockHeader to CatchUpCheckpoint # only when there is at least one connected peer. full_node_index = self.num_nodes - 1 self.start_node(full_node_index, ["--full"], phase_to_wait=None) for i in range(self.num_nodes - 1): connect_nodes(self.nodes, full_node_index, i) self.log.info("Wait for full node to sync, index=%d", full_node_index) self.nodes[full_node_index].wait_for_phase(["NormalSyncPhase"], wait_time=240) sync_blocks(self.nodes, sync_count=False) full_node_client = RpcClient(self.nodes[full_node_index]) # At epoch 1, block header exists while body not synchronized try: print( full_node_client.block_by_epoch(full_node_client.EPOCH_NUM(1))) except ReceivedErrorResponseError as e: assert 'Internal error' == e.response.message # There is no state from epoch 1 to snapshot_epoch # Note, state of genesis epoch always exists assert full_node_client.epoch_number() >= snapshot_epoch wait_until( lambda: full_node_client.epoch_number() == archive_node_client. epoch_number() and full_node_client.epoch_number("latest_state") == archive_node_client.epoch_number("latest_state")) # We have snapshot_epoch for state execution but # don't offer snapshot_epoch for Rpc clients. for i in range(1, snapshot_epoch + 1): try: full_node_client.get_balance(full_node_client.GENESIS_ADDR, full_node_client.EPOCH_NUM(i)) raise AssertionError( "should not have state for epoch {}".format(i)) except ReceivedErrorResponseError as e: assert "State for epoch" in e.response.message assert "does not exist" in e.response.message # Wait for execution to complete. time.sleep(1) # There should be states after checkpoint for i in range(snapshot_epoch + 1, full_node_client.epoch_number() - 3): full_balance = full_node_client.get_balance( full_node_client.GENESIS_ADDR, full_node_client.EPOCH_NUM(i)) archive_balance = archive_node_client.get_balance( archive_node_client.GENESIS_ADDR, archive_node_client.EPOCH_NUM(i)) assert_equal(full_balance, archive_balance) # Blocks within execution defer (5 epochs) and reward_defer (12 epochs) do not have state_valid available_blocks = blocks_in_era[:-17] assert_blocks_valid(self.nodes[:-1], available_blocks) assert_blocks_valid(self.nodes[-1:], available_blocks)