Merge branch 'fix/95-cache-reserves-count' into 'master'

Fixes #95

Closes #95

See merge request aave-tech/protocol-v2!105
This commit is contained in:
The-3D 2020-10-28 11:46:37 +00:00
commit a9c3a033ac

View File

@ -913,13 +913,16 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
* @dev adds a reserve to the array of the _reserves address * @dev adds a reserve to the array of the _reserves address
**/ **/
function _addReserveToList(address asset) internal { function _addReserveToList(address asset) internal {
require(_reservesCount < MAX_NUMBER_RESERVES, Errors.NO_MORE_RESERVES_ALLOWED);
uint256 reservesCount = _reservesCount;
require(reservesCount < MAX_NUMBER_RESERVES, Errors.NO_MORE_RESERVES_ALLOWED);
bool reserveAlreadyAdded = _reserves[asset].id != 0 || _reservesList[0] == asset; bool reserveAlreadyAdded = _reserves[asset].id != 0 || _reservesList[0] == asset;
if (!reserveAlreadyAdded) { if (!reserveAlreadyAdded) {
_reserves[asset].id = uint8(_reservesCount); _reserves[asset].id = uint8(reservesCount);
_reservesList[_reservesCount] = asset; _reservesList[reservesCount] = asset;
_reservesCount++; _reservesCount++;
} }