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

Question: what values to use for LinearFee? #711

Closed
gmoratorio opened this issue Jan 13, 2025 · 12 comments
Closed

Question: what values to use for LinearFee? #711

gmoratorio opened this issue Jan 13, 2025 · 12 comments

Comments

@gmoratorio
Copy link

In our codebase we previously had a simple LinearFee calculation of

let linear_fee = LinearFee::new(&BigNum::from(44_u32), &BigNum::from(155381_u32));

derived from the protocol params

"min_fee_a": 44,
"min_fee_b": 155381,

After upgrading to CSL 13.2.1, however, I get a Phase-1 Validation fee error when trying to submit a test transaction on preprod:

Fee is less than the minimum fee. Min fee: 877860, Fee: 876320

I can bypass this error by arbitrarily upping the constant and/or coefficient values in the LinearFee calculation, but I'd like to be using real protocol parameters and best-practice values instead of just guessing a higher number that'll pass Phase-1.

What values should be used for the first and second arg of LinearFee, and if they aren't min_fee_a and min_fee_b, where should I be sourcing these values?

@lisicky
Copy link
Contributor

lisicky commented Jan 13, 2025

Hi @gmoratorio ! Could you clarify does it happens only on the last 13.2.1 version ?
LinearFee doesn’t have min_fee_a and min_fee_b in parameter naming because it doesn’t reflect purpose of these fields.

Do you modify a tx somehow after change calculation?

@gmoratorio
Copy link
Author

gmoratorio commented Jan 13, 2025

@lisicky thanks for the quick reply! Good point, this started happening some time before 13.2.1 with the prior HF. I suspect it might have been due to nodes we're submitting through already upgrading to new cost models ahead of time. I "fixed" the issue by upping the coefficient arg a bit, and mentally filed it under "I need to get real values for these when the next HF comes around..."

Now after upgrading to 13.2.1 even my "upped" values started failing, and instead of arbitrarily increasing them a second time I decided it was time to find proper values to use.

We use this logic in our base tx_builder_config that we use for all transactions

pub static ref COINS_PER_UTXO_BYTE: BigNum = BigNum::from(4310_u32);
    pub static ref DEFAULT_DATA_COST: DataCost = DataCost::new_coins_per_byte(&COINS_PER_UTXO_BYTE);
    pub static ref REF_SCRIPT_COINS_PER_BYTE: UnitInterval = UnitInterval::new(&BigNum::from(15_u32), &BigNum::from(1_u32));

 let linear_fee = LinearFee::new(&BigNum::from(44_u32), &BigNum::from(155381_u32));
    let config_builder = TransactionBuilderConfigBuilder::new()
        .fee_algo(&linear_fee)
        .pool_deposit(&BigNum::from(500000000_u32))
        .key_deposit(&BigNum::from(2000000_u32))
        .max_value_size(5000)
        .max_tx_size(16384)
        .ex_unit_prices(&ExUnitPrices::new(
            &UnitInterval::new(&BigNum::from(577_u32), &BigNum::from(10000_u32)),
            &UnitInterval::new(&BigNum::from(721_u32), &BigNum::from(10_000_000_u32)),
        ))
        .ref_script_coins_per_byte(&REF_SCRIPT_COINS_PER_BYTE)
        .coins_per_utxo_byte(&COINS_PER_UTXO_BYTE);

then for usages we call

let mut builder = TransactionBuilder::new(&csl::tx_builder_config()?);

and add_output, set_inputs etc. to the builder as needed

What values should we be using for the constant and coefficient values if not min_fee_a and min_fee_b?

@lisicky
Copy link
Contributor

lisicky commented Jan 13, 2025

@gmoratorio coefficient is min_fee_a and constant is min_fee_b from protocol parameters.
Params look ok. But probably my second question was little bit messy, so let me rephrase it, sorry for it. When you call tx_builder.add_changed_if_needed or a similar functions, do you do some modifications in a transaction after it?

@gmoratorio
Copy link
Author

@lisicky yes, you're correct, coefficient is min_fee_a and constant is min_fee_b. I wrote them backwards in my other message. We're using them as you describe there.

I just checked all of our usages, and we don't seem to make any modifications after we set the change. Right after we call add_change_if_needed we immediately build the transaction.

In general our pattern is:

  • builder = TransactionBuilder::new(&csl::tx_builder_config()?)
  • add inputs/outputs/refScripts to builder
  • builder.add_change_if_needed(&destination_address)?
  • builder.build_tx()?

@lisicky
Copy link
Contributor

lisicky commented Jan 13, 2025

do you use referenced scripts ?

@gmoratorio
Copy link
Author

yes we use reference scripts in some places, and in particular the tx that I'm seeing the fee error on I know for sure uses one.

For that transaction in question, these are the high-level steps:

  • let mut builder = TransactionBuilder::new(&csl::tx_builder_config()?);
  • builder.add_reference_input(&ref_input);
  • builder.set_inputs(&inputs);
  • builder.add_output(&output_builder.build()?)?;
  • builder.set_validity_start_interval_bignum
  • builder.set_ttl_bignum(&csl::time_to_slot
  • builder.calc_script_data_hash
  • builder.add_change_if_needed
  • builder.build_tx()?;

and then we sign and submit the tx

@lisicky
Copy link
Contributor

lisicky commented Jan 13, 2025

@gmoratorio check that you are specifying referenced script size correctly, since Conway referenced scripts affects transaction fee

@lisicky
Copy link
Contributor

lisicky commented Jan 13, 2025

you can use add_script_reference_input function

@gmoratorio
Copy link
Author

gmoratorio commented Jan 14, 2025

ok @lisicky I think I finally figured out the issue. In this particular tx method we were calling add_change_if_needed first and then calc_script_data_hash

builder.add_change_if_needed(&buyer_addr)?;
builder.calc_script_data_hash(&TxBuilderConstants::plutus_conway_cost_models())?;

I inverted them so the calc happened first, and it seems to have resolved the fee issue. This is also the pattern we use in all of our other txs. It must have been accidentally inverted here.

builder.calc_script_data_hash(&TxBuilderConstants::plutus_conway_cost_models())?;
builder.add_change_if_needed(&buyer_addr)?;

Does this sound right to you?

@lisicky
Copy link
Contributor

lisicky commented Jan 14, 2025

Yep it’s correct order

builder.calc_script_data_hash(&TxBuilderConstants::plutus_conway_cost_models())?;
builder.add_change_if_needed(&buyer_addr)?;

@lisicky
Copy link
Contributor

lisicky commented Jan 14, 2025

Otherwise fee would be calculated incorrectly

@gmoratorio
Copy link
Author

sounds good, thanks @lisicky for talking through it. Tx are working now, I think this ticket can be closed. Really appreciate the time.

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

No branches or pull requests

2 participants