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

Add constraints field to TransactionLayer #2620

Merged

Conversation

jonathanknowles
Copy link
Member

@jonathanknowles jonathanknowles commented Apr 23, 2021

Issue Number

ADP-839

Overview

This PR:

  • adds field constraints of type TxConstraints to the TransactionLayer record type.
  • adds an implementation of constraints to Shelley.Transaction.TransactionLayer.
  • adds property tests to demonstrate the correctness of Shelley.Transaction.TransactionLayer.constraints.

Refactoring

This PR also:

  • makes TxSize into a concrete type exported by Primitive.Types.Tx.
  • removes calcMinimumCoinValue from TransactionLayer, as TxConstraints.txOutputMinimumAdaQuantity makes this redundant.

Future work

This PR will make it possible to:

  • remove tokenBundleSizeAssessor from TransactionLayer, as TxConstraints.txOutputMaximumSize makes this redundant.

@jonathanknowles jonathanknowles force-pushed the jonathanknowles/multi-asset-migration-transaction-layer branch from 356242e to 20c3255 Compare April 23, 2021 09:28
@jonathanknowles jonathanknowles changed the title Add txConstraints field to TransactionLayer Add constraints field to TransactionLayer Apr 23, 2021
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/multi-asset-migration-transaction-layer branch from 20c3255 to 1cf1668 Compare April 23, 2021 10:06
@jonathanknowles jonathanknowles self-assigned this Apr 23, 2021
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/multi-asset-migration-transaction-layer branch from 1cf1668 to 93eab53 Compare April 26, 2021 04:57
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/multi-asset-migration-transaction-layer branch 13 times, most recently from 36a01a8 to d98beeb Compare April 28, 2021 05:43
@jonathanknowles jonathanknowles marked this pull request as ready for review April 28, 2021 06:30
Copy link
Collaborator

@Anviking Anviking left a comment

Choose a reason for hiding this comment

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

lgtm!

@@ -540,45 +550,82 @@ _decodeSignedTx era bytes = do
_ ->
Left ErrDecodeSignedTxNotSupported

data TxSkeleton = TxSkeleton
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might as well put the

his record type includes the minimal set of fields that are absolutely
necessary for the estimateTxSize function to perform its calculations,
and nothing else.

As such, the fields of TxSkeleton contain a subset of the data included
in the union of SelectionSkeleton and TransactionCtx.

From the commit message as a doc comment here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah good point! I'll add some comments in there. 👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in d7ff662.

-- between 'txOutputSize' and 'txOutputMaximumSize' should also indicate that
-- the bundle is oversized.
--
prop_txConstraints_txOutputMaximumSize :: Large TokenBundle -> Property
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

-- selection produces a result that is consistent with the result of using
-- 'estimateTxCost'.
--
prop_txConstraints_txCost :: MockSelection -> Property
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@jonathanknowles
Copy link
Member Author

bors r+

iohk-bors bot added a commit that referenced this pull request Apr 29, 2021
2620: Add `constraints` field to `TransactionLayer` r=jonathanknowles a=jonathanknowles

# Issue Number

ADP-839

# Overview

This PR:

- [x] adds field `constraints` of type `TxConstraints` to the `TransactionLayer` record type.
- [x] adds an implementation of `constraints` to `Shelley.Transaction.TransactionLayer`.
- [x] adds property tests to demonstrate the correctness of `Shelley.Transaction.TransactionLayer.constraints`.

# Refactoring

This PR also:

- [x] makes `TxSize` into a concrete type exported by `Primitive.Types.Tx`.
- [x] removes `calcMinimumCoinValue` from `TransactionLayer`, as `TxConstraints.txOutputMinimumAdaQuantity` makes this redundant.

# Future work

This PR will make it possible to:

- remove `tokenBundleSizeAssessor` from `TransactionLayer`, as `TxConstraints.txOutputMaximumSize` makes this redundant.


Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Apr 29, 2021

Build failed:

Looks like this was a cache failure.

@jonathanknowles
Copy link
Member Author

bors r+

iohk-bors bot added a commit that referenced this pull request Apr 29, 2021
2620: Add `constraints` field to `TransactionLayer` r=jonathanknowles a=jonathanknowles

# Issue Number

ADP-839

# Overview

This PR:

- [x] adds field `constraints` of type `TxConstraints` to the `TransactionLayer` record type.
- [x] adds an implementation of `constraints` to `Shelley.Transaction.TransactionLayer`.
- [x] adds property tests to demonstrate the correctness of `Shelley.Transaction.TransactionLayer.constraints`.

# Refactoring

This PR also:

- [x] makes `TxSize` into a concrete type exported by `Primitive.Types.Tx`.
- [x] removes `calcMinimumCoinValue` from `TransactionLayer`, as `TxConstraints.txOutputMinimumAdaQuantity` makes this redundant.

