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

CIP-0055? | Babbage Era Protocol Parameters #265

Merged
merged 4 commits into from
Jun 29, 2022

Conversation

JaredCorduan
Copy link
Contributor

This informational CIP extends CIP-0028 to introduce a change to one of the Alonzo protocol parameters in the Babbage era, namely lovelacePerUTxOWord. We propose to have this updateable parameter be based on bytes instead of words (eight bytes).

@gitmachtl
Copy link
Contributor

@JaredCorduan , question, i am calculating the current value discrete in my stakepool operator scripts, based on mary/alonzo values. (https://github.com/gitmachtl/scripts/blob/f84ed987ab0dcdcba7caee758a9f723853735899/cardano/mainnet/00_common.sh#L669-L752)

After the HF event, can i still use the same calculation method but just multiplying the value of the coinsPerUTxOByte value by 8 and use this as the new "word" amount?

@JaredCorduan
Copy link
Contributor Author

@JaredCorduan , question, i am calculating the current value discrete in my stakepool operator scripts, based on mary/alonzo values. (https://github.com/gitmachtl/scripts/blob/f84ed987ab0dcdcba7caee758a9f723853735899/cardano/mainnet/00_common.sh#L669-L752)

After the HF event, can i still use the same calculation method but just multiplying the value of the coinsPerUTxOByte value by 8 and use this as the new "word" amount?

No, that is not guaranteed to work. The old formula was based on an upper bound to the memory usage, and the new formula is based on the size on the wire.

@KtorZ
Copy link
Member

KtorZ commented May 24, 2022

@JaredCorduan I do expect the new formula to always yield values that are less or equal to what they used to be with the current formula, as the approximation was 'over-estimating' sizes generally speaking. Right?

@KtorZ KtorZ changed the title CIP for babbage era coinsPerUTxOByte CIP-0055? | CIP for babbage era coinsPerUTxOByte May 24, 2022
@JaredCorduan
Copy link
Contributor Author

@JaredCorduan
Copy link
Contributor Author

@JaredCorduan I do expect the new formula to always yield values that are less or equal to what they used to be with the current formula, as the approximation was 'over-estimating' sizes generally speaking. Right?

(clicked the wrong button, sorry to close/open the PR) That is probably true, but we have not tested it or made that promise.

@JaredCorduan
Copy link
Contributor Author

as the approximation was 'over-estimating' sizes generally speaking. Right?

just to be clear, the old formula was over-estimating the size in memory. the new methods is an exact measurement of the size on the wire. in other words, we are measuring something slightly different in Babbage, though obviously they are correlated.

@gitmachtl
Copy link
Contributor

gitmachtl commented May 25, 2022

as the approximation was 'over-estimating' sizes generally speaking. Right?

just to be clear, the old formula was over-estimating the size in memory. the new methods is an exact measurement of the size on the wire. in other words, we are measuring something slightly different in Babbage, though obviously they are correlated.

can the size be calculated from the "build-raw transaction" output we do already to produce a "dummy-tx" for later usage with the "transaction calculate-min-fee" command? like just using the cBor hex content of the unwitnessed-tx-file, size is length of that cbor string / 2 (because hex uses 2 chars for 1 byte). i want to have an external 2nd option to calculate the minAda. if it is necessary to do the signing too, that would be a nightmare with hw wallets or multisig operations.

currently we can calculate the minRequiredUTxO externally by the formular or via the internal "calculate-min-required-utxo" command. but the external formular method does not require any cBor conversion just pure "bash" commands.

@JaredCorduan
Copy link
Contributor Author

can the size be calculated from the "build-raw transaction" output we do already to produce a "dummy-tx" for later usage with the "transaction calculate-min-fee" command? like just using the cBor hex content of the unwitnessed-tx-file, size is length of that cbor string / 2 (because hex uses 2 chars for 1 byte). i want to have an external 2nd option to calculate the minAda. if it is necessary to do the signing too, that would be a nightmare with hw wallets or multisig operations.

almost! it's not the size of the cbor tx that matters, but the size of each cbor txout inside the output of build-raw transaction. for each such output hex, after you have divided by two (to account for the hex), all you have to is multiply by the protocol parameter coinsPerUTxOByte.

@gitmachtl
Copy link
Contributor

can the size be calculated from the "build-raw transaction" output we do already to produce a "dummy-tx" for later usage with the "transaction calculate-min-fee" command? like just using the cBor hex content of the unwitnessed-tx-file, size is length of that cbor string / 2 (because hex uses 2 chars for 1 byte). i want to have an external 2nd option to calculate the minAda. if it is necessary to do the signing too, that would be a nightmare with hw wallets or multisig operations.

almost! it's not the size of the cbor tx that matters, but the size of each cbor txout inside the output of build-raw transaction. for each such output hex, after you have divided by two (to account for the hex), all you have to is multiply by the protocol parameter coinsPerUTxOByte.

hmm ok, but this is not trivial because it would need to redo the whole cbor conversion... hmm.

@JaredCorduan
Copy link
Contributor Author

hmm ok, but this is not trivial because it would need to redo the whole cbor conversion... hmm.

what cbor conversion are you referring to?

@gitmachtl
Copy link
Contributor

gitmachtl commented May 27, 2022

hmm ok, but this is not trivial because it would need to redo the whole cbor conversion... hmm.

what cbor conversion are you referring to?

to bring any kind of txOut into the used cBor format for calculating the minAda. there is no native solution to do this in pure bash without 3rd party tools. but lets see how it differs. currently running testnodes in the vasil-qa testchain. any plans to bring this new parameter into this testchain anytime soon?

@JaredCorduan
Copy link
Contributor Author

currently running testnodes in the vasil-qa testchain. any plans to bring this new parameter into this testchain anytime soon?

it's already using the new calculation on vasil-qa.

@KtorZ KtorZ changed the title CIP-0055? | CIP for babbage era coinsPerUTxOByte CIP-0055? | Babbage Era's coinsPerUTxOByte Jun 7, 2022
@KtorZ
Copy link
Member

KtorZ commented Jun 7, 2022

@JaredCorduan what about the 'extra entropy' and the 'decentralization parameter' which are now gone in Babbage/Vasil? Do you think you could add two lines of rationale as for why those parameters have now been removed so that we have a complete overview of the updatable parameters changes.

@JaredCorduan
Copy link
Contributor Author

@JaredCorduan what about the 'extra entropy' and the 'decentralization parameter' which are now gone in Babbage/Vasil? Do you think you could add two lines of rationale as for why those parameters have now been removed so that we have a complete overview of the updatable parameters changes.

yes, that's a great idea.

@JaredCorduan JaredCorduan changed the title CIP-0055? | Babbage Era's coinsPerUTxOByte CIP-0055? | Babbage Era Protocol Parameters Jun 7, 2022
@JaredCorduan
Copy link
Contributor Author

@KtorZ I've added some prose about the removal of d and extraEntropy.

Copy link
Contributor

@SebastienGllmt SebastienGllmt left a comment

Choose a reason for hiding this comment

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

LGTM

newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 6, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 6, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 6, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 6, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 6, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 6, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 6, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 6, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 7, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 7, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 7, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 7, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 7, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 7, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 7, 2022
newhoggy added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 8, 2022
iohk-bors bot added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 8, 2022
4141: Add utxoCostPerByte protocol parameter r=newhoggy a=newhoggy

Resolves #4052
See cardano-foundation/CIPs#265

Co-authored-by: John Ky <john.ky@iohk.io>
iohk-bors bot added a commit to IntersectMBO/cardano-node that referenced this pull request Jul 8, 2022
4141: Add utxoCostPerByte protocol parameter r=newhoggy a=newhoggy

Resolves #4052
See cardano-foundation/CIPs#265

Co-authored-by: John Ky <john.ky@iohk.io>
@gitmachtl
Copy link
Contributor

gitmachtl commented Jul 8, 2022

@JaredCorduan

hi, i have troubles to get the math right. so i have a simple transaction to a testnet base address. sending lovelaces and 10x ATADAcoin. this results in a minADA value of 1168010 lovelaces. according to the utxoCostPerByte value of 4310 this should be 271 bytes. but when i only take the CBOR part of this txout

{0: h'00897789A996EC52F93668D18DD4DBE5F00036A0406F6DA37185C641CAF695C35024868C4DD6F694E16B88BDF6986E31A074F790D75241C44B', 1: [1168010, {h'34250EDD1E9836F5378702FBF9416B709BC140E04F668CC355208518': {h'4154414441636F696E': 10}}]}

cbor-hex:
A200583900897789A996EC52F93668D18DD4DBE5F00036A0406F6DA37185C641CAF695C35024868C4DD6F694E16B88BDF6986E31A074F790D75241C44B01821A0011D28AA1581C34250EDD1E9836F5378702FBF9416B709BC140E04F668CC355208518A1494154414441636F696E0A

thats only 111 bytes and not 271 bytes? what am i missing here? 160 bytes as a fixed addition?

EDIT: ah... the overhead ...
https://github.com/input-output-hk/cardano-ledger/blob/2505b7f103c78ee5a230b3e302e31d9607fffbd5/eras/babbage/impl/src/Cardano/Ledger/Babbage/Rules/Utxo.hs#L251-L264

@JaredCorduan
Copy link
Contributor Author

@gitmachtl great catch, I forgot that we ended up adding the constant overhead, that should definitely be a part of this CIP!

@gitmachtl
Copy link
Contributor

gitmachtl commented Jul 10, 2022

@JaredCorduan i figured out, that for a mary/alonzo transaction in babbage era you get along with an overhead of only 158 bytes. what is causing the 2 extra bytes for a babbage formated transaction? is it the change in the legacy/babbage transaction output (https://github.com/input-output-hk/cardano-ledger/blob/2505b7f103c78ee5a230b3e302e31d9607fffbd5/eras/babbage/test-suite/cddl-files/babbage.cddl#L77-L88) ?

@JaredCorduan
Copy link
Contributor Author

@gitmachtl -

Note that the purpose of the minimum UTxO value is to constrain how much memory someone can take up in the UTxO map, relative to how many lovelace they control. And we are now (starting in the Babbage era) using the number of bytes of a given transaction output on the wire to approximate the impact in memory to the UTxO.

In Haskell, a Word (eight bytes) is the smallest unit of space that you can take up. The twenty words in the overhead exist to account for some of the difference between the size of an output on the wire, and the size in memory of the unspent transaction output which it creates. Recall that an unspent transaction output is an entry in a map, mapping a transaction input to a transaction output. So, at the very least, the overhead needs to include the size in memory of the transaction input and also the impact of the map data structure. Let's first dig into that.


The UTxO map looks like:

newtype UTxO era = UTxO (Map (TxIn (Crypto era)) (TxOut era))

type Size     = Int

data Map k a  = Bin {-# UNPACK #-} !Size !k a !(Map k a) !(Map k a)
              | Tip

So each element of the map, ie each Bin, uses:

  • 1 Word for for the type constructor
  • 1 Word for Size
  • 1 Word for the pointer to k
  • 1 Word for the pointer to a
  • 2 Words for the two pointers, left and right, that the map uses for the binary tree structure

Total: 6 Words + the size of k + the size of a
(ie 6 Words + the size of the transaction input + the size of the transaction output.)

Remember that we are approximating the size of a by the number of bytes on the wire of the transaction output (and that this number is not a part of the overhead).


The transaction inputs look like:

data TxIn crypto = TxIn !(TxId crypto) {-# UNPACK #-} !TxIx

So each TxIn uses:

  • 1 Word for the type constructor
  • 1 Word for the pointer to TxId (the transaction ID)
  • 1 Word for TxIx (the transaction index).

Total: 3 Words + the size of TxId


The transaction IDs look like:

newtype TxId crypto = TxId {_unTxId :: SafeHash crypto EraIndependentTxBody}
newtype SafeHash crypto index = SafeHash (Hash.Hash (CC.HASH crypto) index)
-- Resolves to:
newtype Hash Blake2b_256 EraIndependentTxBody = UnsafeHashRep (PackedBytes (SizeHash Blake2b_256))
-- Which is this case:
data PackedBytes (n :: Nat) where
  ...
  PackedBytes32 :: {-# UNPACK #-} !Word64
                -> {-# UNPACK #-} !Word64
                -> {-# UNPACK #-} !Word64
                -> {-# UNPACK #-} !Word64
                -> PackedBytes 32
  ...

So each TxId uses:

  • 1 Word for the type constructor
  • 4 Words for the data

Total: 5 Words


This brings us to 14 words of overhead.

The remaining 6 words account for the space taken up by the transaction output which is not accounted for in the bytes on the wire. Since outputs can vary a lot (Babbage era outputs have a lot of options, such as inline datums, reference scripts, etc), we did not do accounting as above, but rather chose 6 because that was the value which made the minimum lovelace of an lovelace-only output have a minimum of 1 ADA (using the current Alonzo protocol parameters). Though the minimum utxo calculation has changed each era, ever since the Shelley era we have kept the minimum value for a lovelace-only outputs as close to 1 ADA as we can.

@gitmachtl
Copy link
Contributor

thx 🙏

Jimbo4350 pushed a commit to IntersectMBO/cardano-node that referenced this pull request Aug 2, 2022
newhoggy added a commit to IntersectMBO/cardano-api that referenced this pull request May 23, 2023
newhoggy added a commit to IntersectMBO/cardano-cli that referenced this pull request May 24, 2023
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.

6 participants