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 Shelley TransactionLayer #1673

Merged
merged 36 commits into from
May 30, 2020
Merged

Add Shelley TransactionLayer #1673

merged 36 commits into from
May 30, 2020

Conversation

Anviking
Copy link
Member

@Anviking Anviking commented May 18, 2020

Issue Number

#1672

Overview

  • Added toCardano conversion functions interacting with cardano-api
  • Fixed mistakes in existing conversion functions
  • Implemented Shelley TransactionLayer and enabled Wallet and Transaction integration tests.
  • Property test making sure estimateSize never underestimates

Comments

Main commit: 4f6ea17

-- without converting from @SlotId@.
let epochLength = EpochLength 1215

let Cardano.TxUnsignedShelley unsigned = Cardano.buildShelleyTransaction
Copy link
Member Author

@Anviking Anviking May 18, 2020

Choose a reason for hiding this comment

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

Would be nicer to use signTransaction.

But I thought the way cardano-crypto carries an encrypted XPrv and a password to the very end was intentional for… some security reasons? To construct SignKeyDSIGN we'd need to provide the unencrypted key.

Copy link
Member

@KtorZ KtorZ May 19, 2020

Choose a reason for hiding this comment

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

was intentional for… some security reasons

Partly. Having key encrypted in-memory was an explicit request from the previous development team which was several times depicted as useless by cryptographers. What matters is storing them encrypted (cf the wallet-chain-libs rust implementation). We still use cardano-crypto for lack of alternative.

@Anviking Anviking self-assigned this May 18, 2020
@Anviking Anviking force-pushed the anviking/ADP-319/shelley-txs branch from aa5ac1a to 5360a16 Compare May 20, 2020 15:49
@KtorZ KtorZ added the ADDING FEATURE Mark a PR as adding a new feature, for auto-generated CHANGELOG label May 20, 2020
@Anviking Anviking force-pushed the anviking/ADP-319/shelley-txs branch from 646cd23 to c066371 Compare May 20, 2020 18:36
@KtorZ KtorZ force-pushed the anviking/ADP-319/shelley-txs branch 3 times, most recently from 2183848 to a3df4c1 Compare May 22, 2020 16:29
@Anviking Anviking force-pushed the anviking/ADP-319/shelley-txs branch 2 times, most recently from 84e9ee4 to 32c2475 Compare May 25, 2020 17:22
@Anviking Anviking force-pushed the anviking/ADP-319/shelley-txs branch 7 times, most recently from 094c617 to 2145ca1 Compare May 28, 2020 13:39
@Anviking Anviking marked this pull request as ready for review May 28, 2020 13:39
@Anviking Anviking requested a review from KtorZ May 28, 2020 13:42
@Anviking
Copy link
Member Author

We could split this if desired, but I think it should be manageable.

let certs = []

-- TODO: The SlotId-SlotNo conversion based on epoch length would not
-- work if the epoch length changed in a hard fork.
Copy link
Member

Choose a reason for hiding this comment

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

Although, the transaction itself would be invalid before the hard-fork. True that, subsequent hardfork after shelley may be a risk but for Byron -> Shelley, there's no problem here if we know the new epoch length prior to the hardfork.

Copy link
Member Author

Choose a reason for hiding this comment

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

era  Byron | Shelley
el       3 | 2
epoch   0 1 2 3
=========================================
slot 0 |0 3 6 8
  V  1 |1 4 7 9
     2 |2 5

If we are here given a correct SlotId 3 1 at SlotNo 9 (which arguably would be unlikely, since there's a similar conversion to create the SlotId)

The we cannot simply convert back to SlotNo using the genesis epoch length (here 3):

(SlotNo 3*3+1) == (SlotNo 10)
But the correct answer is: SlotNo 9


-- TODO: The SlotId-SlotNo conversion based on epoch length would not
-- work if the epoch length changed in a hard fork.
let timeToLive = (toSlotNo epochLength slot) + 7200
Copy link
Member

Choose a reason for hiding this comment

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

7200 ? Avoid magic numbers, make it a named constant and explain the rationale of choosing 7200 (ultimately, we want that configurable via the API). Can you make sure to let Alex know about this?

-- Maybe that value wasn't taking delegation keys into account?
--
-- Regardless:
-- TODO: Implement properly.
Copy link
Member

Choose a reason for hiding this comment

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

The length of the output will actually depend on the value and the type of addresses used. We can assume worst-case scenario which are currently 65 bytes for addresses indeed. 32 bytes for just the value sounds huge.

Copy link
Member

@KtorZ KtorZ left a comment

Choose a reason for hiding this comment

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

Nice work. I think we can go with this first big chunk and do improvements / additions on top.

@KtorZ
Copy link
Member

KtorZ commented May 28, 2020

bors try

iohk-bors bot added a commit that referenced this pull request May 28, 2020
@iohk-bors
Copy link
Contributor

iohk-bors bot commented May 28, 2020

try

Build failed

Anviking and others added 20 commits May 30, 2020 18:39
To make it work on shelley, without relying on that the minFee is
accurate.
- split functions out so that they read better and will likely be re-used for implementing other parts of the transaction layer.
- avoid unnecessary identifiers declaration. Too many identifiers in a single small context don't make things more readable.
- changed a few types to avoid repeating the same unwrapping operation
- named some in-place calculation (like realFee)
- used forM + pattern-matching instead of mapM and pointfree style. Pointfree is usually not readable when it's in a context with more than one line
The fee calculation isn't actually made on the transaction size in bytes, but rather, on an abstract representation of the transaction.
This is detailed in the ledger specifications and implemented in the cardano-ledger-specs module. So, we might as well re-use this here.
@KtorZ KtorZ force-pushed the anviking/ADP-319/shelley-txs branch from bdd431c to 3c1d508 Compare May 30, 2020 16:39
By not depending on a pass to the next epoch, which can be quite long on the cardano-node.
@KtorZ KtorZ force-pushed the anviking/ADP-319/shelley-txs branch from dbd08da to 406bfa2 Compare May 30, 2020 16:52
@KtorZ
Copy link
Member

KtorZ commented May 30, 2020

I force pushed the "regenerate nix" commit like a retard. :|

@KtorZ
Copy link
Member

KtorZ commented May 30, 2020

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented May 30, 2020

Build succeeded

@iohk-bors iohk-bors bot merged commit 3fb783f into master May 30, 2020
@iohk-bors iohk-bors bot deleted the anviking/ADP-319/shelley-txs branch May 30, 2020 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADDING FEATURE Mark a PR as adding a new feature, for auto-generated CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants