Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/MERC-954-mercury-feeds-should-pr…
Browse files Browse the repository at this point in the history
…obably-start-at-the-first-block-number-not-at-zero' into MERC-954-mercury-feeds-should-probably-start-at-the-first-block-number-not-at-zero
  • Loading branch information
samsondav committed Jun 21, 2023
2 parents 53a7341 + e90b177 commit e92a181
Show file tree
Hide file tree
Showing 40 changed files with 1,270 additions and 1,155 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ jobs:
- name: Check if image exists
if: needs.changes.outputs.src == 'true'
id: check-image
uses: smartcontractkit/chainlink-github-actions/docker/image-exists@bc6e3b5cf369b76e361d372ceb7d144525635ce0 # v2.2.0
uses: smartcontractkit/chainlink-github-actions/docker/image-exists@336617ae6d70fec60c15cc3382e17a4d2615a801 # v2.2.0
with:
repository: chainlink
tag: ${{ github.sha }}${{ matrix.image.tag-suffix }}
AWS_REGION: ${{ secrets.QA_AWS_REGION }}
AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
- name: Build Image
if: steps.check-image.outputs.exists == 'false' && needs.changes.outputs.src == 'true'
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/build-image@bc6e3b5cf369b76e361d372ceb7d144525635ce0 # v2.2.0
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/build-image@336617ae6d70fec60c15cc3382e17a4d2615a801 # v2.2.0
with:
cl_repo: smartcontractkit/chainlink
cl_ref: ${{ github.sha }}
Expand Down Expand Up @@ -209,7 +209,7 @@ jobs:
## Run this step when changes that require tests to be run are made
- name: Run Tests
if: needs.changes.outputs.src == 'true'
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@bc6e3b5cf369b76e361d372ceb7d144525635ce0 # v2.2.0
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@336617ae6d70fec60c15cc3382e17a4d2615a801 # v2.2.0
env:
PYROSCOPE_SERVER: ${{ matrix.product.pyroscope_env == '' && '' || !startsWith(github.ref, 'refs/tags/') && '' || secrets.QA_PYROSCOPE_INSTANCE }} # Avoid sending blank envs https://github.com/orgs/community/discussions/25725
PYROSCOPE_ENVIRONMENT: ${{ matrix.product.pyroscope_env }}
Expand All @@ -230,7 +230,7 @@ jobs:
## Run this step when changes that do not need the test to run are made
- name: Run Setup
if: needs.changes.outputs.src == 'false'
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-run-tests-environment@bc6e3b5cf369b76e361d372ceb7d144525635ce0 # v2.2.0
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-run-tests-environment@336617ae6d70fec60c15cc3382e17a4d2615a801 # v2.2.0
with:
test_download_vendor_packages_command: cd ./integration-tests && go mod download
go_mod_path: ./integration-tests/go.mod
Expand Down Expand Up @@ -314,7 +314,7 @@ jobs:
run: |
echo "Running migration tests from version '${{ steps.get_latest_version.outputs.latest_version }}' to: '${{ github.sha }}'"
- name: Run Migration Tests
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@bc6e3b5cf369b76e361d372ceb7d144525635ce0 # v2.2.0
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@336617ae6d70fec60c15cc3382e17a4d2615a801 # v2.2.0
with:
test_command_to_run: make test_need_operator_assets && cd ./integration-tests && go test -timeout 30m -count=1 -json ./migration 2>&1 | tee /tmp/gotest.log | gotestfmt
test_download_vendor_packages_command: cd ./integration-tests && go mod download
Expand Down Expand Up @@ -412,7 +412,7 @@ jobs:
steps:
- name: Check if image exists
id: check-image
uses: smartcontractkit/chainlink-github-actions/docker/image-exists@bc6e3b5cf369b76e361d372ceb7d144525635ce0 # v2.2.0
uses: smartcontractkit/chainlink-github-actions/docker/image-exists@336617ae6d70fec60c15cc3382e17a4d2615a801 # v2.2.0
with:
repository: chainlink-solana-tests
tag: ${{ needs.get_solana_sha.outputs.sha }}
Expand Down Expand Up @@ -551,7 +551,7 @@ jobs:
ref: ${{ needs.get_solana_sha.outputs.sha }}
- name: Run Tests
if: needs.changes.outputs.src == 'true'
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@bc6e3b5cf369b76e361d372ceb7d144525635ce0 # v2.2.0
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@336617ae6d70fec60c15cc3382e17a4d2615a801 # v2.2.0
with:
test_command_to_run: export ENV_JOB_IMAGE=${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com/chainlink-solana-tests:${{ needs.get_solana_sha.outputs.sha }} && make test_smoke
cl_repo: ${{ env.CHAINLINK_IMAGE }}
Expand All @@ -576,7 +576,7 @@ jobs:
### Start Live Testnet Section

testnet-smoke-tests-matrix:
if: startsWith(github.ref, 'refs/tags/') || ${{ github.event_name == 'schedule' }} ## Only run live tests on new tags and nightly
if: ${{ github.event_name == 'schedule' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) }} ## Only run live tests on new tags and nightly
environment: integration
permissions:
checks: write
Expand Down Expand Up @@ -619,7 +619,7 @@ jobs:
ref: ${{ github.event.pull_request.head.sha || github.event.merge_group.head_sha }}
## Only run OCR smoke test for now
- name: Run Tests
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@bc6e3b5cf369b76e361d372ceb7d144525635ce0 # v2.2.0
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@336617ae6d70fec60c15cc3382e17a4d2615a801 # v2.2.0
env:
PYROSCOPE_SERVER: ${{ secrets.QA_PYROSCOPE_INSTANCE }}
PYROSCOPE_ENVIRONMENT: ci-smoke-ocr-evm-${{ matrix.testnet }} # TODO: Only for OCR for now
Expand Down
3 changes: 3 additions & 0 deletions contracts/src/v0.8/dev/automation/2_1/KeeperRegistry2_1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ contract KeeperRegistry2_1 is KeeperRegistryBase2_1, OCR2Abstract, Chainable, ER
if (transmitter.active) revert RepeatedTransmitter();
transmitter.active = true;
transmitter.index = uint8(i);
// new transmitters start afresh from current totalPremium
// some spare change of premium from previous pool will be forfeited
transmitter.lastCollected = totalPremium;
s_transmitters[temp] = transmitter;
}
Expand Down Expand Up @@ -303,6 +305,7 @@ contract KeeperRegistry2_1 is KeeperRegistryBase2_1, OCR2Abstract, Chainable, ER
transcoder: onchainConfig.transcoder,
maxCheckDataSize: onchainConfig.maxCheckDataSize,
maxPerformDataSize: onchainConfig.maxPerformDataSize,
upkeepPrivilegeManager: onchainConfig.upkeepPrivilegeManager,
nonce: s_storage.nonce,
configCount: s_storage.configCount,
latestConfigBlockNumber: s_storage.latestConfigBlockNumber,
Expand Down
26 changes: 13 additions & 13 deletions contracts/src/v0.8/dev/automation/2_1/KeeperRegistryBase2_1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ abstract contract KeeperRegistryBase2_1 is ConfirmedOwner, ExecutionPrevention {
uint256 internal s_fallbackGasPrice;
uint256 internal s_fallbackLinkPrice;
uint256 internal s_expectedLinkBalance; // Used in case of erroneous LINK transfers to contract
address internal s_upkeepManager;
mapping(address => MigrationPermission) internal s_peerRegistryMigrationPermission; // Permissions for migration to and fro
mapping(uint256 => bytes) internal s_upkeepTriggerConfig; // upkeep triggers
mapping(uint256 => bytes) internal s_upkeepOffchainConfig; // general config set by users for each upkeep
mapping(uint256 => bytes) internal s_upkeepAdminOffchainConfig; // general config set by an administrative role
mapping(uint256 => bytes) internal s_upkeepPrivilegeConfig; // general config set by an administrative role

error ArrayHasNoEntries();
error CannotCancel();
Expand All @@ -119,7 +118,7 @@ abstract contract KeeperRegistryBase2_1 is ConfirmedOwner, ExecutionPrevention {
error OnlyCallableByPayee();
error OnlyCallableByProposedAdmin();
error OnlyCallableByProposedPayee();
error OnlyCallableByUpkeepManager();
error OnlyCallableByUpkeepPrivilegeManager();
error OnlyPausedUpkeep();
error OnlyUnpausedUpkeep();
error ParameterLengthError();
Expand Down Expand Up @@ -195,6 +194,7 @@ abstract contract KeeperRegistryBase2_1 is ConfirmedOwner, ExecutionPrevention {
* @member fallbackLinkPrice LINK price used if the LINK price feed is stale
* @member transcoder address of the transcoder contract
* @member registrar address of the registrar contract
* @member address which can set privilege for upkeeps
*/
struct OnchainConfig {
uint32 paymentPremiumPPB;
Expand All @@ -210,6 +210,7 @@ abstract contract KeeperRegistryBase2_1 is ConfirmedOwner, ExecutionPrevention {
uint256 fallbackLinkPrice;
address transcoder;
address[] registrars;
address upkeepPrivilegeManager;
}

/**
Expand Down Expand Up @@ -322,6 +323,7 @@ abstract contract KeeperRegistryBase2_1 is ConfirmedOwner, ExecutionPrevention {
uint32 maxCheckDataSize; // max length of checkData bytes
uint32 maxPerformDataSize; // max length of performData bytes
// 4 bytes to 3rd EVM word
address upkeepPrivilegeManager; // address which can set privilege for upkeeps
}

// Report transmitted by OCR to transmit function
Expand Down Expand Up @@ -408,7 +410,7 @@ abstract contract KeeperRegistryBase2_1 is ConfirmedOwner, ExecutionPrevention {
event PayeeshipTransferRequested(address indexed transmitter, address indexed from, address indexed to);
event PayeeshipTransferred(address indexed transmitter, address indexed from, address indexed to);
event PaymentWithdrawn(address indexed transmitter, uint256 indexed amount, address indexed to, address payee);
event UpkeepAdminOffchainConfigSet(uint256 indexed id, bytes adminOffchainConfig);
event UpkeepPrivilegeConfigSet(uint256 indexed id, bytes privilegeConfig);
event UpkeepAdminTransferRequested(uint256 indexed id, address indexed from, address indexed to);
event UpkeepAdminTransferred(uint256 indexed id, address indexed from, address indexed to);
event UpkeepCanceled(uint256 indexed id, uint64 indexed atBlockHeight);
Expand Down Expand Up @@ -448,7 +450,6 @@ abstract contract KeeperRegistryBase2_1 is ConfirmedOwner, ExecutionPrevention {
i_link = LinkTokenInterface(link);
i_linkNativeFeed = AggregatorV3Interface(linkNativeFeed);
i_fastGasFeed = AggregatorV3Interface(fastGasFeed);
s_upkeepManager = msg.sender;
}

/////////////
Expand Down Expand Up @@ -650,14 +651,13 @@ abstract contract KeeperRegistryBase2_1 is ConfirmedOwner, ExecutionPrevention {
) internal returns (uint96) {
Transmitter memory transmitter = s_transmitters[transmitterAddress];

uint96 uncollected = totalPremium - transmitter.lastCollected;
uint96 due = uncollected / payeeCount;
transmitter.balance += due;
transmitter.lastCollected = totalPremium;

// Transfer spare change to owner
s_storage.ownerLinkBalance += (uncollected - due * payeeCount);
s_transmitters[transmitterAddress] = transmitter;
if (transmitter.active) {
uint96 uncollected = totalPremium - transmitter.lastCollected;
uint96 due = uncollected / payeeCount;
transmitter.balance += due;
transmitter.lastCollected += due * payeeCount;
s_transmitters[transmitterAddress] = transmitter;
}

return transmitter.balance;
}
Expand Down
44 changes: 16 additions & 28 deletions contracts/src/v0.8/dev/automation/2_1/KeeperRegistryLogicB2_1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,12 @@ contract KeeperRegistryLogicB2_1 is KeeperRegistryBase2_1 {
s_peerRegistryMigrationPermission[peer] = permission;
}

/**
* @dev Called through KeeperRegistry main contract
*/
function setUpkeepAdminOffchainConfig(uint256 upkeepId, bytes calldata newAdminOffchainConfig) external {
if (msg.sender != s_upkeepManager) {
revert OnlyCallableByUpkeepManager();
function setUpkeepPrivilegeConfig(uint256 upkeepId, bytes calldata newPrivilegeConfig) external {
if (msg.sender != s_storage.upkeepPrivilegeManager) {
revert OnlyCallableByUpkeepPrivilegeManager();
}
s_upkeepAdminOffchainConfig[upkeepId] = newAdminOffchainConfig;
emit UpkeepAdminOffchainConfigSet(upkeepId, newAdminOffchainConfig);
}

/**
* @dev Called through KeeperRegistry main contract
*/
function setUpkeepManager(address newUpkeepManager) external onlyOwner {
s_upkeepManager = newUpkeepManager;
s_upkeepPrivilegeConfig[upkeepId] = newPrivilegeConfig;
emit UpkeepPrivilegeConfigSet(upkeepId, newPrivilegeConfig);
}

/////////////
Expand Down Expand Up @@ -297,8 +287,12 @@ contract KeeperRegistryLogicB2_1 is KeeperRegistryBase2_1 {
address query
) external view returns (bool active, uint8 index, uint96 balance, uint96 lastCollected, address payee) {
Transmitter memory transmitter = s_transmitters[query];
uint96 totalDifference = s_hotVars.totalPremium - transmitter.lastCollected;
uint96 pooledShare = totalDifference / uint96(s_transmittersList.length);

uint96 pooledShare = 0;
if (transmitter.active) {
uint96 totalDifference = s_hotVars.totalPremium - transmitter.lastCollected;
pooledShare = totalDifference / uint96(s_transmittersList.length);
}

return (
transmitter.active,
Expand Down Expand Up @@ -357,7 +351,8 @@ contract KeeperRegistryLogicB2_1 is KeeperRegistryBase2_1 {
fallbackGasPrice: s_fallbackGasPrice,
fallbackLinkPrice: s_fallbackLinkPrice,
transcoder: s_storage.transcoder,
registrars: s_registrars.values()
registrars: s_registrars.values(),
upkeepPrivilegeManager: s_storage.upkeepPrivilegeManager
});

return (state, config, s_signersList, s_transmittersList, s_hotVars.f);
Expand Down Expand Up @@ -390,16 +385,9 @@ contract KeeperRegistryLogicB2_1 is KeeperRegistryBase2_1 {
}

/**
* @notice returns the upkeep manager address
*/
function getUpkeepManager() external view returns (address) {
return s_upkeepManager;
}

/**
* @notice returns the upkeep administrative offchain config
* @notice returns the upkeep privilege config
*/
function getUpkeepAdminOffchainConfig(uint256 upkeepId) external view returns (bytes memory) {
return s_upkeepAdminOffchainConfig[upkeepId];
function getUpkeepPrivilegeConfig(uint256 upkeepId) external view returns (bytes memory) {
return s_upkeepPrivilegeConfig[upkeepId];
}
}

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions contracts/src/v0.8/tests/VerifiableLoadBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pragma solidity ^0.8.6;

import "../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol";
import "../automation/2_0/KeeperRegistrar2_0.sol";
import "../automation/2_0/KeeperRegistry2_0.sol";
import "../dev/automation/2_1/interfaces/IKeeperRegistryMaster.sol";
import {ArbSys} from "../dev/vendor/@arbitrum/nitro-contracts/src/precompiles/ArbSys.sol";

abstract contract VerifiableLoadBase is ConfirmedOwner {
error IndexOutOfRange();
Expand Down Expand Up @@ -41,7 +42,7 @@ abstract contract VerifiableLoadBase is ConfirmedOwner {
EnumerableSet.UintSet internal s_upkeepIDs;
KeeperRegistrar2_0 public registrar;
LinkTokenInterface public linkToken;
KeeperRegistry2_0 public registry;
IKeeperRegistryMaster public registry;
// check if an upkeep is eligible for adding funds at this interval
uint256 public upkeepTopUpCheckInterval = 5;
// an upkeep will get this amount of LINK for every top up
Expand All @@ -63,7 +64,7 @@ abstract contract VerifiableLoadBase is ConfirmedOwner {
constructor(address registrarAddress, bool useArb) ConfirmedOwner(msg.sender) {
registrar = KeeperRegistrar2_0(registrarAddress);
(, , , address registryAddress, ) = registrar.getRegistrationConfig();
registry = KeeperRegistry2_0(payable(address(registryAddress)));
registry = IKeeperRegistryMaster(payable(address(registryAddress)));
linkToken = registrar.LINK();
useArbitrumBlockNum = useArb;
}
Expand Down Expand Up @@ -95,7 +96,7 @@ abstract contract VerifiableLoadBase is ConfirmedOwner {
function setConfig(KeeperRegistrar2_0 newRegistrar) external {
registrar = newRegistrar;
(, , , address registryAddress, ) = registrar.getRegistrationConfig();
registry = KeeperRegistry2_0(payable(address(registryAddress)));
registry = IKeeperRegistryMaster(payable(address(registryAddress)));
linkToken = registrar.LINK();

emit RegistrarSet(address(registrar));
Expand Down Expand Up @@ -154,7 +155,7 @@ abstract contract VerifiableLoadBase is ConfirmedOwner {
upkeepContract: address(this),
gasLimit: gasLimit,
adminAddress: address(this), // use address of this contract as the admin
checkData: bytes(""), // update check data later bc upkeep id is not available now
checkData: bytes(""), // update pipeline data later bc upkeep id is not available now
offchainConfig: bytes(""),
amount: amount
});
Expand Down Expand Up @@ -183,13 +184,13 @@ abstract contract VerifiableLoadBase is ConfirmedOwner {
}

/**
* @notice updates check data for an upkeep. In order for the upkeep to be performed, the check data must be the abi encoded upkeep ID.
* @notice updates pipeline data for an upkeep. In order for the upkeep to be performed, the pipeline data must be the abi encoded upkeep ID.
* @param upkeepId the upkeep ID
* @param checkData the new check data for the upkeep
* @param pipelineData the new pipeline data for the upkeep
*/
function updateCheckData(uint256 upkeepId, bytes calldata checkData) external {
registry.updateCheckData(upkeepId, checkData);
checkDatas[upkeepId] = checkData;
function updateUpkeepPipelineData(uint256 upkeepId, bytes calldata pipelineData) external {
registry.setUpkeepPipelineData(upkeepId, pipelineData);
checkDatas[upkeepId] = pipelineData;
}

function withdrawLinks(uint256 upkeepId) external {
Expand Down Expand Up @@ -297,14 +298,14 @@ abstract contract VerifiableLoadBase is ConfirmedOwner {
}

/**
* @notice batch updating check data for all upkeeps.
* @notice batch updating pipeline data for all upkeeps.
* @param upkeepIds an array of upkeep IDs
*/
function batchUpdateCheckData(uint256[] calldata upkeepIds) external {
function batchUpdatePipelineData(uint256[] calldata upkeepIds) external {
uint256 len = upkeepIds.length;
for (uint256 i = 0; i < len; i++) {
uint256 upkeepId = upkeepIds[i];
this.updateCheckData(upkeepId, abi.encode(upkeepId));
this.updateUpkeepPipelineData(upkeepId, abi.encode(upkeepId));
}
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/tests/VerifiableLoadMercuryUpkeep.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ contract VerifiableLoadMercuryUpkeep is VerifiableLoadBase, FeedLookupCompatible
// minBalanceThresholdMultiplier (20) * min balance. If not, add addLinkAmount (0.2) to the upkeep
// upkeepTopUpCheckInterval, minBalanceThresholdMultiplier, and addLinkAmount are configurable
if (blockNum - lastTopUpBlocks[upkeepId] > upkeepTopUpCheckInterval) {
UpkeepInfo memory info = registry.getUpkeep(upkeepId);
KeeperRegistryBase2_1.UpkeepInfo memory info = registry.getUpkeep(upkeepId);
uint96 minBalance = registry.getMinBalanceForUpkeep(upkeepId);
if (info.balance < minBalanceThresholdMultiplier * minBalance) {
this.addFunds(upkeepId, addLinkAmount);
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/tests/VerifiableLoadUpkeep.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ contract VerifiableLoadUpkeep is VerifiableLoadBase {
// minBalanceThresholdMultiplier (20) * min balance. If not, add addLinkAmount (0.2) to the upkeep
// upkeepTopUpCheckInterval, minBalanceThresholdMultiplier, and addLinkAmount are configurable
if (blockNum - lastTopUpBlocks[upkeepId] > upkeepTopUpCheckInterval) {
UpkeepInfo memory info = registry.getUpkeep(upkeepId);
KeeperRegistryBase2_1.UpkeepInfo memory info = registry.getUpkeep(upkeepId);
uint96 minBalance = registry.getMinBalanceForUpkeep(upkeepId);
if (info.balance < minBalanceThresholdMultiplier * minBalance) {
this.addFunds(upkeepId, addLinkAmount);
Expand Down
Loading

0 comments on commit e92a181

Please sign in to comment.