Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving skip of updateState() by time, and caching dynamics for indexes #725

Merged
merged 3 commits into from
Nov 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions contracts/protocol/libraries/logic/ReserveLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,17 @@ library ReserveLogic {
DataTypes.ReserveData storage reserve,
DataTypes.ReserveCache memory reserveCache
) internal {
// If time didn't pass since last stored timestamp, skip state update
//solium-disable-next-line
if (reserve.lastUpdateTimestamp == uint40(block.timestamp)) {
return;
}

_updateIndexes(reserve, reserveCache);
_accrueToTreasury(reserve, reserveCache);

//solium-disable-next-line
reserve.lastUpdateTimestamp = uint40(block.timestamp);
}

/**
Expand Down Expand Up @@ -283,9 +292,6 @@ library ReserveLogic {
DataTypes.ReserveData storage reserve,
DataTypes.ReserveCache memory reserveCache
) internal {
reserveCache.nextLiquidityIndex = reserveCache.currLiquidityIndex;
reserveCache.nextVariableBorrowIndex = reserveCache.currVariableBorrowIndex;

// Only cumulating on the supply side if there is any income being produced
// The case of Reserve Factor 100% is not a problem (currentLiquidityRate == 0),
// as liquidity index should not be updated
Expand Down Expand Up @@ -314,9 +320,6 @@ library ReserveLogic {
);
reserve.variableBorrowIndex = reserveCache.nextVariableBorrowIndex.toUint128();
}

//solium-disable-next-line
reserve.lastUpdateTimestamp = uint40(block.timestamp);
}

/**
Expand All @@ -334,8 +337,9 @@ library ReserveLogic {

reserveCache.reserveConfiguration = reserve.configuration;
reserveCache.reserveFactor = reserveCache.reserveConfiguration.getReserveFactor();
reserveCache.currLiquidityIndex = reserve.liquidityIndex;
reserveCache.currVariableBorrowIndex = reserve.variableBorrowIndex;
reserveCache.currLiquidityIndex = reserveCache.nextLiquidityIndex = reserve.liquidityIndex;
reserveCache.currVariableBorrowIndex = reserveCache.nextVariableBorrowIndex = reserve
.variableBorrowIndex;
reserveCache.currLiquidityRate = reserve.currentLiquidityRate;
reserveCache.currVariableBorrowRate = reserve.currentVariableBorrowRate;

Expand Down