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

Update min_ada_required() to Alonzo rules #219

Merged
merged 3 commits into from
Nov 4, 2021

Conversation

rooooooooob
Copy link
Contributor

let utxo_entry_size_without_val = 27; // in words
let size = bundle_size(
&assets,
&OutputSizeConstants {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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.

Copy link
Contributor Author

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() {
Copy link
Contributor Author

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.

Copy link

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
Copy link
Contributor Author

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);
Copy link
Contributor Author

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))
Copy link
Contributor Author

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

Copy link
Contributor Author

@rooooooooob rooooooooob left a 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.

@rooooooooob rooooooooob marked this pull request as ready for review October 14, 2021 05:39
@Scitz0
Copy link

Scitz0 commented Oct 14, 2021

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.

As an assurance for the value this is a screenshot from Daedalus Flight 4.3.1.

image

@vsubhuman vsubhuman added this to the 9.2.0 milestone Oct 19, 2021
@vsubhuman vsubhuman self-requested a review October 19, 2021 15:09
@vsubhuman vsubhuman modified the milestones: 9.2.0, 10.0.0 Nov 1, 2021
@vsubhuman
Copy link
Contributor

Thank you, @rooooooooob! This is a great change, but it's really breaking tho, so it gonna need to be in the next version 10.0.0

@vsubhuman vsubhuman linked an issue Nov 1, 2021 that may be closed by this pull request
Copy link
Contributor

@pedromtcosta pedromtcosta left a comment

Choose a reason for hiding this comment

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

Looks good!

@vsubhuman vsubhuman modified the milestones: 10.0.0, 9.2.0 Nov 2, 2021
@vsubhuman vsubhuman changed the base branch from master to alonzo-min-utxo-size November 4, 2021 08:40
@vsubhuman vsubhuman changed the base branch from alonzo-min-utxo-size to master November 4, 2021 08:41
Copy link
Contributor

@vsubhuman vsubhuman left a comment

Choose a reason for hiding this comment

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

/check

@vsubhuman vsubhuman changed the base branch from master to alonzo-min-utxo-size November 4, 2021 09:44
@vsubhuman
Copy link
Contributor

Changed target to another local branch alonzo-min-utxo-size to resolve conflicts and run tests first

@vsubhuman vsubhuman merged commit 308800a into Emurgo:alonzo-min-utxo-size Nov 4, 2021
@vsubhuman vsubhuman mentioned this pull request Feb 6, 2022
40 tasks
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.

coinSize in Alonzo era
4 participants