Skip to content
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

fix(pg): deploy the executor once per cli command #244

Merged
merged 2 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/real-moons-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chugsplash/plugins': patch
---

Deploy the executor only once per CLI command
24 changes: 18 additions & 6 deletions packages/plugins/src/hardhat/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ export const deployAllChugSplashConfigs = async (
) => {
const remoteExecution = (await getChainId(hre.ethers.provider)) !== 31337
const fileNames = fs.readdirSync(hre.config.paths.chugsplash)

let executor: ChugSplashExecutor
if (!remoteExecution) {
// We must remove the command line arguments that begin with '--' from the process.argv array,
// or else the BaseServiceV2 (inherited by the executor) will throw an error.
removeFlagsFromCommandLineArgs()
executor = new ChugSplashExecutor()
}

for (const fileName of fileNames) {
const configPath = path.join(hre.config.paths.chugsplash, fileName)
// Skip this config if it's empty.
Expand All @@ -63,7 +72,8 @@ export const deployAllChugSplashConfigs = async (
silent,
remoteExecution,
ipfsUrl,
noCompile
noCompile,
executor
)
}
}
Expand All @@ -75,8 +85,15 @@ export const deployChugSplashConfig = async (
remoteExecution: boolean,
ipfsUrl: string,
noCompile: boolean,
executor?: ChugSplashExecutor,
spinner: ora.Ora = ora({ isSilent: true })
) => {
if (executor === undefined && !remoteExecution) {
throw new Error(
'You must pass in a ChugSplashExecutor if executing locally'
)
}

const provider = hre.ethers.provider
const signer = provider.getSigner()
const signerAddress = await signer.getAddress()
Expand Down Expand Up @@ -207,11 +224,6 @@ export const deployChugSplashConfig = async (
to: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
value: ethers.utils.parseEther('1'),
})

// We must remove the command line arguments that begin with '--' from the process.argv array,
// or else the BaseServiceV2 (inherited by the executor) will throw an error.
removeFlagsFromCommandLineArgs()
const executor = new ChugSplashExecutor()
await executor.main(
{
privateKey:
Expand Down
15 changes: 14 additions & 1 deletion packages/plugins/src/hardhat/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import ora from 'ora'
import Hash from 'ipfs-only-hash'
import * as dotenv from 'dotenv'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { getArtifactsFromParsedCanonicalConfig } from '@chugsplash/executor'
import {
ChugSplashExecutor,
getArtifactsFromParsedCanonicalConfig,
} from '@chugsplash/executor'

import {
createDeploymentArtifacts,
Expand All @@ -63,6 +66,7 @@ import {
successfulProposalMessage,
} from '../messages'
import { monitorRemoteExecution, postExecutionActions } from './execution'
import { removeFlagsFromCommandLineArgs } from '../env'

// Load environment variables from .env
dotenv.config()
Expand Down Expand Up @@ -177,6 +181,14 @@ export const chugsplashDeployTask = async (
const remoteExecution = (await getChainId(provider)) !== 31337
await deployChugSplashPredeploys(provider, provider.getSigner())

let executor: ChugSplashExecutor
if (!remoteExecution) {
// We must remove the command line arguments that begin with '--' from the process.argv array,
// or else the BaseServiceV2 (inherited by the executor) will throw an error.
removeFlagsFromCommandLineArgs()
executor = new ChugSplashExecutor()
}

spinner.succeed('ChugSplash is ready to go.')

await deployChugSplashConfig(
Expand All @@ -186,6 +198,7 @@ export const chugsplashDeployTask = async (
remoteExecution,
ipfsUrl,
noCompile,
executor,
spinner
)
}
Expand Down