code: def handle_receive_lockedtransfer(
          channel_state: NettingChannelState,
          mediated_transfer: LockedTransferSignedState,
  ) -> EventsOrError:
      
      events: List[Event]
      is_valid, msg, merkletree = is_valid_lockedtransfer(
          mediated_transfer,
          channel_state,
          channel_state.partner_state,
          channel_state.our_state,
      )
  
      if is_valid:
          assert merkletree, 'is_valid_lock_expired should return merkletree if valid'
          channel_state.partner_state.balance_proof = mediated_transfer.balance_proof
          channel_state.partner_state.merkletree = merkletree
  
          lock = mediated_transfer.lock
          channel_state.partner_state.secrethashes_to_lockedlocks[lock.secrethash] = lock
  
          send_processed = SendProcessed(
              recipient=mediated_transfer.balance_proof.sender,
              channel_identifier=CHANNEL_IDENTIFIER_GLOBAL_QUEUE,
              message_identifier=mediated_transfer.message_identifier,
          )
          events = [send_processed]
      else:
          assert msg, 'is_valid_lock_expired should return error msg if not valid'
          invalid_locked = EventInvalidReceivedLockedTransfer(
              payment_identifier=mediated_transfer.payment_identifier,
              reason=msg,
          )
          events = [invalid_locked]
  
      return is_valid, events, msg
docs: Register the latest known transfer.
  
      The receiver needs to use this method to update the container with a
      _valid_ transfer, otherwise the locksroot will not contain the pending
      transfer. The receiver needs to ensure that the merkle root has the
      secrethash included, otherwise it won't be able to claim it.