Skip to content

Commit 19964f3

Browse files
committed
feat: sequencer inbox optimization
1 parent 798934b commit 19964f3

29 files changed

+587
-801
lines changed

deploy/BridgeStubCreator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = async hre => {
33
const { deploy } = deployments
44
const { deployer } = await getNamedAccounts()
55

6-
await deploy('BridgeStub', { from: deployer, args: [] })
6+
await deploy('BridgeStub', { from: deployer, args: [deployer] })
77
}
88

99
module.exports.tags = ['BridgeStub', 'test']

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"test:e2e": "hardhat test test/e2e/*.ts",
3737
"postinstall": "patch-package",
3838
"deploy-factory": "hardhat run scripts/deployment.ts",
39+
"deploy-rollup": "hardhat run scripts/rollupCreation.ts",
3940
"deploy-eth-rollup": "hardhat run scripts/createEthRollup.ts",
4041
"deploy-erc20-rollup": "hardhat run scripts/createERC20Rollup.ts"
4142
},

scripts/config.ts.example

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ export const config = {
1919
'{"chainId":13331370,"homesteadBlock":0,"daoForkBlock":null,"daoForkSupport":true,"eip150Block":0,"eip150Hash":"0x0000000000000000000000000000000000000000000000000000000000000000","eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"constantinopleBlock":0,"petersburgBlock":0,"istanbulBlock":0,"muirGlacierBlock":0,"berlinBlock":0,"londonBlock":0,"clique":{"period":0,"epoch":0},"arbitrum":{"EnableArbOS":true,"AllowDebugPrecompiles":false,"DataAvailabilityCommittee":false,"InitialArbOSVersion":10,"InitialChainOwner":"0x1234123412341234123412341234123412341234","GenesisBlockNum":0}}',
2020
genesisBlockNum: ethers.BigNumber.from('0'),
2121
sequencerInboxMaxTimeVariation: {
22-
delayBlocks: ethers.BigNumber.from('5760'),
23-
futureBlocks: ethers.BigNumber.from('12'),
24-
delaySeconds: ethers.BigNumber.from('86400'),
25-
futureSeconds: ethers.BigNumber.from('3600'),
22+
delayBlocks: 5760,
23+
futureBlocks: 12,
24+
delaySeconds: 86400,
25+
futureSeconds: 3600,
2626
},
2727
},
2828
validators: [

src/bridge/AbsBridge.sol

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ import {
1414
NotSequencerInbox,
1515
NotOutbox,
1616
InvalidOutboxSet,
17-
BadSequencerMessageNumber
17+
BadSequencerMessageNumber,
18+
EmptyDelayedMessagesRead,
19+
DelayedBackwards,
20+
DelayedTooFar
1821
} from "../libraries/Error.sol";
1922
import "./IBridge.sol";
2023
import "./Messages.sol";
2124
import "../libraries/DelegateCallAware.sol";
25+
import "./ISequencerInbox.sol";
2226

2327
import {L1MessageType_batchPostingReport} from "../libraries/MessageTypes.sol";
2428

@@ -55,8 +59,15 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
5559

5660
uint256 public override sequencerReportedSubMessageCount;
5761

62+
uint256 public totalDelayedMessagesRead;
63+
5864
address internal constant EMPTY_ACTIVEOUTBOX = address(type(uint160).max);
5965

66+
function postUpgradeInit() external onlyDelegated onlyProxyOwner {
67+
totalDelayedMessagesRead = ISequencerInbox(sequencerInbox).totalDelayedMessagesRead();
68+
if (totalDelayedMessagesRead == 0) revert EmptyDelayedMessagesRead();
69+
}
70+
6071
modifier onlyRollupOrOwner() {
6172
if (msg.sender != address(rollup)) {
6273
address rollupOwner = rollup.owner();
@@ -101,7 +112,9 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
101112
bytes32 dataHash,
102113
uint256 afterDelayedMessagesRead,
103114
uint256 prevMessageCount,
104-
uint256 newMessageCount
115+
uint256 newMessageCount,
116+
TimeBounds memory timeBounds,
117+
BatchDataLocation batchDataLocation
105118
)
106119
external
107120
onlySequencerInbox
@@ -119,6 +132,9 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
119132
) {
120133
revert BadSequencerMessageNumber(sequencerReportedSubMessageCount, prevMessageCount);
121134
}
135+
if (afterDelayedMessagesRead > delayedInboxAccs.length) revert DelayedTooFar();
136+
if (afterDelayedMessagesRead < totalDelayedMessagesRead) revert DelayedBackwards();
137+
122138
sequencerReportedSubMessageCount = newMessageCount;
123139
seqMessageIndex = sequencerInboxAccs.length;
124140
if (sequencerInboxAccs.length > 0) {
@@ -129,6 +145,18 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
129145
}
130146
acc = keccak256(abi.encodePacked(beforeAcc, dataHash, delayedAcc));
131147
sequencerInboxAccs.push(acc);
148+
totalDelayedMessagesRead = afterDelayedMessagesRead;
149+
150+
emit SequencerBatchDelivered(
151+
seqMessageIndex,
152+
beforeAcc,
153+
acc,
154+
delayedAcc,
155+
afterDelayedMessagesRead,
156+
timeBounds,
157+
batchDataLocation,
158+
msg.sender
159+
);
132160
}
133161

134162
/// @inheritdoc IBridge
@@ -304,5 +332,5 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
304332
* variables without shifting down storage in the inheritance chain.
305333
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
306334
*/
307-
uint256[40] private __gap;
335+
uint256[39] private __gap;
308336
}

src/bridge/AbsOutbox.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ abstract contract AbsOutbox is DelegateCallAware, IOutbox {
7676
});
7777
bridge = _bridge;
7878
rollup = address(_bridge.rollup());
79+
if (address(rollup) == address(0)) revert RollupNotChanged();
7980
}
8081

