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

billing config override #12536

Merged
merged 2 commits into from
Mar 22, 2024
Merged

billing config override #12536

merged 2 commits into from
Mar 22, 2024

Conversation

shileiwill
Copy link
Contributor

No description provided.

Copy link
Contributor

I see you updated files related to contracts. Please run pnpm changeset in the contracts directory to add a changeset.

if (address(billingConfigOverridden.priceFeed) != ZERO_ADDRESS) {
// use the overridden configs
paymentParams.billingToken.gasFeePPB = billingConfigOverridden.gasFeePPB;
paymentParams.billingToken.flatFeeMicroLink = billingConfigOverridden.flatFeeMicroLink;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@RyanRHall comparing the BillingConfig struct and this PaymentsParams struct, I think only these 2 configs are override-able. Let me know if anything else to override?

also, since the _calculatePaymentAmount func is upkeepID agnostic, i hope it is okay to override before the _calculatePaymentAmount call.

Copy link
Contributor

Choose a reason for hiding this comment

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

hey sorry this was a bit confusing. I think you could define a new struct, something like...

struct BillingOverrides {
  gasFeePPB;
  flatFeeMicroLink;  // note this will become flatFeeMilliCents soon
}

@@ -705,6 +710,8 @@ abstract contract AutomationRegistryBase2_3 is ConfirmedOwner {
maxL1Fee = hotVars.gasCeilingMultiplier * hotVars.chainModule.getMaxL1Fee(maxCalldataSize);
}

// TODO: this is for checkupkeep, I guess we also need to override the billing config based on upkeep ID?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIUC, we also need to override for checkUpkeep too.

Copy link
Contributor

Go solidity wrappers are out-of-date, regenerate them via the make wrappers-all command

Copy link
Contributor

@RyanRHall RyanRHall left a comment

Choose a reason for hiding this comment

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

looks great 👍 just a couple small requests :)

*/
struct BillingOverrides {
uint32 gasFeePPB;
uint24 flatFeeMicroLink;
Copy link
Contributor

Choose a reason for hiding this comment

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

Update to flatFeeMilliCents after rebase :)

