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

SetConfig optimization + billing config improvements #36

Merged
merged 23 commits into from
Feb 2, 2022

Conversation

archseer
Copy link
Collaborator

@archseer archseer commented Jan 20, 2022

Need to fit each call into 4kb

[please don't squash]

Comment on lines 76 to 81
base_gas: None,
gas_per_signature: None,
gas_adjustment: None,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are now settable via setBilling but can also be nil to use the built-in default

Comment on lines 1204 to 1219
let gas_per_signature = decimal(config.gas_per_signature.unwrap_or(17_000));
let base_gas = decimal(config.base_gas.unwrap_or(84_000));
let gas_adjustment = Decimal::percent(u64::from(config.gas_adjustment.unwrap_or(140)));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adjusted based on devnet values. We seemed to over-estimate by almost exactly 4x. The amount charged is also the "gas allocated", not "gas used" and the difference seems to be about 1.4x

@archseer archseer marked this pull request as ready for review January 21, 2022 12:58
pkg/terra/contract_transmitter.go Outdated Show resolved Hide resolved
contracts/ocr2/src/msg.rs Show resolved Hide resolved
contracts/ocr2/src/integration_tests.rs Show resolved Hide resolved
contracts/ocr2/src/state.rs Outdated Show resolved Hide resolved
@krebernisak krebernisak linked an issue Jan 25, 2022 that may be closed by this pull request
pub struct Billing {
/// Should match https://fcd.terra.dev/v1/txs/gas_prices
/// NOTE: needs to be scaled to the same amount of decimals places as LINK token
pub recommended_gas_price: u64,
pub observation_payment: u64,
pub transmission_payment: u64,
pub base_gas: Option<u64>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd suggest we rename this as gas_base to be consistent with other args.

@archseer archseer force-pushed the set-config-optimization branch 2 times, most recently from a94ab2e to d32ce28 Compare February 1, 2022 08:05
@archseer archseer changed the title SetConfig optimization SetConfig optimization + billing config improvements Feb 1, 2022
contracts/ocr2/schema/execute_msg.json Outdated Show resolved Hide resolved
@@ -929,11 +931,15 @@ pub fn execute_set_billing(
Event::new("set_billing")
.add_attribute(
"recommended_gas_price",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we rename this attribute as recommended_gas_price_uluna to keep it consistent?

// + transmitter gas reimbursement
.checked_add(transmitter.payment)?)
Ok(
Uint128::new(u128::from(config.billing.observation_payment_gjuels) * 10u128.pow(9)) // scale to juels
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider extracting this scale factor 10u128.pow(9) as a constant.

@archseer
Copy link
Collaborator Author

archseer commented Feb 2, 2022

That's converting/unwrapping from the Binary type, internally we just use byte vecs https://github.com/smartcontractkit/chainlink-terra/blob/c5e735e9fae73580d330bfde74db64c11bcf9a39/contracts/ocr2/src/msg.rs#L30-L32

observation_payment: new BN(input.observationPaymentGjuels).toNumber(),
observation_payment_gjuels: new BN(input.observationPaymentGjuels).toNumber(),
transmission_payment_gjuels: new BN(input.transmissionPaymentGjuels).toNumber(),
recommended_gas_price_uluna: input.recommendedGasPriceUluna
Copy link
Member

@RodrigoAD RodrigoAD Feb 2, 2022

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a string, you can pass through the value from https://fcd.terra.dev/v1/txs/gas_prices without modifying it

Copy link
Member

Choose a reason for hiding this comment

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

This info comes from the RDD, so we can expect it to come in the right format

@archseer archseer merged commit 6f4877c into main Feb 2, 2022
@archseer archseer deleted the set-config-optimization branch February 2, 2022 15:36
@@ -33,7 +33,7 @@ const makeContractInput = async (input: CommandInput): Promise<ContractInput> =>
config: {
observation_payment_gjuels: new BN(input.observationPaymentGjuels).toNumber(),
transmission_payment_gjuels: new BN(input.transmissionPaymentGjuels).toNumber(),
recommended_gas_price_uluna: input.recommendedGasPriceUluna
recommended_gas_price_uluna: new BN(input.recommendedGasPriceUluna).toString(),
Copy link
Contributor

Choose a reason for hiding this comment

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

If this works, I think it will have the effect of converting the decimal to an integer, either by truncating or rounding I suppose. Is that really what we want to do?

From: https://github.com/indutny/bn.js/
"Note: decimals are not supported in this library."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, agreed. RDD should store this as a string to avoid losing precision. @RodrigoAD

Copy link
Member

Choose a reason for hiding this comment

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

You're completely right. I'll open a fix

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like it's handled in #76

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.

Tx size limit reached on setting config
5 participants