Skip to content

Commit

Permalink
Changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkaseman committed Feb 19, 2024
1 parent 86321d6 commit 97fea36
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 101 deletions.
116 changes: 58 additions & 58 deletions contracts/gas-snapshots/functions.gas-snapshot

Large diffs are not rendered by default.

34 changes: 15 additions & 19 deletions contracts/src/v0.8/functions/dev/v1_X/FunctionsBilling.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ abstract contract FunctionsBilling is Routable, IFunctionsBilling {
uint96 juelsPerGas,
uint256 l1FeeShareWei,
uint96 callbackCostJuels,
uint72 donFee,
uint72 adminFee,
uint72 operationFee
uint72 donFeeJuels,
uint72 adminFeeJuels,
uint72 operationFeeJuels
);

// ================================================================
Expand Down Expand Up @@ -124,11 +124,10 @@ abstract contract FunctionsBilling is Routable, IFunctionsBilling {

/// @inheritdoc IFunctionsBilling
function getWeiPerUnitLink() public view returns (uint256) {
FunctionsBillingConfig memory config = s_config;
(, int256 weiPerUnitLink, , uint256 timestamp, ) = s_linkToNativeFeed.latestRoundData();
// solhint-disable-next-line not-rely-on-time
if (config.feedStalenessSeconds < block.timestamp - timestamp && config.feedStalenessSeconds > 0) {
return config.fallbackNativePerUnitLink;
if (s_config.feedStalenessSeconds < block.timestamp - timestamp && s_config.feedStalenessSeconds > 0) {
return s_config.fallbackNativePerUnitLink;
}
if (weiPerUnitLink <= 0) {
revert InvalidLinkWeiPrice(weiPerUnitLink);
Expand All @@ -144,11 +143,10 @@ abstract contract FunctionsBilling is Routable, IFunctionsBilling {

/// @inheritdoc IFunctionsBilling
function getUsdPerUnitLink() public view returns (uint256, uint8) {
FunctionsBillingConfig memory config = s_config;
(, int256 usdPerUnitLink, , uint256 timestamp, ) = s_linkToUsdFeed.latestRoundData();
// solhint-disable-next-line not-rely-on-time
if (config.feedStalenessSeconds < block.timestamp - timestamp && config.feedStalenessSeconds > 0) {
return (config.fallbackUsdPerUnitLink, config.fallbackUsdPerUnitLinkDecimals);
if (s_config.feedStalenessSeconds < block.timestamp - timestamp && s_config.feedStalenessSeconds > 0) {
return (s_config.fallbackUsdPerUnitLink, s_config.fallbackUsdPerUnitLinkDecimals);
}
if (usdPerUnitLink <= 0) {
revert InvalidUsdLinkPrice(usdPerUnitLink);
Expand Down Expand Up @@ -224,10 +222,8 @@ abstract contract FunctionsBilling is Routable, IFunctionsBilling {
function _startBilling(
FunctionsResponse.RequestMeta memory request
) internal returns (FunctionsResponse.CommitmentWithOperationFee memory commitment) {
FunctionsBillingConfig memory config = s_config;

// Nodes should support all past versions of the structure
if (request.dataVersion > config.maxSupportedRequestDataVersion) {
if (request.dataVersion > s_config.maxSupportedRequestDataVersion) {
revert UnsupportedRequestDataVersion();
}

Expand All @@ -246,7 +242,7 @@ abstract contract FunctionsBilling is Routable, IFunctionsBilling {
revert InsufficientBalance();
}

uint32 timeoutTimestamp = uint32(block.timestamp + config.requestTimeoutSeconds);
uint32 timeoutTimestamp = uint32(block.timestamp + s_config.requestTimeoutSeconds);
bytes32 requestId = keccak256(
abi.encode(
address(this),
Expand Down Expand Up @@ -274,8 +270,8 @@ abstract contract FunctionsBilling is Routable, IFunctionsBilling {
requestId: requestId,
donFee: donFee,
operationFee: operationFee,
gasOverheadBeforeCallback: config.gasOverheadBeforeCallback,
gasOverheadAfterCallback: config.gasOverheadAfterCallback
gasOverheadBeforeCallback: s_config.gasOverheadBeforeCallback,
gasOverheadAfterCallback: s_config.gasOverheadAfterCallback
});

s_requestCommitments[requestId] = keccak256(abi.encode(commitment));
Expand Down Expand Up @@ -352,9 +348,9 @@ abstract contract FunctionsBilling is Routable, IFunctionsBilling {
juelsPerGas: juelsPerGas,
l1FeeShareWei: l1FeeShareWei,
callbackCostJuels: callbackCostJuels,
donFee: commitment.donFee,
adminFee: commitment.adminFee,
operationFee: commitment.operationFee
donFeeJuels: commitment.donFee,
adminFeeJuels: commitment.adminFee,
operationFeeJuels: commitment.operationFee
});
}
return resultCode;
Expand Down Expand Up @@ -439,7 +435,7 @@ abstract contract FunctionsBilling is Routable, IFunctionsBilling {
function _isExistingRequest(bytes32 requestId) internal view returns (bool) {
return s_requestCommitments[requestId] != bytes32(0);
}

// Overriden in FunctionsCoordinator.sol
function _owner() internal view virtual returns (address owner);
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ contract FunctionsCoordinator is OCR2Base, IFunctionsCoordinator, FunctionsBilli

/// @dev check if node is in current transmitter list
function _isTransmitter(address node) internal view returns (bool) {
address[] memory nodes = s_transmitters;
// Bounded by "maxNumOracles" on OCR2Abstract.sol
for (uint256 i = 0; i < nodes.length; ++i) {
if (nodes[i] == node) {
for (uint256 i = 0; i < s_transmitters.length; ++i) {
if (s_transmitters[i] == node) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ struct FunctionsBillingConfig {
uint32 feedStalenessSeconds; // ║ How long before we consider the feed price to be stale and fallback to fallbackNativePerUnitLink.
uint32 gasOverheadBeforeCallback; // ║ Represents the average gas execution cost before the fulfillment callback. This amount is always billed for every request.
uint32 gasOverheadAfterCallback; // ║ Represents the average gas execution cost after the fulfillment callback. This amount is always billed for every request.
uint72 donFee; // ║ Additional flat fee (denominated in cents of USD, paid as LINK) that will be split between Node Operators.
uint40 minimumEstimateGasPriceWei; // ║ The lowest amount of wei that will be used as the tx.gasprice when estimating the cost to fulfill the request
uint16 maxSupportedRequestDataVersion; // ═══════╝ The highest support request data version supported by the node. All lower versions should also be supported.
uint224 fallbackNativePerUnitLink; // ═══════════╗ Fallback NATIVE CURRENCY / LINK conversion rate if the data feed is stale
uint32 requestTimeoutSeconds; // ════════════════╝ How many seconds it takes before we consider a request to be timed out
uint72 operationFee; // ═════════════════════════╗ Additional flat fee (denominated in cents of USD, paid as LINK) that will be paid to the owner of the Coordinator contract.
uint16 maxSupportedRequestDataVersion; // ║ The highest support request data version supported by the node. All lower versions should also be supported.
uint64 fallbackUsdPerUnitLink; // ║ Fallback LINK / USD conversion rate if the data feed is stale
uint8 fallbackUsdPerUnitLinkDecimals; // ════════╝ Fallback LINK / USD conversion rate decimal places if the data feed is stale
uint224 fallbackNativePerUnitLink; // ═══════════╗ Fallback NATIVE CURRENCY / LINK conversion rate if the data feed is stale
uint32 requestTimeoutSeconds; // ════════════════╝ How many seconds it takes before we consider a request to be timed out
uint16 donFee; // ═══════════════════════════════╗ Additional flat fee (denominated in cents of USD, paid as LINK) that will be split between Node Operators.
uint16 operationFee; // ═════════════════════════╝ Additional flat fee (denominated in cents of USD, paid as LINK) that will be paid to the owner of the Coordinator contract.
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ library FunctionsResponse {
uint40 gasOverheadBeforeCallback; // ║ Represents the average gas execution cost before the fulfillment callback.
uint40 gasOverheadAfterCallback; // ║ Represents the average gas execution cost after the fulfillment callback.
uint32 timeoutTimestamp; // ═══════════╝ The timestamp at which a request will be eligible to be timed out
uint72 operationFee; // ══════════════════════ Flat fee (in Juels of LINK) that will be paid to the Coordinator Owner for operation of the network
uint72 operationFee; // ═══════════════ Flat fee (in Juels of LINK) that will be paid to the Coordinator Owner for operation of the network
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ contract FunctionsBilling_UpdateConfig is FunctionsRouterSetup {
function setUp() public virtual override {
FunctionsRouterSetup.setUp();

// Multiply all config values by 2 to confirm that they change
configToSet = FunctionsBillingConfig({
feedStalenessSeconds: getCoordinatorConfig().feedStalenessSeconds * 2,
gasOverheadAfterCallback: getCoordinatorConfig().gasOverheadAfterCallback * 2,
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/v0.8/functions/tests/v1_X/Setup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ contract FunctionsRouterSetup is BaseTest {

uint16 internal s_maxConsumersPerSubscription = 3;
uint72 internal s_adminFee = 100; // 100 Juels
uint72 internal s_donFee = 100; // $1
uint72 internal s_operationFee = 100; // $1
uint16 internal s_donFee = 100; // $1
uint16 internal s_operationFee = 100; // $1
bytes4 internal s_handleOracleFulfillmentSelector = 0x0ca76175;
uint16 s_subscriptionDepositMinimumRequests = 1;
uint72 s_subscriptionDepositJuels = 11 * JUELS_PER_LINK;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ functions_allow_list: ../../../contracts/solc/v0.8.19/functions/v1_X/TermsOfServ
functions_billing_registry_events_mock: ../../../contracts/solc/v0.8.6/functions/v0_0_0/FunctionsBillingRegistryEventsMock.abi ../../../contracts/solc/v0.8.6/functions/v0_0_0/FunctionsBillingRegistryEventsMock.bin 50deeb883bd9c3729702be335c0388f9d8553bab4be5e26ecacac496a89e2b77
functions_client: ../../../contracts/solc/v0.8.19/functions/v1_X/FunctionsClient.abi ../../../contracts/solc/v0.8.19/functions/v1_X/FunctionsClient.bin 2368f537a04489c720a46733f8596c4fc88a31062ecfa966d05f25dd98608aca
functions_client_example: ../../../contracts/solc/v0.8.19/functions/v1_X/FunctionsClientExample.abi ../../../contracts/solc/v0.8.19/functions/v1_X/FunctionsClientExample.bin abf32e69f268f40e8530eb8d8e96bf310b798a4c0049a58022d9d2fb527b601b
functions_coordinator: ../../../contracts/solc/v0.8.19/functions/v1_X/FunctionsCoordinator.abi ../../../contracts/solc/v0.8.19/functions/v1_X/FunctionsCoordinator.bin 87c95b1fd19ea664fbfae422a402b700c8da94eb47b06e676a25d1b159bfda63
functions_coordinator: ../../../contracts/solc/v0.8.19/functions/v1_X/FunctionsCoordinator.abi ../../../contracts/solc/v0.8.19/functions/v1_X/FunctionsCoordinator.bin 8c47e8239e1c8d000c832bba7d0148df104002f70366b4d8238f272d43c15edc
functions_coordinator_1_1_0: ../../../contracts/solc/v0.8.19/functions/v1_1_0/FunctionsCoordinator.abi ../../../contracts/solc/v0.8.19/functions/v1_1_0/FunctionsCoordinator.bin 88c2f899cfcb7b21530741b5446f3a32c92d8b457bfdd2a0160f51364b8d5d1a
functions_load_test_client: ../../../contracts/solc/v0.8.19/functions/v1_X/FunctionsLoadTestClient.abi ../../../contracts/solc/v0.8.19/functions/v1_X/FunctionsLoadTestClient.bin c8dbbd5ebb34435800d6674700068837c3a252db60046a14b0e61e829db517de
functions_oracle_events_mock: ../../../contracts/solc/v0.8.6/functions/v0_0_0/FunctionsOracleEventsMock.abi ../../../contracts/solc/v0.8.6/functions/v0_0_0/FunctionsOracleEventsMock.bin 3ca70f966f8fe751987f0ccb50bebb6aa5be77e4a9f835d1ae99e0e9bfb7d52c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ func StartNewChainWithContracts(t *testing.T, nClients int) (*bind.TransactOpts,
GasOverheadBeforeCallback: uint32(325_000),
GasOverheadAfterCallback: uint32(50_000),
RequestTimeoutSeconds: uint32(300),
DonFee: big.NewInt(0),
DonFee: uint16(0),
MaxSupportedRequestDataVersion: uint16(1),
FulfillmentGasPriceOverEstimationBP: uint32(1_000),
FallbackNativePerUnitLink: big.NewInt(5_000_000_000_000_000),
MinimumEstimateGasPriceWei: big.NewInt(1_000_000_000),
OperationFee: big.NewInt(0),
OperationFee: uint16(0),
FallbackUsdPerUnitLink: uint64(1_400_000_000),
FallbackUsdPerUnitLinkDecimals: uint8(8),
}
Expand Down

0 comments on commit 97fea36

Please sign in to comment.