Skip to content

Commit

Permalink
chore(protocol): make two state variables in TaikoL2.sol public and a…
Browse files Browse the repository at this point in the history
…dd `adjustExcess` (#17891)
  • Loading branch information
dantaik authored Aug 8, 2024
1 parent 57c8f6f commit ba21f68
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions packages/protocol/contracts/L2/TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ contract TaikoL2 is EssentialContract {

/// @notice The last synced L1 block height.
uint64 public lastSyncedBlock;
uint64 private parentTimestamp;
uint64 private parentGasTarget;
uint64 public parentTimestamp;
uint64 public parentGasTarget;

/// @notice The L1's chain ID.
uint64 public l1ChainId;
Expand Down Expand Up @@ -222,6 +222,23 @@ contract TaikoL2 is EssentialContract {
return LibL2Config.get();
}

/// @notice Returns the new gas excess that will keep the basefee the same.
/// @param _currGasExcess The current gas excess value.
/// @param _currGasTarget The current gas target.
/// @param _newGasTarget The new gas target.
/// @return newGasExcess_ The new gas excess value.
function adjustExcess(
uint64 _currGasExcess,
uint64 _currGasTarget,
uint64 _newGasTarget
)
public
pure
returns (uint64 newGasExcess_)
{
return Lib1559Math.adjustExcess(_currGasExcess, _currGasTarget, _newGasTarget);
}

/// @notice Tells if we need to validate basefee (for simulation).
/// @return Returns true to skip checking basefee mismatch.
function skipFeeCheck() public pure virtual returns (bool) {
Expand Down Expand Up @@ -270,8 +287,8 @@ contract TaikoL2 is EssentialContract {
private
{
if (
_anchorStateRoot == 0 || _anchorBlockId == 0
|| (block.number != 1 && _parentGasUsed == 0)
_anchorStateRoot == 0 || _anchorBlockId == 0 || _gasIssuancePerSecond == 0
|| _basefeeAdjustmentQuotient == 0 || (block.number != 1 && _parentGasUsed == 0)
) {
revert L2_INVALID_PARAM();
}
Expand All @@ -290,8 +307,7 @@ contract TaikoL2 is EssentialContract {
if (postFork && newGasTarget != parentGasTarget) {
// adjust parentGasExcess to keep the basefee unchanged. Note that due to math
// calculation precision, the basefee may change slightly.
parentGasExcess =
Lib1559Math.adjustExcess(parentGasExcess, parentGasTarget, newGasTarget);
parentGasExcess = adjustExcess(parentGasExcess, parentGasTarget, newGasTarget);
}

// Verify the base fee per gas is correct
Expand Down

0 comments on commit ba21f68

Please sign in to comment.