Skip to content

Commit

Permalink
Merge pull request sphinx-labs#244 from chugsplash/sg/develop
Browse files Browse the repository at this point in the history
fix(pg): deploy the executor once per cli command
  • Loading branch information
sam-goldman authored Nov 22, 2022
2 parents a5af6ab + 097e26e commit af6bfa2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
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

0 comments on commit af6bfa2

Please sign in to comment.