Skip to content

Commit

Permalink
feat(core): make chugsplash-deploy task execute locally
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Apr 10, 2023
1 parent acdb0e4 commit 11fd15c
Show file tree
Hide file tree
Showing 27 changed files with 699 additions and 965 deletions.
8 changes: 8 additions & 0 deletions .changeset/unlucky-balloons-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@chugsplash/core': minor
'@chugsplash/contracts': patch
'@chugsplash/executor': patch
'@chugsplash/plugins': patch
---

Make chugsplash-deploy task execute locally by default
1 change: 1 addition & 0 deletions packages/contracts/contracts/ChugSplashDataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct ChugSplashBundleState {
uint256 actionsExecuted;
uint256 timeClaimed;
address selectedExecutor;
bool remoteExecution;
}

/**
Expand Down
66 changes: 39 additions & 27 deletions packages/contracts/contracts/ChugSplashManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
uint256 numActions,
uint256 numTargets,
string configUri,
bool remoteExecution,
address proposer
);

Expand Down Expand Up @@ -330,6 +331,15 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
keccak256(abi.encode(_actionRoot, _targetRoot, _numActions, _numTargets, _configUri));
}

function assertCallerIsOwnerOrSelectedExecutor(bool _remoteExecution) internal view {
_remoteExecution
? require(
getSelectedExecutor(activeBundleId) == msg.sender,
"ChugSplashManager: caller is not approved executor"
)
: require(owner() == msg.sender, "ChugSplashManager: caller is not owner");
}

function totalDebt() public view returns (uint256) {
return totalExecutorDebt + totalProtocolDebt;
}
Expand Down Expand Up @@ -397,7 +407,8 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
bytes32 _targetRoot,
uint256 _numActions,
uint256 _numTargets,
string memory _configUri
string memory _configUri,
bool _remoteExecution
) public {
require(isProposer(msg.sender), "ChugSplashManager: caller must be proposer");

Expand All @@ -423,6 +434,7 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
bundle.targetRoot = _targetRoot;
bundle.actions = new bool[](_numActions);
bundle.targets = _numTargets;
bundle.remoteExecution = _remoteExecution;

emit ChugSplashBundleProposed(
bundleId,
Expand All @@ -431,6 +443,7 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
_numActions,
_numTargets,
_configUri,
_remoteExecution,
msg.sender
);
registry.announceWithData("ChugSplashBundleProposed", abi.encodePacked(msg.sender));
Expand All @@ -446,13 +459,15 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
* @param _bundleId ID of the bundle to approve
*/
function approveChugSplashBundle(bytes32 _bundleId) public onlyOwner {
require(
address(this).balance - totalDebt() >= ownerBondAmount,
"ChugSplashManager: insufficient balance in manager"
);

ChugSplashBundleState storage bundle = _bundles[_bundleId];

if (bundle.remoteExecution) {
require(
address(this).balance - totalDebt() >= ownerBondAmount,
"ChugSplashManager: insufficient balance in manager"
);
}

require(
bundle.status == ChugSplashBundleStatus.PROPOSED,
"ChugSplashManager: bundle must be proposed"
Expand Down Expand Up @@ -482,13 +497,10 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
) public {
uint256 initialGasLeft = gasleft();

require(
getSelectedExecutor(activeBundleId) == msg.sender,
"ChugSplashManager: caller is not approved executor for active bundle ID"
);

ChugSplashBundleState storage bundle = _bundles[activeBundleId];

assertCallerIsOwnerOrSelectedExecutor(bundle.remoteExecution);

require(
bundle.status == ChugSplashBundleStatus.APPROVED,
"ChugSplashManager: execution has already been initiated"
Expand Down Expand Up @@ -557,7 +569,7 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
emit ChugSplashBundleInitiated(activeBundleId, msg.sender);
registry.announce("ChugSplashBundleInitiated");

_payExecutorAndProtocol(initialGasLeft);
_payExecutorAndProtocol(initialGasLeft, bundle.remoteExecution);
}

/**
Expand All @@ -578,13 +590,10 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
bytes32 noProxyContractKindHash = keccak256("no-proxy");
uint256 initialGasLeft = gasleft();

require(
getSelectedExecutor(activeBundleId) == msg.sender,
"ChugSplashManager: caller is not approved executor for active bundle ID"
);

ChugSplashBundleState storage bundle = _bundles[activeBundleId];

assertCallerIsOwnerOrSelectedExecutor(bundle.remoteExecution);

uint256 numActions = _actions.length;
ChugSplashAction memory action;
uint256 actionIndex;
Expand Down Expand Up @@ -665,7 +674,7 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
registry.announceWithData("ChugSplashActionExecuted", abi.encodePacked(action.proxy));
}

_payExecutorAndProtocol(initialGasLeft);
_payExecutorAndProtocol(initialGasLeft, bundle.remoteExecution);
}

/**
Expand All @@ -684,18 +693,15 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
) public {
uint256 initialGasLeft = gasleft();

require(
getSelectedExecutor(activeBundleId) == msg.sender,
"ChugSplashManager: caller is not approved executor for active bundle ID"
);
ChugSplashBundleState storage bundle = _bundles[activeBundleId];

assertCallerIsOwnerOrSelectedExecutor(bundle.remoteExecution);

require(
activeBundleId != bytes32(0),
"ChugSplashManager: no bundle has been approved for execution"
);

ChugSplashBundleState storage bundle = _bundles[activeBundleId];

require(
bundle.actionsExecuted == bundle.actions.length,
"ChugSplashManager: bundle was not executed completely"
Expand Down Expand Up @@ -751,7 +757,7 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
emit ChugSplashBundleCompleted(completedBundleId, msg.sender, bundle.actionsExecuted);
registry.announce("ChugSplashBundleCompleted");

_payExecutorAndProtocol(initialGasLeft);
_payExecutorAndProtocol(initialGasLeft, bundle.remoteExecution);
}

function executeEntireBundle(
Expand Down Expand Up @@ -781,7 +787,7 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {

ChugSplashBundleState storage bundle = _bundles[activeBundleId];

if (bundle.timeClaimed + executionLockTime >= block.timestamp) {
if (bundle.remoteExecution && bundle.timeClaimed + executionLockTime >= block.timestamp) {
// Give the owner's bond to the executor if the bundle is cancelled within the
// `executionLockTime` window.
totalExecutorDebt += ownerBondAmount;
Expand All @@ -808,6 +814,8 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {

ChugSplashBundleState storage bundle = _bundles[activeBundleId];

require(bundle.remoteExecution, "ChugSplashManager: bundle must be executed locally");

require(
block.timestamp > bundle.timeClaimed + executionLockTime,
"ChugSplashManager: bundle is currently claimed by an executor"
Expand Down Expand Up @@ -949,7 +957,11 @@ contract ChugSplashManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
registry.announce("ETHDeposited");
}

function _payExecutorAndProtocol(uint256 _initialGasLeft) internal {
function _payExecutorAndProtocol(uint256 _initialGasLeft, bool _remoteExecution) internal {
if (!_remoteExecution) {
return;
}

uint256 gasPrice;
if (block.chainid != 10 && block.chainid != 420) {
// Use the gas price for any network that isn't Optimism.
Expand Down
3 changes: 3 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
"@eth-optimism/contracts-bedrock": "^0.8.0",
"@eth-optimism/core-utils": "^0.9.1",
"@ethersproject/abstract-provider": "^5.7.0",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@openzeppelin/hardhat-upgrades": "^1.22.1",
"@openzeppelin/upgrades-core": "^1.20.6",
"chalk": "^4.1.2",
"core-js": "^3.27.1",
"dotenv": "^16.0.3",
"ethers": "^5.6.9",
"fs": "^0.0.1-security",
"handlebars": "^4.7.7",
Expand All @@ -50,6 +52,7 @@
"ora": "^5.4.1",
"semver": "^7.3.8",
"solidity-ast": "^0.4.45",
"undici": "^5.21.1",
"yesno": "^0.4.0"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 11fd15c

Please sign in to comment.