async def _reconsider_peak(self, block_record: BlockRecord, genesis: bool, fork_point_with_peak: Optional[uint32], npc_result: Optional[NPCResult]) -> Tuple[(Optional[uint32], Optional[uint32], List[BlockRecord], Tuple[(List[CoinRecord], Dict[(bytes, Dict[(bytes32, CoinRecord)])])])]:
    '\n        When a new block is added, this is called, to check if the new block is the new peak of the chain.\n        This also handles reorgs by reverting blocks which are not in the heaviest chain.\n        It returns the height of the fork between the previous chain and the new chain, or returns\n        None if there was no update to the heaviest chain.\n        '
    peak = self.get_peak()
    lastest_coin_state: Dict[(bytes32, CoinRecord)] = {}
    hint_coin_state: Dict[(bytes32, Dict[(bytes32, CoinRecord)])] = {}
    if genesis:
        if (peak is None):
            block: Optional[FullBlock] = (await self.block_store.get_full_block(block_record.header_hash))
            assert (block is not None)
            if (npc_result is not None):
                (tx_removals, tx_additions) = tx_removals_and_additions(npc_result.npc_list)
            else:
                (tx_removals, tx_additions) = ([], [])
            if block.is_transaction_block():
                assert (block.foliage_transaction_block is not None)
                added = (await self.coin_store.new_block(block.height, block.foliage_transaction_block.timestamp, block.get_included_reward_coins(), tx_additions, tx_removals))
            else:
                (added, _) = ([], [])
            (await self.block_store.set_peak(block_record.header_hash))
            return (uint32(0), uint32(0), [block_record], (added, {}))
        return (None, None, [], ([], {}))
    assert (peak is not None)
    if (block_record.weight > peak.weight):
        if (block_record.prev_hash == peak.header_hash):
            fork_height: int = peak.height
        elif (fork_point_with_peak is not None):
            fork_height = fork_point_with_peak
        else:
            fork_height = find_fork_point_in_chain(self, block_record, peak)
        if (block_record.prev_hash != peak.header_hash):
            roll_changes: List[CoinRecord] = (await self.coin_store.rollback_to_block(fork_height))
            for coin_record in roll_changes:
                lastest_coin_state[coin_record.name] = coin_record
        heights_to_delete = []
        for ses_included_height in self.__sub_epoch_summaries.keys():
            if (ses_included_height > fork_height):
                heights_to_delete.append(ses_included_height)
        for height in heights_to_delete:
            log.info(f'delete ses at height {height}')
            del self.__sub_epoch_summaries[height]
        blocks_to_add: List[Tuple[(FullBlock, BlockRecord)]] = []
        curr = block_record.header_hash
        while ((fork_height < 0) or (curr != self.height_to_hash(uint32(fork_height)))):
            fetched_full_block: Optional[FullBlock] = (await self.block_store.get_full_block(curr))
            fetched_block_record: Optional[BlockRecord] = (await self.block_store.get_block_record(curr))
            assert (fetched_full_block is not None)
            assert (fetched_block_record is not None)
            blocks_to_add.append((fetched_full_block, fetched_block_record))
            if (fetched_full_block.height == 0):
                break
            curr = fetched_block_record.prev_hash
        records_to_add = []
        for (fetched_full_block, fetched_block_record) in reversed(blocks_to_add):
            records_to_add.append(fetched_block_record)
            if fetched_full_block.is_transaction_block():
                if (fetched_block_record.header_hash == block_record.header_hash):
                    (tx_removals, tx_additions, npc_res) = (await self.get_tx_removals_and_additions(fetched_full_block, npc_result))
                else:
                    (tx_removals, tx_additions, npc_res) = (await self.get_tx_removals_and_additions(fetched_full_block, None))
                assert (fetched_full_block.foliage_transaction_block is not None)
                added_rec = (await self.coin_store.new_block(fetched_full_block.height, fetched_full_block.foliage_transaction_block.timestamp, fetched_full_block.get_included_reward_coins(), tx_additions, tx_removals))
                removed_rec: List[Optional[CoinRecord]] = [(await self.coin_store.get_coin_record(name)) for name in tx_removals]
                record: Optional[CoinRecord]
                for record in added_rec:
                    assert record
                    lastest_coin_state[record.name] = record
                for record in removed_rec:
                    assert record
                    lastest_coin_state[record.name] = record
                if (npc_res is not None):
                    hint_list: List[Tuple[(bytes32, bytes)]] = self.get_hint_list(npc_res)
                    (await self.hint_store.add_hints(hint_list))
                    for (coin_id, hint) in hint_list:
                        key = hint
                        if (key not in hint_coin_state):
                            hint_coin_state[key] = {}
                        hint_coin_state[key][coin_id] = lastest_coin_state[coin_id]
        (await self.block_store.set_peak(block_record.header_hash))
        return (uint32(max(fork_height, 0)), block_record.height, records_to_add, (list(lastest_coin_state.values()), hint_coin_state))
    return (None, None, [], ([], {}))
