|
| 1 | +# Determinism |
| 2 | + |
| 3 | +An important principle that occurs in a few places throughout the Cardano ledger |
| 4 | +is that of determinism. Perhaps one way to summarise is would be to say: "the |
| 5 | +transaction is all you need" - that is, when trying to compute the results of |
| 6 | +a transaction, you need only look at the transaction itself rather than |
| 7 | +computing with the full ledger state. |
| 8 | + |
| 9 | +There are two important instantiations of this principle: |
| 10 | + |
| 11 | +## Transaction Determinism |
| 12 | + |
| 13 | +This instance tells us that, given a transaction is valid, its outputs are |
| 14 | +determined fully by the transaction itself. It may be necessary to look at |
| 15 | +certain parts of the ledger state to determine whether it is valid - for |
| 16 | +example, to check that the inputs have not been spent - but assuming it is |
| 17 | +valid, the outputs created will be exactly as described in the transaction. |
| 18 | + |
| 19 | +## Script determinism |
| 20 | + |
| 21 | +This instance tells us that, assuming a transaction passes phase 1 validation, |
| 22 | +the validity of a script is determined only by data contained in the transaction |
| 23 | +and in the transaction outputs that it spends or references. |
| 24 | + |
| 25 | +## Implications for Node Implementors |
| 26 | + |
| 27 | +These properties allow node implementors to safely make certain assumptions |
| 28 | +which can speed up transaction and block processing. |
| 29 | + |
| 30 | +1. When processing historical blocks, nodes need only consider (or even |
| 31 | + deserialise) [transaction bodies](./blocks.md), since the rest of the |
| 32 | + block payload can only impact the block _validity_, which is already known |
| 33 | + for historical blocks. |
| 34 | +2. Many of the more expensive checks of transaction validity need only be |
| 35 | + carried out once. In particular, the cryptographic verification and script |
| 36 | + execution need only be carried out once, when the transaction first enters |
| 37 | + the mempool. Subsequently it is required only to check that the inputs still |
| 38 | + exist. |
| 39 | + |
| 40 | +To take advantage of these properties, ledger implementers must distinguish |
| 41 | +between these checks in the ledger in such a way as to allow transactions to be |
| 42 | +(re-)processed without repeating expensive computation. |
0 commit comments