8182
function postUpgradeInit() external onlyDelegated onlyProxyOwner {

src/bridge/IBridge.sol

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
// solhint-disable-next-line compiler-version
66
pragma solidity >=0.6.9 <0.9.0;
7+
pragma experimental ABIEncoderV2;
78

89
import "./IOwnable.sol";
910

@@ -48,6 +49,17 @@ interface IBridge {
4849
bytes data
4950
);
5051

52+
event SequencerBatchDelivered(
53+
uint256 indexed batchSequenceNumber,
54+
bytes32 indexed beforeAcc,
55+
bytes32 indexed afterAcc,
56+
bytes32 delayedAcc,
57+
uint256 afterDelayedMessagesRead,
58+
TimeBounds timeBounds,
59+
BatchDataLocation dataLocation,
60+
address sequencerInbox
61+
);
62+
5163
event InboxToggle(address indexed inbox, bool enabled);
5264

5365
event OutboxToggle(address indexed outbox, bool enabled);
@@ -88,13 +100,17 @@ interface IBridge {
88100

89101
function sequencerMessageCount() external view returns (uint256);
90102

103+
function totalDelayedMessagesRead() external view returns (uint256);
104+
91105
// ---------- onlySequencerInbox functions ----------
92106

93107
function enqueueSequencerMessage(
94108
bytes32 dataHash,
95109
uint256 afterDelayedMessagesRead,
96110
uint256 prevMessageCount,
97-
uint256 newMessageCount
111+
uint256 newMessageCount,
112+
TimeBounds memory timeBounds,
113+
BatchDataLocation dataLocation
98114
)
99115
external
100116
returns (

src/bridge/ISequencerInbox.sol

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,18 @@ import "./IDelayedMessageProvider.sol";
1111
import "./IBridge.sol";
1212

1313
interface ISequencerInbox is IDelayedMessageProvider {
14+
/// @notice The maximum amount of time variatin between a message being posted on the L1 and being executed on the L2
15+
/// @param delayBlocks The max amount of blocks in the past that a message can be received on L2
16+
/// @param futureBlocks The max amount of blocks in the future that a message can be received on L2
17+
/// @param delaySeconds The max amount of seconds in the past that a message can be received on L2
18+
/// @param futureSeconds The max amount of seconds in the future that a message can be received on L2
1419
struct MaxTimeVariation {
1520
uint64 delayBlocks;
1621
uint64 futureBlocks;
1722
uint64 delaySeconds;
1823
uint64 futureSeconds;
1924
}
2025

21-
event SequencerBatchDelivered(
22-
uint256 indexed batchSequenceNumber,
23-
bytes32 indexed beforeAcc,
24-
bytes32 indexed afterAcc,
25-
bytes32 delayedAcc,
26-
uint256 afterDelayedMessagesRead,
27-
IBridge.TimeBounds timeBounds,
28-
IBridge.BatchDataLocation dataLocation
29-
);
30-
3126
event OwnerFunctionCalled(uint256 indexed id);
3227

3328
/// @dev a separate event that emits batch data when this isn't easily accessible in the tx.input
@@ -39,6 +34,8 @@ interface ISequencerInbox is IDelayedMessageProvider {
3934
/// @dev a keyset was invalidated
4035
event InvalidateKeyset(bytes32 indexed keysetHash);
4136

37+
/// @notice The total number of delated messages read in the bridge
38+
/// @dev We surface this here for backwards compatibility
4239
function totalDelayedMessagesRead() external view returns (uint256);
4340

4441
function bridge() external view returns (IBridge);
@@ -103,9 +100,6 @@ interface ISequencerInbox is IDelayedMessageProvider {
103100

104101
function dasKeySetInfo(bytes32) external view returns (bool, uint64);
105102

106-
/// @notice Remove force inclusion delay after a L1 chainId fork
107-
function removeDelayAfterFork() external;
108-
109103
/// @notice Force messages from the delayed inbox to be included in the chain
110104
/// Callable by any address, but message can only be force-included after maxTimeVariation.delayBlocks and
111105
/// maxTimeVariation.delaySeconds has elapsed. As part of normal behaviour the sequencer will include these
@@ -140,7 +134,9 @@ interface ISequencerInbox is IDelayedMessageProvider {
140134
uint256 sequenceNumber,
141135
bytes calldata data,
142136
uint256 afterDelayedMessagesRead,
143-
IGasRefunder gasRefunder
137+
IGasRefunder gasRefunder,
138+
uint256 prevMessageCount,
139+
uint256 newMessageCount
144140
) external;
145141

146142
function addSequencerL2Batch(
@@ -154,12 +150,6 @@ interface ISequencerInbox is IDelayedMessageProvider {
154150

155151
// ---------- onlyRollupOrOwner functions ----------
156152

157-
/**
158-
* @notice Set max delay for sequencer inbox
159-
* @param maxTimeVariation_ the maximum time variation parameters
160-
*/
161-
function setMaxTimeVariation(MaxTimeVariation memory maxTimeVariation_) external;
162-
163153
/**
164154
* @notice Updates whether an address is authorized to be a batch poster at the sequencer inbox
165155
* @param addr the address
@@ -187,10 +177,7 @@ interface ISequencerInbox is IDelayedMessageProvider {
187177
*/
188178
function setIsSequencer(address addr, bool isSequencer_) external;
189179

190-
// ---------- initializer ----------
191-
192-
function initialize(IBridge bridge_, MaxTimeVariation calldata maxTimeVariation_) external;
193-
180+
/// @notice Allows the rollup owner to sync the rollup address
194181
function updateRollupAddress() external;
195182
}
196183

0 commit comments

Comments
 (0)