Skip to content

Commit

Permalink
Deprecate unnecessary public variables in L2 (#11247)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-chrzan authored Oct 15, 2024
1 parent 591b114 commit 131c499
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 80 deletions.
90 changes: 67 additions & 23 deletions packages/protocol/contracts-0.8/common/GasPriceMinimum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ contract GasPriceMinimum is
// TODO add IGasPriceMinimum
using FixidityLib for FixidityLib.Fraction;

uint256 public deprecated_gasPriceMinimum;
uint256 public gasPriceMinimumFloor;
uint256 private deprecated_gasPriceMinimum;
uint256 private deprecated_gasPriceMinimumFloor;

// Block congestion level targeted by the gas price minimum calculation.
FixidityLib.Fraction public targetDensity;
FixidityLib.Fraction private deprecated_targetDensity;

// Speed of gas price minimum adjustment due to congestion.
FixidityLib.Fraction public adjustmentSpeed;
FixidityLib.Fraction private deprecated_adjustmentSpeed;

uint256 public baseFeeOpCodeActivationBlock;
uint256 public constant ABSOLUTE_MINIMAL_GAS_PRICE = 1;
uint256 private deprecated_baseFeeOpCodeActivationBlock;
uint256 private constant ABSOLUTE_MINIMAL_GAS_PRICE = 1;

event TargetDensitySet(uint256 targetDensity);
event GasPriceMinimumFloorSet(uint256 gasPriceMinimumFloor);
Expand Down Expand Up @@ -112,7 +112,7 @@ contract GasPriceMinimum is
* @param tokenAddress The currency the gas price should be in (defaults to Celo).
* @return current gas price minimum in the requested currency
*/
function getGasPriceMinimum(address tokenAddress) external view returns (uint256) {
function getGasPriceMinimum(address tokenAddress) external view onlyL1 returns (uint256) {
return Math.max(_getGasPriceMinimum(tokenAddress), ABSOLUTE_MINIMAL_GAS_PRICE);
}
/**
Expand All @@ -123,7 +123,7 @@ contract GasPriceMinimum is
* @return Patch version of the contract.
*/
function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) {
return (1, 2, 0, 2);
return (1, 2, 1, 0);
}

/**
Expand All @@ -132,8 +132,11 @@ contract GasPriceMinimum is
* @dev Value is expected to be < 1.
*/
function setAdjustmentSpeed(uint256 _adjustmentSpeed) public onlyOwner onlyL1 {
adjustmentSpeed = FixidityLib.wrap(_adjustmentSpeed);
require(adjustmentSpeed.lt(FixidityLib.fixed1()), "adjustment speed must be smaller than 1");
deprecated_adjustmentSpeed = FixidityLib.wrap(_adjustmentSpeed);
require(
deprecated_adjustmentSpeed.lt(FixidityLib.fixed1()),
"adjustment speed must be smaller than 1"
);
emit AdjustmentSpeedSet(_adjustmentSpeed);
}

Expand All @@ -143,8 +146,11 @@ contract GasPriceMinimum is
* @dev Value is expected to be < 1.
*/
function setTargetDensity(uint256 _targetDensity) public onlyOwner onlyL1 {
targetDensity = FixidityLib.wrap(_targetDensity);
require(targetDensity.lt(FixidityLib.fixed1()), "target density must be smaller than 1");
deprecated_targetDensity = FixidityLib.wrap(_targetDensity);
require(
deprecated_targetDensity.lt(FixidityLib.fixed1()),
"target density must be smaller than 1"
);
emit TargetDensitySet(_targetDensity);
}

Expand All @@ -155,12 +161,15 @@ contract GasPriceMinimum is
*/
function setGasPriceMinimumFloor(uint256 _gasPriceMinimumFloor) public onlyOwner onlyL1 {
require(_gasPriceMinimumFloor > 0, "gas price minimum floor must be greater than zero");
gasPriceMinimumFloor = _gasPriceMinimumFloor;
deprecated_gasPriceMinimumFloor = _gasPriceMinimumFloor;
emit GasPriceMinimumFloorSet(_gasPriceMinimumFloor);
}

function gasPriceMinimum() public view returns (uint256) {
if (baseFeeOpCodeActivationBlock > 0 && block.number >= baseFeeOpCodeActivationBlock) {
function gasPriceMinimum() public view onlyL1 returns (uint256) {
if (
deprecated_baseFeeOpCodeActivationBlock > 0 &&
block.number >= deprecated_baseFeeOpCodeActivationBlock
) {
return block.basefee;
} else {
return deprecated_gasPriceMinimum;
Expand All @@ -179,25 +188,60 @@ contract GasPriceMinimum is
function getUpdatedGasPriceMinimum(
uint256 blockGasTotal,
uint256 blockGasLimit
) public view returns (uint256) {
) public view onlyL1 returns (uint256) {
FixidityLib.Fraction memory blockDensity = FixidityLib.newFixedFraction(
blockGasTotal,
blockGasLimit
);
bool densityGreaterThanTarget = blockDensity.gt(targetDensity);
bool densityGreaterThanTarget = blockDensity.gt(deprecated_targetDensity);
FixidityLib.Fraction memory densityDelta = densityGreaterThanTarget
? blockDensity.subtract(targetDensity)
: targetDensity.subtract(blockDensity);
? blockDensity.subtract(deprecated_targetDensity)
: deprecated_targetDensity.subtract(blockDensity);
FixidityLib.Fraction memory adjustment = densityGreaterThanTarget
? FixidityLib.fixed1().add(adjustmentSpeed.multiply(densityDelta))
: FixidityLib.fixed1().subtract(adjustmentSpeed.multiply(densityDelta));
? FixidityLib.fixed1().add(deprecated_adjustmentSpeed.multiply(densityDelta))
: FixidityLib.fixed1().subtract(deprecated_adjustmentSpeed.multiply(densityDelta));

uint256 newGasPriceMinimum = adjustment
.multiply(FixidityLib.newFixed(gasPriceMinimum()))
.add(FixidityLib.fixed1())
.fromFixed();

return newGasPriceMinimum >= gasPriceMinimumFloor ? newGasPriceMinimum : gasPriceMinimumFloor;
return
newGasPriceMinimum >= deprecated_gasPriceMinimumFloor
? newGasPriceMinimum
: deprecated_gasPriceMinimumFloor;
}

/**
* @notice Returns the gas price minimum floor.
* @return The gas price minimum floor.
*/
function gasPriceMinimumFloor() external view onlyL1 returns (uint256) {
return deprecated_gasPriceMinimumFloor;
}

/**
* @notice Returns the target density.
* @return The target density.
*/
function targetDensity() external view onlyL1 returns (uint256) {
return deprecated_targetDensity.unwrap();
}

/**
* @notice Returns the adjustment speed.
* @return The adjustment speed.
*/
function adjustmentSpeed() external view onlyL1 returns (uint256) {
return deprecated_adjustmentSpeed.unwrap();
}

/**
* @notice Returns the basefee opcode activation block.
* @return The basefee opcode activation block.
*/
function baseFeeOpCodeActivationBlock() external view onlyL1 returns (uint256) {
return deprecated_baseFeeOpCodeActivationBlock;
}

/**
Expand All @@ -213,7 +257,7 @@ contract GasPriceMinimum is
allowZero || _baseFeeOpCodeActivationBlock > 0,
"baseFee opCode activation block must be greater than zero"
);
baseFeeOpCodeActivationBlock = _baseFeeOpCodeActivationBlock;
deprecated_baseFeeOpCodeActivationBlock = _baseFeeOpCodeActivationBlock;
emit BaseFeeOpCodeActivationBlockSet(_baseFeeOpCodeActivationBlock);
}

Expand Down
40 changes: 26 additions & 14 deletions packages/protocol/contracts/common/FeeCurrencyWhitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ pragma solidity ^0.5.13;
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";

import "./interfaces/IFeeCurrencyWhitelist.sol";

import "../common/Initializable.sol";

import "../common/interfaces/ICeloVersionedContract.sol";
import "../../contracts-0.8/common/IsL2Check.sol";

/**
* @title Holds a whitelist of the ERC20+ tokens that can be used to pay for gas
Expand All @@ -16,10 +15,11 @@ contract FeeCurrencyWhitelist is
IFeeCurrencyWhitelist,
Ownable,
Initializable,
ICeloVersionedContract
ICeloVersionedContract,
IsL2Check
{
// Array of all the tokens enabled
address[] public whitelist;
address[] private deprecated_whitelist;

event FeeCurrencyWhitelisted(address token);

Expand All @@ -42,16 +42,28 @@ contract FeeCurrencyWhitelist is
* @dev Add a token to the whitelist
* @param tokenAddress The address of the token to add.
*/
function addToken(address tokenAddress) external onlyOwner {
whitelist.push(tokenAddress);
function addToken(address tokenAddress) external onlyOwner onlyL1 {
deprecated_whitelist.push(tokenAddress);
emit FeeCurrencyWhitelisted(tokenAddress);
}

/**
* @return a list of all tokens enabled as gas fee currency.
* @dev Once Celo becomes an L2, use the FeeCurrencyDirectory contract
* instead.
*/
function getWhitelist() external view onlyL1 returns (address[] memory) {
return deprecated_whitelist;
}

/**
* @notice Gets the whitelist item at the specified index.
* @return Address of a token in the whitelist.
* @dev Once Celo becomes an L2, use the FeeCurrencyDirectory contract
* instead.
*/
function getWhitelist() external view returns (address[] memory) {
return whitelist;
function whitelist(uint256 index) external view onlyL1 returns (address) {
return deprecated_whitelist[index];
}

/**
Expand All @@ -62,7 +74,7 @@ contract FeeCurrencyWhitelist is
* @return Patch version of the contract.
*/
function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) {
return (1, 1, 1, 0);
return (1, 1, 2, 0);
}

/**
Expand All @@ -71,11 +83,11 @@ contract FeeCurrencyWhitelist is
* @param tokenAddress The address of the token to remove.
* @param index The index of the token in the whitelist array.
*/
function removeToken(address tokenAddress, uint256 index) public onlyOwner {
require(whitelist[index] == tokenAddress, "Index does not match");
uint256 length = whitelist.length;
whitelist[index] = whitelist[length - 1];
whitelist.pop();
function removeToken(address tokenAddress, uint256 index) public onlyOwner onlyL1 {
require(deprecated_whitelist[index] == tokenAddress, "Index does not match");
uint256 length = deprecated_whitelist.length;
deprecated_whitelist[index] = deprecated_whitelist[length - 1];
deprecated_whitelist.pop();
emit FeeCurrencyWhitelistRemoved(tokenAddress);
}
}
32 changes: 26 additions & 6 deletions packages/protocol/contracts/governance/BlockchainParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ contract BlockchainParameters is Ownable, Initializable, UsingPrecompiles {
}

ClientVersion private minimumClientVersion; // obsolete
uint256 public blockGasLimit;
uint256 public intrinsicGasForAlternativeFeeCurrency;
LookbackWindow public uptimeLookbackWindow;
uint256 private deprecated_blockGasLimit;
uint256 private deprecated_intrinsicGasForAlternativeFeeCurrency;
LookbackWindow private uptimeLookbackWindow;

event IntrinsicGasForAlternativeFeeCurrencySet(uint256 gas);
event BlockGasLimitSet(uint256 limit);
Expand Down Expand Up @@ -67,15 +67,15 @@ contract BlockchainParameters is Ownable, Initializable, UsingPrecompiles {
* @return Patch version of the contract.
*/
function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) {
return (1, 3, 0, 1);
return (1, 3, 1, 0);
}

/**
* @notice Sets the block gas limit.
* @param gasLimit New block gas limit.
*/
function setBlockGasLimit(uint256 gasLimit) public onlyOwner onlyL1 {
blockGasLimit = gasLimit;
deprecated_blockGasLimit = gasLimit;
emit BlockGasLimitSet(gasLimit);
}

Expand All @@ -84,7 +84,7 @@ contract BlockchainParameters is Ownable, Initializable, UsingPrecompiles {
* @param gas Intrinsic gas for non-gold gas currencies.
*/
function setIntrinsicGasForAlternativeFeeCurrency(uint256 gas) public onlyOwner onlyL1 {
intrinsicGasForAlternativeFeeCurrency = gas;
deprecated_intrinsicGasForAlternativeFeeCurrency = gas;
emit IntrinsicGasForAlternativeFeeCurrencySet(gas);
}

Expand Down Expand Up @@ -116,6 +116,26 @@ contract BlockchainParameters is Ownable, Initializable, UsingPrecompiles {
require(lookbackWindow != 0, "UptimeLookbackWindow is not initialized");
}

/**
* @notice Gets the Celo L1 block gas limit.
* @return The block gas limit.
* @dev Once Celo becomes an L2, query Optimism's L1 SystemConfig contract
* instead.
*/
function blockGasLimit() public view onlyL1 returns (uint256) {
return deprecated_blockGasLimit;
}

/**
* @notice Gets the intrinsic gas paid for transactions using alternative fee
* currencies.
* @return The intrinsic gas for alternative fee currencies.
* @dev Once Celo becomes an L2, query the FeeCurrencyDirectory instead.
*/
function intrinsicGasForAlternativeFeeCurrency() public view onlyL1 returns (uint256) {
return deprecated_intrinsicGasForAlternativeFeeCurrency;
}

/**
* @notice Gets the uptime lookback window.
*/
Expand Down
Loading

0 comments on commit 131c499

Please sign in to comment.