-
Notifications
You must be signed in to change notification settings - Fork 125
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
Update min_ada_required() to Alonzo rules #219
Update min_ada_required() to Alonzo rules #219
Conversation
Following: https://github.com/input-output-hk/cardano-ledger-specs/blob/master/doc/explanations/min-utxo-alonzo.rst Some tests in tx_builder.rs still need to be updated
let utxo_entry_size_without_val = 27; // in words | ||
let size = bundle_size( | ||
&assets, | ||
&OutputSizeConstants { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are actually fixed values in the doc so I'm not sure if it's worth it to pass in vs just hardcoding inside of bundle_size()
anymore.
ada_only_utxo_size, | ||
min_utxo.0 | ||
))) | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc doesn't mention explicitly about combining data hash with the min ada-only utxo value. It just says that is 1,000,000 but if you do the size calculation on it without a data hash it's actually like ~950,000.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Scitz0 mentioned that:
I don't fully trust the linked alonzo min utxo ledger spec.
For example, taking coinSize into consideration and looking at Mary min-utxo ledger spec document, for Ada only its calculated as:
adaOnlyUTxOSize = utxoEntrySizeWithoutVal + coinSize = 27
Switching coinSize to 2 gives an adaOnlyUTxOSize value of 29. If you multiple this with coinsPerUTxOWord you get a value of 999978 Lovelace. For an Ada-only transaction, this is a perfectly valid output to use. Tested on both TestNet and MainNet.
#[test] | ||
fn proper_asset_size_calculation() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure where this test data came from. I got all the tests I added from the doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was added based on this issue:
#194
…ize 0 -> 2 for ada-only min add calculations
pool_deposit: &BigNum, // protocol parameter | ||
key_deposit: &BigNum, // protocol parameter | ||
max_value_size: u32, // protocol parameter | ||
max_tx_size: u32, // protocol parameter | ||
coins_per_utxo_word: &Coin, // protocol parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up moving this to the end instead of keeping it where it was to purposefully break the API so that people won't accidentally supply the type-compatible minimum_utxo_val to coins_per_utxo_word which would result in massively different minimum ada calculations that will be off by ~30 times.
@@ -680,8 +681,8 @@ mod tests { | |||
tx_builder.get_explicit_input().unwrap().checked_add(&tx_builder.get_implicit_input().unwrap()).unwrap(), | |||
tx_builder.get_explicit_output().unwrap().checked_add(&Value::new(&tx_builder.get_fee_if_set().unwrap())).unwrap() | |||
); | |||
assert_eq!(tx_builder.full_size().unwrap(), 283); | |||
assert_eq!(tx_builder.output_sizes(), vec![61, 65]); | |||
assert_eq!(tx_builder.full_size().unwrap(), 284); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to bump these up by 1 due to how CBOR encodes data. Integers below I think 20 are stored in 1 byte with the value embedded in the type tag, but valid values with the supplied 1 coin per utxo word (=29 for asset-less outputs) now take 2 bytes for UINT tag + anther byte for the number 29.
@@ -665,7 +666,7 @@ mod tests { | |||
); | |||
tx_builder.add_output(&TransactionOutput::new( | |||
&addr_net_0, | |||
&Value::new(&to_bignum(10)) | |||
&Value::new(&to_bignum(29)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If anyone's wondering, 29 is the new adda only min utxo when you have coin size per utxo word = 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to @Scitz0 :
I don't fully trust the linked alonzo min utxo ledger spec.
For example, taking coinSize into consideration and looking at Mary min-utxo ledger spec document, for Ada only its calculated as:
adaOnlyUTxOSize = utxoEntrySizeWithoutVal + coinSize = 27
Switching coinSize to 2 gives an adaOnlyUTxOSize value of 29. If you multiple this with coinsPerUTxOWord you get a value of 999978 Lovelace. For an Ada-only transaction, this is a perfectly valid output to use. Tested on both TestNet and MainNet.
For output containing a token however the formula showed in alonze spec seem fine, e.g
coinsPerUTx, Word * ( utxoEntrySizeWithoutVal + size (v) + dataHashSize (dh) )
So I made this change since apparently that is what is accepted by mainnet, not the mentioned 1_000_000 fixed value before. We might want to verify this 100% though.
Thank you, @rooooooooob! This is a great change, but it's really breaking tho, so it gonna need to be in the next version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/check
Changed target to another local branch |
Following: https://github.com/input-output-hk/cardano-ledger-specs/blob/master/doc/explanations/min-utxo-alonzo.rst
Some tests in tx_builder.rs still need to be updated