I'm reading "mastering bitcoin" and got into transaction validation.
Can you explain to me what is the meaning of "A matching transaction in the pool, or in a block in the main branch, must exist." ?
In order for a transaction to be valid all of the outputs it spends must also be valid as well. Before accepting a transaction into the memory pool or accepting it into it's local block chain, one of the checks is to ensure all of it's parents are available to be spent.
If an unconfirmed transaction sent via the network is received and it's parent outputs do not exist, it is ignored or placed in a holding pool to wait and see if it's parent outputs might become available in the future.
If a block contains a transaction for which the outputs it is spending do not exist or are invalid, then the entire block is invalid and it is discarded. Any node sending you an invalid block like this is wasting your node's time and is banned as a result.