When a new block is added, this is called, to check if the new block is the new peak of the chain.
This also handles reorgs by reverting blocks which are not in the heaviest chain.
It returns the height of the fork between the previous chain and the new chain, or returns
None if there was no update to the heaviest chain.
async def _reconsider_peak(self, block_record: BlockRecord, genesis: bool, fork_point_with_peak: Optional[uint32], npc_result: Optional[NPCResult]) -> Tuple[(Optional[uint32], Optional[uint32], List[BlockRecord], Tuple[(List[CoinRecord], Dict[(bytes, Dict[(bytes32, CoinRecord)])])])]:
    '\n        When a new block is added, this is called, to check if the new block is the new peak of the chain.\n        This also handles reorgs by reverting blocks which are not in the heaviest chain.\n        It returns the height of the fork between the previous chain and the new chain, or returns\n        None if there was no update to the heaviest chain.\n        '
    peak = self.get_peak()
    lastest_coin_state: Dict[(bytes32, CoinRecord)] = {}
    hint_coin_state: Dict[(bytes32, Dict[(bytes32, CoinRecord)])] = {}
    if genesis:
        if (peak is None):
            block: Optional[FullBlock] = (await self.block_store.get_full_block(block_record.header_hash))
            assert (block is not None)
            if (npc_result is not None):
                (tx_removals, tx_additions) = tx_removals_and_additions(npc_result.npc_list)
            else:
                (tx_removals, tx_additions) = ([], [])
            if block.is_transaction_block():
                assert (block.foliage_transaction_block is not None)
                added = (await self.coin_store.new_block(block.height, block.foliage_transaction_block.timestamp, block.get_included_reward_coins(), tx_additions, tx_removals))
            else:
                (added, _) = ([], [])
            (await self.block_store.set_peak(block_record.header_hash))
            return (uint32(0), uint32(0), [block_record], (added, {}))
        return (None, None, [], ([], {}))
    assert (peak is not None)
    if (block_record.weight > peak.weight):
        if (block_record.prev_hash == peak.header_hash):
            fork_height: int = peak.height
        elif (fork_point_with_peak is not None):
            fork_height = fork_point_with_peak
        else:
            fork_height = find_fork_point_in_chain(self, block_record, peak)
        if (block_record.prev_hash != peak.header_hash):
            roll_changes: List[CoinRecord] = (await self.coin_store.rollback_to_block(fork_height))
            for coin_record in roll_changes:
                lastest_coin_state[coin_record.name] = coin_record
        heights_to_delete = []
        for ses_included_height in self.__sub_epoch_summaries.keys():
            if (ses_included_height > fork_height):
                heights_to_delete.append(ses_included_height)
        for height in heights_to_delete:
            log.info(f'delete ses at height {height}')
            del self.__sub_epoch_summaries[height]
        blocks_to_add: List[Tuple[(FullBlock, BlockRecord)]] = []
        curr = block_record.header_hash
        while ((fork_height < 0) or (curr != self.height_to_hash(uint32(fork_height)))):
            fetched_full_block: Optional[FullBlock] = (await self.block_store.get_full_block(curr))
            fetched_block_record: Optional[BlockRecord] = (await self.block_store.get_block_record(curr))
            assert (fetched_full_block is not None)
            assert (fetched_block_record is not None)
            blocks_to_add.append((fetched_full_block, fetched_block_record))
            if (fetched_full_block.height == 0):
                break
            curr = fetched_block_record.prev_hash
        records_to_add = []
        for (fetched_full_block, fetched_block_record) in reversed(blocks_to_add):
            records_to_add.append(fetched_block_record)
            if fetched_full_block.is_transaction_block():
                if (fetched_block_record.header_hash == block_record.header_hash):
                    (tx_removals, tx_additions, npc_res) = (await self.get_tx_removals_and_additions(fetched_full_block, npc_result))
                else:
                    (tx_removals, tx_additions, npc_res) = (await self.get_tx_removals_and_additions(fetched_full_block, None))
                assert (fetched_full_block.foliage_transaction_block is not None)
                added_rec = (await self.coin_store.new_block(fetched_full_block.height, fetched_full_block.foliage_transaction_block.timestamp, fetched_full_block.get_included_reward_coins(), tx_additions, tx_removals))
                removed_rec: List[Optional[CoinRecord]] = [(await self.coin_store.get_coin_record(name)) for name in tx_removals]
                record: Optional[CoinRecord]
                for record in added_rec:
                    assert record
                    lastest_coin_state[record.name] = record
                for record in removed_rec:
                    assert record
                    lastest_coin_state[record.name] = record
                if (npc_res is not None):
                    hint_list: List[Tuple[(bytes32, bytes)]] = self.get_hint_list(npc_res)
                    (await self.hint_store.add_hints(hint_list))
                    for (coin_id, hint) in hint_list:
                        key = hint
                        if (key not in hint_coin_state):
                            hint_coin_state[key] = {}
                        hint_coin_state[key][coin_id] = lastest_coin_state[coin_id]
        (await self.block_store.set_peak(block_record.header_hash))
        return (uint32(max(fork_height, 0)), block_record.height, records_to_add, (list(lastest_coin_state.values()), hint_coin_state))
    return (None, None, [], ([], {}))