Skip to content

Commit

Permalink
Merge pull request #6 from OffchainLabs/rollup-arbitrum-host
Browse files Browse the repository at this point in the history
Store rollup node ArbSys block numbers if on an Arbitrum host chain
  • Loading branch information
PlasmaPower authored May 12, 2023
2 parents a687834 + 67127e2 commit 87d5809
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/rollup/IRollupCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ interface IRollupCore {
*/
function getNode(uint64 nodeNum) external view returns (Node memory);

/**
* @notice Returns the block in which the given node was created for looking up its creation event.
* Unlike the Node's createdAtBlock field, this will be the ArbSys blockNumber if the host chain is an Arbitrum chain.
* That means that the block number returned for this is usable for event queries.
* This function will revert if the given node number does not exist.
* @dev This function is meant for internal use only and has no stability guarantees.
*/
function getNodeCreationBlockForLogLookup(uint64 nodeNum) external view returns (uint256);

/**
* @notice Check if the specified node has been staked on by the provided staker.
* Only accurate at the latest confirmed node and afterwards.
Expand Down
44 changes: 44 additions & 0 deletions src/rollup/RollupCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import "../bridge/ISequencerInbox.sol";
import "../bridge/IBridge.sol";
import "../bridge/IOutbox.sol";

import "../precompiles/ArbSys.sol";

import {NO_CHAL_INDEX} from "../libraries/Constants.sol";

abstract contract RollupCore is IRollupCore, PausableUpgradeable {
Expand Down Expand Up @@ -76,6 +78,18 @@ abstract contract RollupCore is IRollupCore, PausableUpgradeable {

bool public validatorWhitelistDisabled;

// If the chain this RollupCore is deployed on is an Arbitrum chain.
bool internal immutable _hostChainIsArbitrum;
// If the chain RollupCore is deployed on, this will contain the ArbSys.blockNumber() at each node's creation.
mapping(uint64 => uint256) internal _nodeCreatedAtArbSysBlock;

constructor() {
(bool ok, bytes memory data) = address(100).staticcall(
abi.encodeWithSelector(ArbSys.arbOSVersion.selector)
);
_hostChainIsArbitrum = ok && data.length == 32;
}

/**
* @notice Get a storage reference to the Node for the given node index
* @param nodeNum Index of the node
Expand All @@ -92,6 +106,30 @@ abstract contract RollupCore is IRollupCore, PausableUpgradeable {
return getNodeStorage(nodeNum);
}

/**
* @notice Returns the block in which the given node was created for looking up its creation event.
* Unlike the Node's createdAtBlock field, this will be the ArbSys blockNumber if the host chain is an Arbitrum chain.
* That means that the block number returned for this is usable for event queries.
* This function will revert if the given node number does not exist.
* @dev This function is meant for internal use only and has no stability guarantees.
*/
function getNodeCreationBlockForLogLookup(uint64 nodeNum)
external
view
override
returns (uint256)
{
if (_hostChainIsArbitrum) {
uint256 blockNum = _nodeCreatedAtArbSysBlock[nodeNum];
require(blockNum > 0, "NO_NODE");
return blockNum;
} else {
Node storage node = getNodeStorage(nodeNum);
require(node.deadlineBlock != 0, "NO_NODE");
return node.createdAtBlock;
}
}

/**
* @notice Check if the specified node has been staked on by the provided staker.
* Only accurate at the latest confirmed node and afterwards.
Expand Down Expand Up @@ -250,6 +288,9 @@ abstract contract RollupCore is IRollupCore, PausableUpgradeable {
__Pausable_init();
_nodes[GENESIS_NODE] = initialNode;
_firstUnresolvedNode = GENESIS_NODE + 1;
if (_hostChainIsArbitrum) {
_nodeCreatedAtArbSysBlock[GENESIS_NODE] = ArbSys(address(100)).arbBlockNumber();
}
}

/**
Expand All @@ -259,6 +300,9 @@ abstract contract RollupCore is IRollupCore, PausableUpgradeable {
function nodeCreated(Node memory node) internal {
_latestNodeCreated++;
_nodes[_latestNodeCreated] = node;
if (_hostChainIsArbitrum) {
_nodeCreatedAtArbSysBlock[_latestNodeCreated] = ArbSys(address(100)).arbBlockNumber();
}
}

/// @notice Reject the next unresolved node
Expand Down
2 changes: 1 addition & 1 deletion test/storage/RollupAdminLogic.dot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ rankdir=LR
color=black
arrowhead=open
node [shape=record, style=filled, fillcolor=gray95 fontname="Courier New"]
8 [label="RollupAdminLogic \<\<Contract\>\>\n | {{ slot| 0 | 1-50 | 51 | 52-100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 } | { type: \<inherited contract\>.variable (bytes) | { unallocated (30) | bool: Initializable._initializing (1) | bool: Initializable._initialized (1) } | { <53> uint256[50]: ContextUpgradeable.__gap (1600) } | { unallocated (31) | bool: PausableUpgradeable._paused (1) } | { <104> uint256[49]: PausableUpgradeable.__gap (1568) } | { unallocated (16) | uint64: RollupCore.extraChallengeTimeBlocks (8) | uint64: RollupCore.confirmPeriodBlocks (8) } | { uint256: RollupCore.chainId (32) } | { uint256: RollupCore.baseStake (32) } | { bytes32: RollupCore.wasmModuleRoot (32) } | { unallocated (12) | IInbox: RollupCore.inbox (20) } | { unallocated (12) | IBridge: RollupCore.bridge (20) } | { unallocated (12) | IOutbox: RollupCore.outbox (20) } | { unallocated (12) | ISequencerInbox: RollupCore.sequencerInbox (20) } | { unallocated (12) | IRollupEventInbox: RollupCore.rollupEventInbox (20) } | { unallocated (12) | IChallengeManager: RollupCore.challengeManager (20) } | { unallocated (12) | address: RollupCore.validatorUtils (20) } | { unallocated (12) | address: RollupCore.validatorWalletCreator (20) } | { unallocated (12) | address: RollupCore.loserStakeEscrow (20) } | { unallocated (12) | address: RollupCore.stakeToken (20) } | { uint256: RollupCore.minimumAssertionPeriod (32) } | { mapping\(address=\>bool\): RollupCore.isValidator (32) } | { uint64: RollupCore._lastStakeBlock (8) | uint64: RollupCore._latestNodeCreated (8) | uint64: RollupCore._firstUnresolvedNode (8) | uint64: RollupCore._latestConfirmed (8) } | { <138> mapping\(uint64=\>Node\): RollupCore._nodes (32) } | { mapping\(uint64=\>mapping\(address=\>bool\)\): RollupCore._nodeStakers (32) } | { <141> address[]: RollupCore._stakerList (32) } | { <147> mapping\(address=\>Staker\): RollupCore._stakerMap (32) } | { <151> Zombie[]: RollupCore._zombies (32) } | { mapping\(address=\>uint256\): RollupCore._withdrawableFunds (32) } | { uint256: RollupCore.totalWithdrawableFunds (32) } | { uint256: RollupCore.rollupDeploymentBlock (32) } | { unallocated (31) | bool: RollupCore.validatorWhitelistDisabled (1) }}}"]
8 [label="RollupAdminLogic \<\<Contract\>\>\n | {{ slot| 0 | 1-50 | 51 | 52-100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 } | { type: \<inherited contract\>.variable (bytes) | { unallocated (30) | bool: Initializable._initializing (1) | bool: Initializable._initialized (1) } | { <53> uint256[50]: ContextUpgradeable.__gap (1600) } | { unallocated (31) | bool: PausableUpgradeable._paused (1) } | { <104> uint256[49]: PausableUpgradeable.__gap (1568) } | { unallocated (16) | uint64: RollupCore.extraChallengeTimeBlocks (8) | uint64: RollupCore.confirmPeriodBlocks (8) } | { uint256: RollupCore.chainId (32) } | { uint256: RollupCore.baseStake (32) } | { bytes32: RollupCore.wasmModuleRoot (32) } | { unallocated (12) | IInbox: RollupCore.inbox (20) } | { unallocated (12) | IBridge: RollupCore.bridge (20) } | { unallocated (12) | IOutbox: RollupCore.outbox (20) } | { unallocated (12) | ISequencerInbox: RollupCore.sequencerInbox (20) } | { unallocated (12) | IRollupEventInbox: RollupCore.rollupEventInbox (20) } | { unallocated (12) | IChallengeManager: RollupCore.challengeManager (20) } | { unallocated (12) | address: RollupCore.validatorUtils (20) } | { unallocated (12) | address: RollupCore.validatorWalletCreator (20) } | { unallocated (12) | address: RollupCore.loserStakeEscrow (20) } | { unallocated (12) | address: RollupCore.stakeToken (20) } | { uint256: RollupCore.minimumAssertionPeriod (32) } | { mapping\(address=\>bool\): RollupCore.isValidator (32) } | { uint64: RollupCore._lastStakeBlock (8) | uint64: RollupCore._latestNodeCreated (8) | uint64: RollupCore._firstUnresolvedNode (8) | uint64: RollupCore._latestConfirmed (8) } | { <138> mapping\(uint64=\>Node\): RollupCore._nodes (32) } | { mapping\(uint64=\>mapping\(address=\>bool\)\): RollupCore._nodeStakers (32) } | { <141> address[]: RollupCore._stakerList (32) } | { <147> mapping\(address=\>Staker\): RollupCore._stakerMap (32) } | { <151> Zombie[]: RollupCore._zombies (32) } | { mapping\(address=\>uint256\): RollupCore._withdrawableFunds (32) } | { uint256: RollupCore.totalWithdrawableFunds (32) } | { uint256: RollupCore.rollupDeploymentBlock (32) } | { unallocated (31) | bool: RollupCore.validatorWhitelistDisabled (1) } | { mapping\(uint64=\>uint256\): RollupCore._nodeCreatedAtArbSysBlock (32) }}}"]

1 [label="uint256[50]: __gap \<\<Array\>\>\n | {{ slot| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 } | { type: variable (bytes) | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) }}}"]

Expand Down
2 changes: 1 addition & 1 deletion test/storage/RollupCore.dot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ rankdir=LR
color=black
arrowhead=open
node [shape=record, style=filled, fillcolor=gray95 fontname="Courier New"]
8 [label="RollupCore \<\<Contract\>\>\n | {{ slot| 0 | 1-50 | 51 | 52-100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 } | { type: \<inherited contract\>.variable (bytes) | { unallocated (30) | bool: Initializable._initializing (1) | bool: Initializable._initialized (1) } | { <53> uint256[50]: ContextUpgradeable.__gap (1600) } | { unallocated (31) | bool: PausableUpgradeable._paused (1) } | { <104> uint256[49]: PausableUpgradeable.__gap (1568) } | { unallocated (16) | uint64: extraChallengeTimeBlocks (8) | uint64: confirmPeriodBlocks (8) } | { uint256: chainId (32) } | { uint256: baseStake (32) } | { bytes32: wasmModuleRoot (32) } | { unallocated (12) | IInbox: inbox (20) } | { unallocated (12) | IBridge: bridge (20) } | { unallocated (12) | IOutbox: outbox (20) } | { unallocated (12) | ISequencerInbox: sequencerInbox (20) } | { unallocated (12) | IRollupEventInbox: rollupEventInbox (20) } | { unallocated (12) | IChallengeManager: challengeManager (20) } | { unallocated (12) | address: validatorUtils (20) } | { unallocated (12) | address: validatorWalletCreator (20) } | { unallocated (12) | address: loserStakeEscrow (20) } | { unallocated (12) | address: stakeToken (20) } | { uint256: minimumAssertionPeriod (32) } | { mapping\(address=\>bool\): isValidator (32) } | { uint64: _lastStakeBlock (8) | uint64: _latestNodeCreated (8) | uint64: _firstUnresolvedNode (8) | uint64: _latestConfirmed (8) } | { <138> mapping\(uint64=\>Node\): _nodes (32) } | { mapping\(uint64=\>mapping\(address=\>bool\)\): _nodeStakers (32) } | { <141> address[]: _stakerList (32) } | { <147> mapping\(address=\>Staker\): _stakerMap (32) } | { <151> Zombie[]: _zombies (32) } | { mapping\(address=\>uint256\): _withdrawableFunds (32) } | { uint256: totalWithdrawableFunds (32) } | { uint256: rollupDeploymentBlock (32) } | { unallocated (31) | bool: validatorWhitelistDisabled (1) }}}"]
8 [label="RollupCore \<\<Contract\>\>\n | {{ slot| 0 | 1-50 | 51 | 52-100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 } | { type: \<inherited contract\>.variable (bytes) | { unallocated (30) | bool: Initializable._initializing (1) | bool: Initializable._initialized (1) } | { <53> uint256[50]: ContextUpgradeable.__gap (1600) } | { unallocated (31) | bool: PausableUpgradeable._paused (1) } | { <104> uint256[49]: PausableUpgradeable.__gap (1568) } | { unallocated (16) | uint64: extraChallengeTimeBlocks (8) | uint64: confirmPeriodBlocks (8) } | { uint256: chainId (32) } | { uint256: baseStake (32) } | { bytes32: wasmModuleRoot (32) } | { unallocated (12) | IInbox: inbox (20) } | { unallocated (12) | IBridge: bridge (20) } | { unallocated (12) | IOutbox: outbox (20) } | { unallocated (12) | ISequencerInbox: sequencerInbox (20) } | { unallocated (12) | IRollupEventInbox: rollupEventInbox (20) } | { unallocated (12) | IChallengeManager: challengeManager (20) } | { unallocated (12) | address: validatorUtils (20) } | { unallocated (12) | address: validatorWalletCreator (20) } | { unallocated (12) | address: loserStakeEscrow (20) } | { unallocated (12) | address: stakeToken (20) } | { uint256: minimumAssertionPeriod (32) } | { mapping\(address=\>bool\): isValidator (32) } | { uint64: _lastStakeBlock (8) | uint64: _latestNodeCreated (8) | uint64: _firstUnresolvedNode (8) | uint64: _latestConfirmed (8) } | { <138> mapping\(uint64=\>Node\): _nodes (32) } | { mapping\(uint64=\>mapping\(address=\>bool\)\): _nodeStakers (32) } | { <141> address[]: _stakerList (32) } | { <147> mapping\(address=\>Staker\): _stakerMap (32) } | { <151> Zombie[]: _zombies (32) } | { mapping\(address=\>uint256\): _withdrawableFunds (32) } | { uint256: totalWithdrawableFunds (32) } | { uint256: rollupDeploymentBlock (32) } | { unallocated (31) | bool: validatorWhitelistDisabled (1) } | { mapping\(uint64=\>uint256\): _nodeCreatedAtArbSysBlock (32) }}}"]

1 [label="uint256[50]: __gap \<\<Array\>\>\n | {{ slot| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 } | { type: variable (bytes) | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) } | { uint256 (32) }}}"]

Expand Down
Loading

0 comments on commit 87d5809

Please sign in to comment.