def _add_onchain_locksroot_to_channel_settled_state_changes(
        raiden: RaidenService,
        storage: SQLiteStorage,
) -> None:
    """ Adds `our_onchain_locksroot` and `partner_onchain_locksroot` to
    ContractReceiveChannelSettled. """
    batch_size = 50
    batch_query = storage.batch_query_state_changes(
        batch_size=batch_size,
        filters=[
            ('_type', 'raiden.transfer.state_change.ContractReceiveChannelSettled'),
        ],
    )
    for state_changes_batch in batch_query:
        updated_state_changes = list()
        for state_change in state_changes_batch:
            state_change_data = json.loads(state_change.data)
            msg = 'v18 state changes cant contain our_onchain_locksroot'
            assert 'our_onchain_locksroot' not in state_change_data, msg

            msg = 'v18 state changes cant contain partner_onchain_locksroot'
            assert 'partner_onchain_locksroot' not in state_change_data, msg

            token_network_identifier = state_change_data['token_network_identifier']
            channel_identifier = state_change_data['channel_identifier']

            channel_new_state_change = _find_channel_new_state_change(
                storage=storage,
                token_network_address=token_network_identifier,
                channel_identifier=channel_identifier,
            )

            if not channel_new_state_change.data:
                raise RaidenUnrecoverableError(
                    f'Could not find the state change for channel {channel_identifier}, '
                    f'token network address: {token_network_identifier} being created. ',
                )

            channel_state_data = json.loads(channel_new_state_change.data)
            new_channel_state = channel_state_data['channel_state']

            canonical_identifier = CanonicalIdentifier(
                chain_identifier=-1,
                token_network_address=to_canonical_address(token_network_identifier),
                channel_identifier=int(channel_identifier),
            )
            our_locksroot, partner_locksroot = get_onchain_locksroots(
                chain=raiden.chain,
                canonical_identifier=canonical_identifier,
                participant1=to_canonical_address(new_channel_state['our_state']['address']),
                participant2=to_canonical_address(new_channel_state['partner_state']['address']),
                block_identifier='latest',
            )

            state_change_data['our_onchain_locksroot'] = serialize_bytes(
                our_locksroot,
            )
            state_change_data['partner_onchain_locksroot'] = serialize_bytes(
                partner_locksroot,
            )

            updated_state_changes.append((
                json.dumps(state_change_data),
                state_change.state_change_identifier,
            ))
        storage.update_state_changes(updated_state_changes)
Adds `our_onchain_locksroot` and `partner_onchain_locksroot` to
    ContractReceiveChannelSettled.