Source of the datum in the validator function

Hi there,

my question is simple: in the validator function where does the datum get provided from?

I noticed when we are constructing a transaction in the off-chain code we for instance say:
utxos ← utxosAt scrAddress
… which gives us a Map where the keys are of type ChainIndexTxOut and contain either a datum hash or the actual datum for every UTXO of the Map.

Now when we submit a transaction we define the lookups usually as:
lookups = Constraints.unspentOutputs utxos
… that gives us a type of ScriptLookups which contains a Map in slOtherData of datum hashes and datums.

So my question is in the validator function does the datum come from this Map in the lookups? And if yes how does the Map from the utxos parameter that contains either a hash or the actual datum translate to the Map in the lookups that de-facto contains both hashes and datums.

And then we have also the ScriptContext that in the TxInfo element also contains a list of datum hashes and datums inside txInfoData. Where does this data comes from when we construct a transaction?

In the plutus pioneer program it was said that for producing transactions the txInfoData parameter is optional, whereas for spending transactions it is mandatory. But I never noticed that we specify any datums when we construct a spending transaction.

Cheers,
Luka