<p>Datums are stored in a hash map per transaction, so if a transaction uses the same datum multiple times, the datum is stored once and only the hashes are stored multiple times. The same goes for redeemers.</p>
<p>(I don't understand all the questions, but this is at least a partial answer. Feel free to add to this answer.)</p>

CC BY-SA 4.0
2022-01-24T11:47:56.980Z
Thank you Sjoerd, This clears things up about the whole "efficient handling of data" in a transaction of datums. Am I correct that you can extend this hash map idea for the redeemer and script as well?
Fermat
CC BY-SA 4.0
2022-01-24T16:28:09.773Z
@Fermat Indeed.
Sjoerd Visscher
CC BY-SA 4.0
2022-01-24T11:25:18.617Z
2022-01-24T11:25:18.617Z
Sjoerd Visscher
<p>I don't have good knowledge of ledger rules, but I can refer to TxInfo data type in <a href="https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Contexts.html" rel="nofollow noreferrer">Plutus</a></p>
<pre><code>data TxInfo = TxInfo
    { txInfoInputs          :: [TxInInfo] -- ^ Transaction inputs
    , txInfoReferenceInputs :: [TxInInfo] -- ^ Transaction reference inputs
    , txInfoOutputs         :: [TxOut] -- ^ Transaction outputs
    , txInfoFee             :: Value -- ^ The fee paid by this transaction.
    , txInfoMint            :: Value -- ^ The 'Value' minted by this transaction.
    , txInfoDCert           :: [DCert] -- ^ Digests of certificates included in this transaction
    , txInfoWdrl            :: Map StakingCredential Integer -- ^ Withdrawals
    , txInfoValidRange      :: POSIXTimeRange -- ^ The valid range for the transaction.
    , txInfoSignatories     :: [PubKeyHash] -- ^ Signatures provided with the transaction, attested that they all signed the tx
    , txInfoRedeemers       :: Map ScriptPurpose Redeemer
    , txInfoData            :: Map DatumHash Datum
    , txInfoId              :: TxId
    -- ^ Hash of the pending transaction (excluding witnesses)
    }
</code></pre>
<p>Here you can see that you need to provide Datum only once per each DatumHash, but for outputs, you need to provide a list [TxOut] with DatumHash in each list item. Redeemers should be provided for each UTxO you are trying to spend.</p>
<p>Regarding contracts, you need to attach script only once even if validating multiple UTxOs.</p>
<p>My answers are based on practical experience, so I may be wrong from Ledger perspective.</p>

CC BY-SA 4.0
2023-02-07T21:30:11.700Z
2023-02-07T21:30:11.700Z
Liotcheg
<p>I have an in-depth question that needs good knowledge of the ledger rules.</p>
<p>I was thinking about how to program efficiently and design apps such that they are parallelizable, a good practice for achieving this is building modular and piece wise. While thinking about certain contracts that could validate in parallel I wondered how such transactions are build and specified for validation. This is not a canonical task and can be ambiguous for a validator. So a natural conclusion is that to preserve determinism one has to fully specify a transaction, some question on this specification.</p>
<p>Consider a transaction that tries to consume <code>n</code> eUTxO's of contract instance A and <code>m</code> of the contract instance B. Then this transaction has to have <code>n+m</code> datums that match the inputs.</p>
<p>Question 1: Do you specify in your transaction which datum corresponds to which input or does the validator node matches them by hashing your suggested datum? Also, if certain datums match, can you save on transaction size by appending the datum once and specifying the datum to each input?</p>
<p>Question 2: Do you append the contracts A and B multiple time (<code>n+m</code> times to be exact) to the transaction or just once for each occurrence? Again, the latter would save on transaction size.</p>
<p>Now there is also another integral part of consuming eUTxO's, namely their redeemers. Since each eUTxO generally have a different redeemer one also has to specify which redeemer is associated to which input.</p>
<p>Question 3: How is this association between redeemer en input specified in a transaction? And moreover, can this specification again be non-injective. That is, a redeemer can be appended once to the transaction but be associated to multiple inputs? This would again save on transaction size.</p>
<p>And lastly we have the outputs where we give each one a possible new datum. These new datums, how are the specified and can they be assigned in a non-injective way to save on transaction size?</p>

<plutus><plutus-pioneer-program><smart-contract><validation><transactions-per-second>
on multiple eUTxO and the validation proces
# on multiple eUTxO and the validation proces

(Asked by: username_0 on 2022-01-24)

I have an in-depth question that needs good knowledge of the ledger rules.

I was thinking about how to program efficiently and design apps such that they are parallelizable, a good practice for achieving this is building modular and piece wise. While thinking about certain contracts that could validate in parallel I wondered how such transactions are build and specified for validation. This is not a canonical task and can be ambiguous for a validator. So a natural conclusion is that to preserve determinism one has to fully specify a transaction, some question on this specification.

Consider a transaction that tries to consume `n` eUTxO's of contract instance A and `m` of the contract instance B. Then this transaction has to have `n+m` datums that match the inputs.

Question 1: Do you specify in your transaction which datum corresponds to which input or does the validator node matches them by hashing your suggested datum? Also, if certain datums match, can you save on transaction size by appending the datum once and specifying the datum to each input?

Question 2: Do you append the contracts A and B multiple time (`n+m` times to be exact) to the transaction or just once for each occurrence? Again, the latter would save on transaction size.

Now there is also another integral part of consuming eUTxO's, namely their redeemers. Since each eUTxO generally have a different redeemer one also has to specify which redeemer is associated to which input.

Question 3: How is this association between redeemer en input specified in a transaction? And moreover, can this specification again be non-injective. That is, a redeemer can be appended once to the transaction but be associated to multiple inputs? This would again save on transaction size.

And lastly we have the outputs where we give each one a possible new datum. These new datums, how are the specified and can they be assigned in a non-injective way to save on transaction size?

**Tags:** plutus, plutus-pioneer-program, smart-contract, validation, transactions-per-second

---

## 2 answers

### Answer by username_1 on 2022-01-24. Score: 3 | Accepted answer

Datums are stored in a hash map per transaction, so if a transaction uses the same datum multiple times, the datum is stored once and only the hashes are stored multiple times. The same goes for redeemers.

(I don't understand all the questions, but this is at least a partial answer. Feel free to add to this answer.)

> **Comments:**
> **username_0**: Thank you Sjoerd, This clears things up about the whole "efficient handling of data" in a transaction of datums. Am I correct that you can extend this hash map idea for the redeemer and script as well?  
> **username_1**: @Fermat Indeed.  

---

### Answer by username_2 on 2023-02-07. Score: 0

I don't have good knowledge of ledger rules, but I can refer to TxInfo data type in Plutus
data TxInfo = TxInfo
    { txInfoInputs          :: [TxInInfo] -- ^ Transaction inputs
    , txInfoReferenceInputs :: [TxInInfo] -- ^ Transaction reference inputs
    , txInfoOutputs         :: [TxOut] -- ^ Transaction outputs
    , txInfoFee             :: Value -- ^ The fee paid by this transaction.
    , txInfoMint            :: Value -- ^ The 'Value' minted by this transaction.
    , txInfoDCert           :: [DCert] -- ^ Digests of certificates included in this transaction
    , txInfoWdrl            :: Map StakingCredential Integer -- ^ Withdrawals
    , txInfoValidRange      :: POSIXTimeRange -- ^ The valid range for the transaction.
    , txInfoSignatories     :: [PubKeyHash] -- ^ Signatures provided with the transaction, attested that they all signed the tx
    , txInfoRedeemers       :: Map ScriptPurpose Redeemer
    , txInfoData            :: Map DatumHash Datum
    , txInfoId              :: TxId
    -- ^ Hash of the pending transaction (excluding witnesses)
    }

Here you can see that you need to provide Datum only once per each DatumHash, but for outputs, you need to provide a list [TxOut] with DatumHash in each list item. Redeemers should be provided for each UTxO you are trying to spend.
Regarding contracts, you need to attach script only once even if validating multiple UTxOs.
My answers are based on practical experience, so I may be wrong from Ledger perspective.


---

