From deec15a3b57545ca1248d284b2399f8daf4e62f2 Mon Sep 17 00:00:00 2001 From: shotaro <10378902+shotaronowhere@users.noreply.github.com> Date: Wed, 10 Apr 2024 13:05:54 -0300 Subject: [PATCH] chore: refactor --- src/bridge/SequencerInbox.sol | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/bridge/SequencerInbox.sol b/src/bridge/SequencerInbox.sol index 47e39d4e1..aa7f4b0fa 100644 --- a/src/bridge/SequencerInbox.sol +++ b/src/bridge/SequencerInbox.sol @@ -304,14 +304,14 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox messageDataHash ); + uint256 delayBlocks_ = delayBlocks; + if (isDelayBufferable) { // proactively apply any pending delay buffer updates before the force included message l1BlockAndTime buffer.update(l1BlockAndTime[0]); + delayBlocks_ = delayBufferableBlocks(buffer.bufferBlocks); emit BufferUpdated(buffer.bufferBlocks); } - uint256 delayBlocks_ = isDelayBufferable && buffer.bufferBlocks < delayBlocks - ? buffer.bufferBlocks - : delayBlocks; // Can only force-include after the Sequencer-only window has expired. if (l1BlockAndTime[0] + delayBlocks_ >= block.number) revert ForceIncludeBlockTooSoon(); @@ -836,13 +836,16 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox uint64 _delayBlocks = delayBlocks; if (isDelayBufferable) { uint64 _buffer = buffer.pendingBufferUpdate(blockNumber); - if (_buffer < _delayBlocks) { - _delayBlocks = _buffer; - } + _delayBlocks = delayBufferableBlocks(_buffer); } return blockNumber + _delayBlocks; } + /// @notice Calculates the buffer dependent delay blocks + function delayBufferableBlocks(uint64 _buffer) internal view returns (uint64) { + return _buffer < delayBlocks ? _buffer : delayBlocks; + } + function _setBufferConfig(BufferConfig memory bufferConfig_) internal { if (!isDelayBufferable) revert NotDelayBufferable(); if (!DelayBuffer.isValidBufferConfig(bufferConfig_)) revert BadBufferConfig(); @@ -850,7 +853,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox if (buffer.bufferBlocks == 0 || buffer.bufferBlocks > bufferConfig_.max) { buffer.bufferBlocks = bufferConfig_.max; } - if (buffer.bufferBlocks < bufferConfig_.threshold){ + if (buffer.bufferBlocks < bufferConfig_.threshold) { buffer.bufferBlocks = bufferConfig_.threshold; } buffer.max = bufferConfig_.max;