# Future work

This PR will make it possible to:

- remove `tokenBundleSizeAssessor` from `TransactionLayer`, as `TxConstraints.txOutputMaximumSize` makes this redundant.


Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Apr 29, 2021

Build failed:

Looks like this was a cache failure.

After rerunning some of the tests, I ran into this failure: (https://hydra.iohk.io/build/6207105/nixlog/1/tail)

Failures:

 test/unit/Network/Wai/Middleware/LoggingSpec.hs:206:9:
 1) Network.Wai.Middleware.Logging, Logging Middleware, GET, 503
      uncaught exception: HttpException
      HttpExceptionRequest Request {
        host                 = "localhost"
        port                 = 54393
        secure               = False
        requestHeaders       = []
        path                 = "/error503"
        queryString          = ""
        method               = "GET"
        proxy                = Nothing
        rawBody              = False
        redirectCount        = 10
        responseTimeout      = ResponseTimeoutDefault
        requestVersion       = HTTP/1.1
      }
       ConnectionTimeout

 To rerun use: --match "/Network.Wai.Middleware.Logging/Logging Middleware/GET, 503/"

Randomized with seed 1415537019

Looks like a instance of:

#2368
#2217

@jonathanknowles jonathanknowles force-pushed the jonathanknowles/multi-asset-migration-transaction-layer branch from 2099f94 to c9470ca Compare April 29, 2021 12:27
@jonathanknowles
Copy link
Member Author

bors r+

@rvl
Copy link
Contributor

rvl commented Apr 29, 2021

bors r-

Let's do the release first, then try to merge this.

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Apr 29, 2021

Canceled.

@jonathanknowles
Copy link
Member Author

bors r+

iohk-bors bot added a commit that referenced this pull request Apr 29, 2021
2620: Add `constraints` field to `TransactionLayer` r=jonathanknowles a=jonathanknowles

# Issue Number

ADP-839

# Overview

This PR:

- [x] adds field `constraints` of type `TxConstraints` to the `TransactionLayer` record type.
- [x] adds an implementation of `constraints` to `Shelley.Transaction.TransactionLayer`.
- [x] adds property tests to demonstrate the correctness of `Shelley.Transaction.TransactionLayer.constraints`.

# Refactoring

This PR also:

- [x] makes `TxSize` into a concrete type exported by `Primitive.Types.Tx`.
- [x] removes `calcMinimumCoinValue` from `TransactionLayer`, as `TxConstraints.txOutputMinimumAdaQuantity` makes this redundant.

# Future work

This PR will make it possible to:

- remove `tokenBundleSizeAssessor` from `TransactionLayer`, as `TxConstraints.txOutputMaximumSize` makes this redundant.


Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
@jonathanknowles
Copy link
Member Author

bors r-

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Apr 30, 2021

Canceled.

…ve.Tx`.

Ultimately, transaction sizes are all expressible in terms of natural
numbers, regardless of whether the sizes are expressed in terms of
bytes, or in terms of some other unit.

So there's currently little need for a type class abstraction here, when
a newtype will suffice.
The purpose of `SelectionSkeleton` is to provide all the data necessary
to calculate the fee associated with a selection.

However, this calculation only depends on the number of inputs, and not
the contents of each input.

Therefore, it's only necessary to include a count of the selected inputs
within `SelectionSkeleton`, and unnecessary to include the actual inputs
themselves.
…on` prefix.

This makes the record field names a bit more consistent.
This record type includes the minimal set of fields that are absolutely
necessary for the `estimateTxSize` function to perform its calculations,
and nothing else.

As such, the fields of `TxSkeleton` contain a subset of the data included
in the union of `SelectionSkeleton` and `TransactionCtx`.

Using this type means that future tests for `estimateTxSize` will only
need to supply values that will actually be used by the function,
simplifying the effort to write tests.
This will allow it to be tested in conjunction with `txConstraints`.
The `constraints` field provides a value of `TxConstraints`.
Replace these uses with `constraints.txOutputMinimumAdaQuantity`.
We probably want to avoid spamming the test log with the output of
`show` for very large token bundles. We already have a large set of
counterexample data.

In response to review feedback:

https://github.com/input-output-hk/cardano-wallet/pull/2620/files#r622669907
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/multi-asset-migration-transaction-layer branch from c9470ca to e687560 Compare April 30, 2021 00:11
@rvl
Copy link
Contributor

rvl commented Apr 30, 2021

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Apr 30, 2021

Build succeeded:

@iohk-bors iohk-bors bot merged commit 182e864 into master Apr 30, 2021
@iohk-bors iohk-bors bot deleted the jonathanknowles/multi-asset-migration-transaction-layer branch April 30, 2021 04:19
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