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

Value encoding #1979

Merged
merged 1 commit into from Nov 25, 2020
Merged

Value encoding #1979

merged 1 commit into from Nov 25, 2020

Conversation

redxaxder
Copy link
Contributor

@redxaxder redxaxder commented Nov 10, 2020

Different serializations for Value

The Value type is used in both TxOuts and in the Mint field of the transaction body, but negative values are only allowed in the latter. The rules already enforce this, but now the serialization does too.

Resolves: CAD-1667 and CAD-2148

@redxaxder redxaxder changed the title Redxaxder/cborvalue Value encoding Nov 10, 2020
Copy link
Contributor

@nc6 nc6 left a comment

Choose a reason for hiding this comment

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

Just left comments since this is still marked as draft.

shelley-ma/impl/src/Cardano/Ledger/Mary/Value.hs Outdated Show resolved Hide resolved
shelley-ma/impl/src/Cardano/Ledger/Mary/Value.hs Outdated Show resolved Hide resolved

-- ========================================================

-- | Remove 0 assets from a map
prune :: Map (PolicyID era) (Map AssetID Integer)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is perhaps a bit slower than the old method?

@redxaxder redxaxder force-pushed the redxaxder/cborvalue branch 11 times, most recently from 69516f9 to d2d5a7a Compare November 24, 2020 17:59
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.

LGTM!

@redxaxder redxaxder force-pushed the redxaxder/cborvalue branch 2 times, most recently from 1f689bf to 7360191 Compare November 24, 2020 19:26
@redxaxder redxaxder marked this pull request as ready for review November 24, 2020 19:51
Copy link
Contributor

@nc6 nc6 left a comment

Choose a reason for hiding this comment

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

Looks pretty good to me, couple of minor comments only

fromCBOR,
toCBOR,
)
import Cardano.Binary (Decoder, Encoding, FromCBOR, ToCBOR, TokenType (..), decodeInt64, decodeWord64, fromCBOR, peekTokenType, toCBOR)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid such very long lines?

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't ormolu do something about this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ormolu basically has two choices: one line, or split them. If you add a random line break somewhere in there, ormolu will then format the whole list. But it allows you to choose not to add any line breaks, as in this case

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll break it up

@@ -1 +1 @@
-c "nix-shell ../../../shell.nix --run \"cabal repl -f development shelley-spec-ledger-test\"" -o ghcid.txt
-c "nix-shell ../../../shell.nix --run \"cabal repl -f development test:shelley-spec-ledger-test\"" -o ghcid.txt
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change intentional?

Copy link
Contributor

Choose a reason for hiding this comment

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

probably not, I'll remove it

Copy link
Contributor

@mrBliss mrBliss left a comment

Choose a reason for hiding this comment

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

Could you fix the PR description before merging? It would be very confusing if the current message ends up in the history. You could, for example, copy the commit message (also rename the PR to match the commit's title).

shelley-ma/impl/src/Cardano/Ledger/Mary/Translation.hs Outdated Show resolved Hide resolved
fromCBOR,
toCBOR,
)
import Cardano.Binary (Decoder, Encoding, FromCBOR, ToCBOR, TokenType (..), decodeInt64, decodeWord64, fromCBOR, peekTokenType, toCBOR)
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't ormolu do something about this?

Comment on lines 486 to 487
let assume Nothing = error $ "illegal value in txout: " <> show vl
assume (Just x) = x
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar suggestion about fromMaybe

The Value type is used in both TxOuts and in the Mint field of the
transaction body, but negative values are only allowed in the latter.
The rules already enforce this, but now the serialization does too.

Resolves: CAD-1667 and CAD-2148
@JaredCorduan JaredCorduan merged commit 7280ee5 into master Nov 25, 2020
@iohk-bors iohk-bors bot deleted the redxaxder/cborvalue branch November 25, 2020 15:24
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

4 participants