Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign of Tx/TxInBlock #2379

Merged
merged 7 commits into from Jul 21, 2021
Merged

Redesign of Tx/TxInBlock #2379

merged 7 commits into from Jul 21, 2021

Conversation

nc6
Copy link
Contributor

@nc6 nc6 commented Jul 12, 2021

This comes out of discussions with the consensus team. Rather than sending basic Shelley transactions around and computing the IsValidating field at the node level, we instead require consumers to compute their own IsValidating field. This is then verified as usual, and the node is required to verify this. Depending on the configuration, the node may choose to do different things with the transaction if the flag is set incorrectly.

This may be reviewed commit by commit; they should all stand alone.

Copy link
Contributor

@nfrisby nfrisby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I'll integrate against it today on my branch and report back.


In one of the commit messages:

Drop 'TxInBlock' and use Core.Tx family.

Since Tx will now be what is submitted by the wallet/node, ...

Is there a typo in that sentence fragment? It reads like "now that X is true" but X already was true. I was expecting something like "now that Tx (ie what the wallet/node submits) contains the same data as TxInBlock, ...`

-- Conditions to define the rule in this Era
HasField "_d" (Core.PParams era) UnitInterval,
HasField "_maxBlockExUnits" (Core.PParams era) ExUnits,
Era era, -- supplies WellFormed HasField, and Crypto constraints
Era.TxSeq era ~ Alonzo.TxSeq era,
Era.TxInBlock era ~ Alonzo.ValidatedTx era,
Core.Tx era ~ Alonzo.ValidatedTx era,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we discussed this on a call, but I'll risk repeating my opinion. ValidatedTx seems like a misnomer. EG Core.Tx is the type of a transaction that we just deserialized from the network; we haven't had a chancee to validate it beyond "does it deserialize".

On the other hand, it does carry a flag, so at least someone is claiming to have validated it.

No particular action requested, just pointing out an awkwardness/opportunity for confusion.

Edit: looking ahead, I see that we'll indirectly have Validated Alonzo.ValidatedTx in the new mempool API, eg.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry, the thing I forgot to do in this branch was rename ValidatedTx, I agree that it's now a bad name!

Copy link
Contributor

@nfrisby nfrisby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a branch on which the non-testing code compiles against this PR's branch. I'm requesting changes based on a couple discovered requirements re the Validated newtype.

@nc6 nc6 force-pushed the nc/alonzo-tx branch 2 times, most recently from b3d337d to 0b8fae3 Compare July 15, 2021 12:08
@nc6 nc6 force-pushed the nc/alonzo-tx branch 3 times, most recently from 8dff99f to a6ab504 Compare July 16, 2021 09:13
@nc6
Copy link
Contributor Author

nc6 commented Jul 19, 2021

@nfrisby Is this ok for you now?

@nc6 nc6 requested a review from JaredCorduan July 19, 2021 12:43
@nfrisby
Copy link
Contributor

nfrisby commented Jul 19, 2021

@nfrisby Is this ok for you now?

I think so. I'll be able to confirm that today.

trustMe :: Bool -> Core.Tx A -> ValidatedTx A
trustMe v (Core.Tx b w a) = ValidatedTx b w (IsValidating v) a
trustMe :: Bool -> ValidatedTx A -> ValidatedTx A
trustMe iv' (ValidatedTx b w _ m) = ValidatedTx b w (IsValidating iv') m
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you do not need this function anymore, the tests can just stamp the correct IsValidating field directly.

Copy link
Contributor

@JaredCorduan JaredCorduan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my end, I think this looks great! It's a nice simplification.

@nfrisby
Copy link
Contributor

nfrisby commented Jul 20, 2021

OK, I have my downstream PR working with this PR right now, except for one last hurdle.

One of my tests isn't compiling, and I think the fix would be to change the type of sleTx to Core.Tx. IE the sleTx for Alonzo should have the flag in it.

https://github.com/input-output-hk/cardano-ledger-specs/blob/ea07de488ca85f1be17e7de7a1d12d4c7eeb8496/shelley/chain-and-ledger/shelley-spec-ledger-test/src/Test/Shelley/Spec/Ledger/Examples/Consensus.hs#L78-L81

https://github.com/input-output-hk/cardano-ledger-specs/blob/810298f87d91a8ab6573d10710baedf35825a3b5/alonzo/test/lib/Test/Cardano/Ledger/Alonzo/Examples/Consensus.hs#L59

(There is already an exampleTransactionInBlock in that module, and I think the sleTx field should now be set to that.)

Edit: if the module hierarchy makes this awkward (is cardano-ledger-core a build-dep of shelley-ledger-spec?), then I suppose you could just tell me how to convert from the current type of sleTx to Core.Tx (AlonzoEra c) and I could update my test code to do that.

nc6 added 5 commits July 20, 2021 16:01
The theme behind this change is that consensus (and the node, and
components above this) will regard an Alonzo Tx to be the full Tx,
including the `IsValidating` tag.

Where previously we exposed the unvarnished `Tx` and kept the
`TxInBlock` as a ledger-internal detail, we will now be doing the
opposite - exposing the full `TxInBlock`.
Since `Tx` will now be what is submitted by the wallet/node, there is no
need for a separate `TxInBlock` concept. Instead, `Tx` becomes a type
family (since it _will_ vary between eras) and everything is defined in
those terms.

As part of this, we alter the `SupportsSegWit` type class to reflect now
the isomorphism between `TxSeq` and `Seq Tx`.
This serialisation is only for use when transmitting Tx from node to
node, or wallet to node.
Previously, we used the Tx/TxInBlock distinction to also embody the fact
that a Tx had been validated, and hence future applications of that Tx
could skip a certain number of checks, an important performance concern.

Now we lack this distinction (which in any case was somewhat a
conflation of concerns), so we introduce the `Validated` newtype to
reflect this, and rewrite the Mempool API to reflect this.
We will drop this when downstream projects are updated.
nc6 added 2 commits July 20, 2021 17:16
Most of this is trivial. We modify `EraGen` to include a `constructTx`,
which creates a transaction from its constituent parts.
Approximately, for the 'TranslateEra' instance.
@nfrisby
Copy link
Contributor

nfrisby commented Jul 20, 2021

I can add flags to get around it, but currently my source-repo-driven-nix-build of cardano-ledger-alonzo is failing with

<no location info>: warning: [-Wunused-packages]
    The following packages were specified via -package or -package-id flags,
    but were not needed for compilation:
      - mtl-2.2.2
      - array-0.5.4.0

Edit: Nevermind, I hadn't noticed that the Plutus source-repo dep needed to be updated. All clear now.

Copy link
Contributor

@nfrisby nfrisby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now works for me. Thanks! Approved.

The only failures I'm now seeing are the result of the new serialization of Alonzo txs, totally expected.

@nc6 nc6 merged commit 136967c into master Jul 21, 2021
@iohk-bors iohk-bors bot deleted the nc/alonzo-tx branch July 21, 2021 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants