Skip to content

Commit

Permalink
Divide l1 fee according to performdata weight
Browse files Browse the repository at this point in the history
  • Loading branch information
infiloop2 committed Feb 16, 2024
1 parent 91398f6 commit 351104a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 11 additions & 2 deletions contracts/src/v0.8/automation/dev/v2_2/AutomationRegistry2_2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ contract AutomationRegistry2_2 is AutomationRegistryBase2_2, OCR2Abstract, Chain
*/
struct TransmitVars {
uint16 numUpkeepsPassedChecks;
uint256 totalCalldataWeight;
uint96 totalReimbursement;
uint96 totalPremium;
}
Expand Down Expand Up @@ -107,6 +108,7 @@ contract AutomationRegistry2_2 is AutomationRegistryBase2_2, OCR2Abstract, Chain
UpkeepTransmitInfo[] memory upkeepTransmitInfo = new UpkeepTransmitInfo[](report.upkeepIds.length);
TransmitVars memory transmitVars = TransmitVars({
numUpkeepsPassedChecks: 0,
totalCalldataWeight: 0,
totalReimbursement: 0,
totalPremium: 0
});
Expand Down Expand Up @@ -139,6 +141,14 @@ contract AutomationRegistry2_2 is AutomationRegistryBase2_2, OCR2Abstract, Chain
report.performDatas[i]
);

// To split L1 fee across the upkeeps, assign a weight to this upkeep based on the length
// of the perform data and calldata overhead
upkeepTransmitInfo[i].calldataWeight =
report.performDatas[i].length +
TRANSMIT_CALLDATA_FIXED_BYTES_OVERHEAD +
(TRANSMIT_CALLDATA_PER_SIGNER_BYTES_OVERHEAD * (hotVars.f + 1));
transmitVars.totalCalldataWeight += upkeepTransmitInfo[i].calldataWeight;

// Deduct that gasUsed by upkeep from our running counter
gasOverhead -= upkeepTransmitInfo[i].gasUsed;

Expand Down Expand Up @@ -167,8 +177,7 @@ contract AutomationRegistry2_2 is AutomationRegistryBase2_2, OCR2Abstract, Chain
report.fastGasWei,
report.linkNative,
gasOverhead,
// TODO: Divide gas overhead in proportion to performData
l1Fee / transmitVars.numUpkeepsPassedChecks
(l1Fee * upkeepTransmitInfo[i].calldataWeight) / transmitVars.totalCalldataWeight
);
transmitVars.totalPremium += premium;
transmitVars.totalReimbursement += reimbursement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ abstract contract AutomationRegistryBase2_2 is ConfirmedOwner {
bool performSuccess;
Trigger triggerType;
uint256 gasUsed;
uint256 calldataWeight;
bytes32 dedupID;
}

Expand Down Expand Up @@ -646,15 +647,16 @@ abstract contract AutomationRegistryBase2_2 is ConfirmedOwner {
} else {
revert InvalidTriggerType();
}
uint256 maxCalldataSize = s_storage.maxPerformDataSize + TRANSMIT_CALLDATA_FIXED_BYTES_OVERHEAD + (TRANSMIT_CALLDATA_PER_SIGNER_BYTES_OVERHEAD * (hotVars.f + 1));
uint256 maxCalldataSize = s_storage.maxPerformDataSize +
TRANSMIT_CALLDATA_FIXED_BYTES_OVERHEAD +
(TRANSMIT_CALLDATA_PER_SIGNER_BYTES_OVERHEAD * (hotVars.f + 1));
(uint256 chainModuleFixedOverhead, uint256 chainModulePerByteOverhead) = s_hotVars.chainModule.getGasOverhead();
maxGasOverhead +=
(REGISTRY_PER_SIGNER_GAS_OVERHEAD * (hotVars.f + 1)) +
((REGISTRY_PER_PERFORM_BYTE_GAS_OVERHEAD + chainModulePerByteOverhead) * maxCalldataSize) +
chainModuleFixedOverhead;

uint256 maxL1Fee = hotVars.gasCeilingMultiplier *
hotVars.chainModule.getMaxL1Fee(maxCalldataSize);
uint256 maxL1Fee = hotVars.gasCeilingMultiplier * hotVars.chainModule.getMaxL1Fee(maxCalldataSize);

(uint96 reimbursement, uint96 premium) = _calculatePaymentAmount(
hotVars,
Expand Down

0 comments on commit 351104a

Please sign in to comment.