-
Notifications
You must be signed in to change notification settings - Fork 728
Refactor accumulator flow #692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
837dec9
641b2fd
8195ef8
7e4f471
ab72ad6
fe28a47
1bf907f
420b95a
e66dda7
5e37723
536639b
909f6bc
b735bea
95ac76b
5febfe1
b8f66e1
adfc003
2f5b441
5dfc6f6
99a1371
be47f36
9e9a313
aa4f18e
d57e4a4
960ea5c
07339b9
a1284d1
c03848c
a32123c
6c84471
23e4530
9d956c0
77923a0
7d2e549
aa84e89
a7aff1f
77b0eef
2fe1374
e7b3d85
b7cf8e9
025636f
72680ae
7ea1a9e
6f6c340
1397c53
2851588
84542a0
51e9b97
3e81710
52e0614
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ import "./IBridge.sol"; | |
| import "./Messages.sol"; | ||
| import "../libraries/DelegateCallAware.sol"; | ||
|
|
||
| import {L1MessageType_batchPostingReport} from "../libraries/MessageTypes.sol"; | ||
|
|
||
| /** | ||
| * @title Staging ground for incoming and outgoing messages | ||
| * @notice Holds the inbox accumulator for delayed messages, and is the ETH escrow | ||
|
|
@@ -26,16 +28,21 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge { | |
| bool allowed; | ||
| } | ||
|
|
||
| mapping(address => InOutInfo) private allowedInboxesMap; | ||
| mapping(address => InOutInfo) private allowedDelayedInboxesMap; | ||
| mapping(address => InOutInfo) private allowedOutboxesMap; | ||
|
|
||
| address[] public allowedInboxList; | ||
| address[] public allowedDelayedInboxList; | ||
| address[] public allowedOutboxList; | ||
|
|
||
| address private _activeOutbox; | ||
|
|
||
| /// @dev Accumulator for delayed inbox messages; tail represents hash of the current state; each element represents the inclusion of a new message. | ||
| bytes32[] public override inboxAccs; | ||
| bytes32[] public override delayedInboxAccs; | ||
|
|
||
| /// @dev Accumulator for sequencer inbox messages; tail represents hash of the current state; each element represents the inclusion of a new message. | ||
| bytes32[] public override sequencerInboxAccs; | ||
|
|
||
| address public sequencerInbox; | ||
|
|
||
| address private constant EMPTY_ACTIVEOUTBOX = address(type(uint160).max); | ||
|
|
||
|
|
@@ -55,14 +62,71 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge { | |
| return outbox; | ||
| } | ||
|
|
||
| function allowedInboxes(address inbox) external view override returns (bool) { | ||
| return allowedInboxesMap[inbox].allowed; | ||
| function allowedDelayedInboxes(address inbox) external view override returns (bool) { | ||
| return allowedDelayedInboxesMap[inbox].allowed; | ||
| } | ||
|
|
||
| function allowedOutboxes(address outbox) external view override returns (bool) { | ||
| return allowedOutboxesMap[outbox].allowed; | ||
| } | ||
|
|
||
| /// @param batchPoster sequencer that included the batch, or zero if not a sequencer | ||
| function enqueueSequencerMessage( | ||
| bytes32 dataHash, | ||
| uint256 afterDelayedMessagesRead, | ||
| address batchPoster | ||
| ) | ||
| external | ||
| override | ||
| returns ( | ||
| uint256 seqMessageCount, | ||
| bytes32 beforeAcc, | ||
| bytes32 delayedAcc, | ||
| bytes32 acc | ||
| ) | ||
| { | ||
| if (msg.sender != sequencerInbox) revert NotSequencerInbox(msg.sender); | ||
| seqMessageCount = sequencerInboxAccs.length; | ||
| if (sequencerInboxAccs.length > 0) { | ||
| beforeAcc = sequencerInboxAccs[sequencerInboxAccs.length - 1]; | ||
| } | ||
| if (afterDelayedMessagesRead > 0) { | ||
| delayedAcc = delayedInboxAccs[afterDelayedMessagesRead - 1]; | ||
| } | ||
| acc = keccak256(abi.encodePacked(beforeAcc, dataHash, delayedAcc)); | ||
| sequencerInboxAccs.push(acc); | ||
|
|
||
| if (batchPoster != address(0)) { | ||
| // we ignore the return value as we don't need the updated delayed inbox count | ||
| // as this msg isn't included in the current sequencer batch | ||
| submitBatchSpendingReport(batchPoster, dataHash, seqMessageCount); | ||
| } | ||
| } | ||
|
|
||
| function submitBatchSpendingReport( | ||
| address batchPoster, | ||
| bytes32 dataHash, | ||
| uint256 seqMessageCount | ||
| ) internal returns (uint256) { | ||
| bytes memory messageData = abi.encodePacked( | ||
| block.timestamp, | ||
| batchPoster, | ||
| dataHash, | ||
| seqMessageCount, | ||
| block.basefee | ||
| ); | ||
|
|
||
| return | ||
| addMessageToDelayedAccumulator( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to emit the message data in an inbox-like event somehow. Maybe it'd be better for the sequencer inbox to still submit the batch spending report?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pushed a change for the sequencer inbox to do so
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chose to add a different entrypoint instead of allowing the sequencer inbox to call |
||
| L1MessageType_batchPostingReport, | ||
| batchPoster, | ||
| uint64(block.number), | ||
| uint64(block.timestamp), // solhint-disable-line not-rely-on-time, | ||
| block.basefee, | ||
| keccak256(messageData) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Enqueue a message in the delayed inbox accumulator. | ||
| * These messages are later sequenced in the SequencerInbox, either by the sequencer as | ||
|
|
@@ -73,9 +137,9 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge { | |
| address sender, | ||
| bytes32 messageDataHash | ||
| ) external payable override returns (uint256) { | ||
| if (!allowedInboxesMap[msg.sender].allowed) revert NotInbox(msg.sender); | ||
| if (!allowedDelayedInboxesMap[msg.sender].allowed) revert NotDelayedInbox(msg.sender); | ||
| return | ||
| addMessageToAccumulator( | ||
| addMessageToDelayedAccumulator( | ||
| kind, | ||
| sender, | ||
| uint64(block.number), | ||
|
|
@@ -85,15 +149,15 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge { | |
| ); | ||
| } | ||
|
|
||
| function addMessageToAccumulator( | ||
| function addMessageToDelayedAccumulator( | ||
| uint8 kind, | ||
| address sender, | ||
| uint64 blockNumber, | ||
| uint64 blockTimestamp, | ||
| uint256 baseFeeL1, | ||
| bytes32 messageDataHash | ||
| ) internal returns (uint256) { | ||
| uint256 count = inboxAccs.length; | ||
| uint256 count = delayedInboxAccs.length; | ||
| bytes32 messageHash = Messages.messageHash( | ||
| kind, | ||
| sender, | ||
|
|
@@ -105,9 +169,9 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge { | |
| ); | ||
| bytes32 prevAcc = 0; | ||
| if (count > 0) { | ||
| prevAcc = inboxAccs[count - 1]; | ||
| prevAcc = delayedInboxAccs[count - 1]; | ||
| } | ||
| inboxAccs.push(Messages.accumulateInboxMessage(prevAcc, messageHash)); | ||
| delayedInboxAccs.push(Messages.accumulateInboxMessage(prevAcc, messageHash)); | ||
| emit MessageDelivered( | ||
| count, | ||
| prevAcc, | ||
|
|
@@ -140,21 +204,28 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge { | |
| emit BridgeCallTriggered(msg.sender, to, value, data); | ||
| } | ||
|
|
||
| function setInbox(address inbox, bool enabled) external override onlyOwner { | ||
| InOutInfo storage info = allowedInboxesMap[inbox]; | ||
| function setSequencerInbox(address _sequencerInbox) external override onlyOwner { | ||
| sequencerInbox = _sequencerInbox; | ||
| emit SequencerInboxUpdated(_sequencerInbox); | ||
| } | ||
|
|
||
| function setDelayedInbox(address inbox, bool enabled) external override onlyOwner { | ||
| InOutInfo storage info = allowedDelayedInboxesMap[inbox]; | ||
| bool alreadyEnabled = info.allowed; | ||
| emit InboxToggle(inbox, enabled); | ||
| if ((alreadyEnabled && enabled) || (!alreadyEnabled && !enabled)) { | ||
| return; | ||
| } | ||
| if (enabled) { | ||
| allowedInboxesMap[inbox] = InOutInfo(allowedInboxList.length, true); | ||
| allowedInboxList.push(inbox); | ||
| allowedDelayedInboxesMap[inbox] = InOutInfo(allowedDelayedInboxList.length, true); | ||
| allowedDelayedInboxList.push(inbox); | ||
| } else { | ||
| allowedInboxList[info.index] = allowedInboxList[allowedInboxList.length - 1]; | ||
| allowedInboxesMap[allowedInboxList[info.index]].index = info.index; | ||
| allowedInboxList.pop(); | ||
| delete allowedInboxesMap[inbox]; | ||
| allowedDelayedInboxList[info.index] = allowedDelayedInboxList[ | ||
| allowedDelayedInboxList.length - 1 | ||
| ]; | ||
| allowedDelayedInboxesMap[allowedDelayedInboxList[info.index]].index = info.index; | ||
| allowedDelayedInboxList.pop(); | ||
| delete allowedDelayedInboxesMap[inbox]; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -178,7 +249,11 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge { | |
| } | ||
| } | ||
|
|
||
| function messageCount() external view override returns (uint256) { | ||
| return inboxAccs.length; | ||
| function delayedMessageCount() external view override returns (uint256) { | ||
| return delayedInboxAccs.length; | ||
| } | ||
|
|
||
| function sequencerMessageCount() external view override returns (uint256) { | ||
| return sequencerInboxAccs.length; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.