Comment on lines 723 to 727
if (s_upkeep[upkeepId].overridesEnabled) {
BillingOverrides memory billingOverrides = s_billingOverrides[upkeepId];
// use the overridden configs
paymentParams.gasFeePPB = billingOverrides.gasFeePPB;
paymentParams.flatFeeMicroLink = billingOverrides.flatFeeMicroLink;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think of moving this code into _calculatePaymentAmount()? We could add upkeepID and overridesEnabled as fields of PaymentParams? this way the override code is all in one place and we don't have to write the same logic twice. Not a strong opinion!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100% agreed on reusing code wherever possible. I actually thought (see in another comment) about moving the overriding logic to _calculatePaymentAmount(), but figured that it is dryer to have the override outside of it.

The main reason is that struct PaymentParams, struct BillingTokenPaymentParams and _calculatePaymentAmount() are all pure payment related and agnostic to upkeep ID. I feel better if we just do the override beforehand, get the right PaymentParams and pass in to the _calculate func and structs. so the payment related structs/func are not tied to upkeepID.

Also not a strong opinion, I do see the pros and cons on both sides...

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good to me, happy to leave it as it 👍

@@ -944,6 +966,13 @@ abstract contract AutomationRegistryBase2_3 is ConfirmedOwner {
PaymentParams memory paymentParams,
uint256 upkeepId
) internal returns (PaymentReceipt memory) {
if (s_upkeep[upkeepId].overridesEnabled) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is an extra SLOAD - can we have this function accept this overridedEnabled as an argument? We read the whole upkeep struct into memory in handleReport() see above comment about adding overridedEnabled and upkeepID to PaymentParams

Copy link
Contributor Author

Choose a reason for hiding this comment

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

adding overridedEnabled and upkeepID to PaymentParams
if the goal is to save gas, then I totally missed this. I think this is in hot path, gas usage should be prioritized.

In this _handlePayment() func, we do have other places SLOAD from s_upkeep, do you think it worth putting them closer in one word? E.g.

uint96 balance = s_upkeep[upkeepId].balance;

Copy link
Contributor

Choose a reason for hiding this comment

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

ooo yeah I think we can save two SLOADs here! Let's change handlePayment() to have this sig...

function _handlePayment(
  HotVars memory hotVars,
  PaymentParams memory paymentParams,
  uint256 upkeepId,
  Upkeep memory upkeep
) 

and then in _handleReport() we just pass the upkeep separately like this...

_handlePayment(
  hotVars,
  PaymentParams({
    // ...
  }),
  report.upkeepIds[i],
  upkeepTransmitInfo[i].upkeep
);

* @param id the upkeepID
* @param billingOverrides the override-able billing config
*/
function setBillingOverrides(uint256 id, BillingOverrides calldata billingOverrides) external {
Copy link
Contributor

Choose a reason for hiding this comment

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

great use of calldata 👍

Comment on lines 45 to 52
function setBillingOverrides(uint256 id, BillingOverrides calldata billingOverrides) external {
_onlyPrivilegeManagerAllowed();

s_upkeep[id].overridesEnabled = true;
s_billingOverrides[id] = billingOverrides;
emit BillingConfigOverridden(id);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

in this function, could we add a check for valid upkeepID? aka revert if the upkeepID does not exist.

if (msg.sender != s_storage.upkeepPrivilegeManager) {
revert OnlyCallableByUpkeepPrivilegeManager();
}
_onlyPrivilegeManagerAllowed();
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, much cleaner 👍

Copy link
Contributor

Go solidity wrappers are out-of-date, regenerate them via the make wrappers-all command

Copy link
Contributor

I see you updated files related to core. Please run pnpm changeset in the root directory to add a changeset.

@shileiwill shileiwill marked this pull request as ready for review March 22, 2024 18:08
@shileiwill shileiwill requested review from a team as code owners March 22, 2024 18:08
@shileiwill shileiwill requested a review from RyanRHall March 22, 2024 18:08
@@ -672,6 +672,7 @@ describe('AutomationRegistry2_3', () => {
)

const conditionalPrice = await registry.getMaxPaymentForGas(
upkeepId,
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 will use another PR to haul all those getMaxPaymentForGas ts tests to foundry, so we can also further test the overrides logic. I hope that is okay.

Copy link
Contributor

Choose a reason for hiding this comment

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

totally fine!

@@ -251,10 +253,11 @@ abstract contract AutomationRegistryBase2_3 is ConfirmedOwner {
*/
struct Upkeep {
bool paused;
bool overridesEnabled;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: this newly added field will not exist in IAutomationRegistryMaster2_3.sol -> UpkeepInfoLegacy. But this shouldnt be a backward compatible issue.

@cl-sonarqube-production
Copy link

@shileiwill shileiwill enabled auto-merge March 22, 2024 19:04
Copy link
Contributor

@RyanRHall RyanRHall left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@@ -428,6 +439,8 @@ abstract contract AutomationRegistryBase2_3 is ConfirmedOwner {
}

event AdminPrivilegeConfigSet(address indexed admin, bytes privilegeConfig);
event BillingConfigOverridden(uint256 indexed id);
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add the BillingConfigOverride to this event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean renaming this event from BillingConfigOverridden to BillingConfigOverride ?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh sorry I meant like event BillingConfigOverridden(uint256 indexed id, BillingConfigOverride override);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it!

@shileiwill shileiwill added this pull request to the merge queue Mar 22, 2024
Merged via the queue into develop with commit 87b0d8f Mar 22, 2024
116 checks passed
@shileiwill shileiwill deleted the AUTO-9181 branch March 22, 2024 19:22
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.

2 participants