@@ -22,8 +22,9 @@ contract Zenith is Passage {
2222 }
2323
2424 /// @notice The sequence number of the next block that can be submitted for a given rollup chainId.
25- /// rollupChainId => nextSequence number
26- mapping (uint256 => uint256 ) public nextSequence;
25+ /// @dev Because sequences must start at 1, accessors must add 1 to this number.
26+ /// rollupChainId => (nextSequence - 1)
27+ mapping (uint256 => uint256 ) sequences;
2728
2829 /// @notice The host block number that a block was last submitted at for a given rollup chainId.
2930 /// rollupChainId => host blockNumber that block was last submitted at
@@ -82,6 +83,22 @@ contract Zenith is Passage {
8283 sequencerAdmin = _sequencerAdmin;
8384 }
8485
86+ /// @notice Returns the next sequence number.
87+ /// @dev Because sequences must start at 1, we add 1 to the mapping value.
88+ /// @param _rollupChainId - the chainId of the rollup chain. Any chainId is accepted by the contract.
89+ /// @return The next sequence number.
90+ function nextSequence (uint256 _rollupChainId ) public view returns (uint256 ) {
91+ return sequences[_rollupChainId] + 1 ;
92+ }
93+
94+ /// @notice Increments the sequence number and returns it.
95+ /// @dev Because sequences must start at 1, we add 1 to the mapping value.
96+ /// @param _rollupChainId - the chainId of the rollup chain. Any chainId is accepted by the contract.
97+ /// @return The next sequence number.
98+ function incrementSequence (uint256 _rollupChainId ) internal returns (uint256 ) {
99+ return ++ sequences[_rollupChainId];
100+ }
101+
85102 /// @notice Add a sequencer to the permissioned sequencer list.
86103 /// @param sequencer - the address of the sequencer to add.
87104 /// @custom:emits SequencerSet if the sequencer is added.
@@ -134,7 +151,7 @@ contract Zenith is Passage {
134151
135152 function _submitBlock (BlockHeader memory header , bytes32 blockDataHash , uint8 v , bytes32 r , bytes32 s ) internal {
136153 // assert that the sequence number is valid and increment it
137- uint256 _nextSequence = nextSequence[ header.rollupChainId] ++ ;
154+ uint256 _nextSequence = incrementSequence ( header.rollupChainId) ;
138155 if (_nextSequence != header.sequence) revert BadSequence (_nextSequence);
139156
140157 // assert that confirmBy time has not passed
0 commit comments