Skip to content

Commit

Permalink
DEVSVCS-147: link balance monitor updates (#14108)
Browse files Browse the repository at this point in the history
* DEVSVCS-147: link balance monitor updates

* changeset
  • Loading branch information
FelixFan1992 authored Aug 16, 2024
1 parent c0c7649 commit 08194be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions contracts/.changeset/nasty-llamas-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/contracts': patch
---

DEVSVCS-147: add a reentrancy guard for balance monitor
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter
error InvalidWatchList();
error InvalidChainSelector();
error DuplicateAddress(address duplicate);
error ReentrantCall();

struct MonitoredAddress {
uint96 minBalance;
Expand Down Expand Up @@ -94,6 +95,8 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter
/// whenever a new one is deployed with the same dstChainSelector.
EnumerableMap.UintToAddressMap private s_onRampAddresses;

bool private reentrancyGuard;

/// @param admin is the administrator address of this contract
/// @param linkToken the LINK token address
/// @param minWaitPeriodSeconds represents the amount of time that has to wait a contract to be funded
Expand All @@ -116,6 +119,7 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter
setMaxPerform(maxPerform);
setMaxCheck(maxCheck);
setUpkeepInterval(upkeepInterval);
reentrancyGuard = false;
}

/// @notice Sets the list of subscriptions to watch and their funding parameters
Expand Down Expand Up @@ -259,7 +263,7 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter

/// @notice tries to fund an array of target addresses, checking if they're underfunded in the process
/// @param targetAddresses is an array of contract addresses to be funded in case they're underfunded
function topUp(address[] memory targetAddresses) public whenNotPaused {
function topUp(address[] memory targetAddresses) public whenNotPaused nonReentrant {
MonitoredAddress memory contractToFund;
uint256 minWaitPeriod = s_minWaitPeriodSeconds;
uint256 localBalance = i_linkToken.balanceOf(address(this));
Expand Down Expand Up @@ -457,6 +461,13 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter
_;
}

modifier nonReentrant() {
if (reentrancyGuard) revert ReentrantCall();
reentrancyGuard = true;
_;
reentrancyGuard = false;
}

/// @notice Pause the contract, which prevents executing performUpkeep
function pause() external onlyRole(ADMIN_ROLE) {
_pause();
Expand Down

0 comments on commit 08194be

Please sign in to comment.