Skip to content

Commit

Permalink
Remove unused proxies code and clean up some deployments ref paths (c…
Browse files Browse the repository at this point in the history
…ompound-finance#525)

* Remove unused proxies code and clean up some deployments ref paths

* Clarify debug statement and tune down workers to see impact on CI

> 1 worker is not obviously better since we often DOS etherscan with the same requests, which slows us down a lot.

* Remove unnecessary slow upgrades at least for the time being

Also try to tune some other parameters to speed up CI/common workflows.

* Sanitize workflows (again) and give space for repeated sig test

* Add sanity check for rewards scenario
  • Loading branch information
jflatow authored Aug 11, 2022
1 parent 5239957 commit d7ee98f
Show file tree
Hide file tree
Showing 24 changed files with 70 additions and 550 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-market.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
eth_pk:
description: Ignore if you plan to use WalletConnect, otherwise, you can paste in a Ethereum private key
jobs:
deploy_market:
deploy-market:
name: Deploy Market
runs-on: ubuntu-latest
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/enact-migration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:
eth_pk:
description: Ignore if you plan to use WalletConnect, otherwise, you can paste in a Ethereum private key
jobs:
enact_migration:
enact-migration:
name: Enact Migration
runs-on: ubuntu-latest
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prepare-migration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
eth_pk:
description: Ignore if you plan to use WalletConnect, otherwise, you can paste in a Ethereum private key
jobs:
prepare_migration:
prepare-migration:
name: Prepare Migration
runs-on: ubuntu-latest
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-contract-linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:
pull_request:
jobs:
run_contract_linter:
run-contract-linter:
name: Contract linter
runs-on: ubuntu-latest
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-gas-profiler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:
pull_request:
jobs:
gas_profiler:
run-gas-profiler:
name: Gas profiler
runs-on: ubuntu-latest
env:
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/run-scenarios.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Run Scenarios'
name: Run Scenarios
on:
workflow_dispatch:
pull_request:
Expand All @@ -25,9 +25,8 @@ jobs:
uses: actions/cache@v2
with:
path: |
deployments/*/contracts/*
deployments/*/aliases.json
deployments/*/proxies.json
deployments/.contracts
deployments/**/aliases.json
!deployments/hardhat
!deployments/relations.ts
!deployments/**/roots.json
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-slither.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:
pull_request:
jobs:
slither_analyzer:
slither-analyzer:
name: Slither analyzer
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run-unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: 'Run Unit Tests'
name: Run Unit Tests
on:
workflow_dispatch:
pull_request:
jobs:
gas_profiler:
unit-tests:
name: Unit tests
runs-on: ubuntu-latest
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scenario-report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types:
- completed
jobs:
report:
scenario-report:
runs-on: ubuntu-latest
steps:
- uses: dorny/test-reporter@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test-report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types:
- completed
jobs:
report:
test-report:
runs-on: ubuntu-latest
steps:
- uses: dorny/test-reporter@v1
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ dist/
deployments/.contracts
deployments/*/*/verify
deployments/*/*/aliases.json
deployments/*/*/pointers.json
deployments/*/*/proxies.json

.env
coverage/
Expand Down
5 changes: 2 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ artifacts
build
cache
coverage
deployments/*/cache
deployments/*/config.json
deployments/*/proxies.json
deployments/.contracts
deployments/*/*/*.json
dist
SPEC.md
12 changes: 6 additions & 6 deletions SCENARIO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ You can run scenarios against a given base as:

`npx hardhat scenario --bases development,goerli,fuji`

You can skip the spider step if you wish:
You can run spider persistently first if you wish:

`npx hardhat scenario --no-spider`
`npx hardhat scenario --spider`

You can change the number of workers:
Note: if you want to speed up, probably better to first:

`npx hardhat scenario --workers 1`
`npx hardhat deploy --simulate --overwrite`

And run synchronously, without worker threads:
You can change the number of workers:

`npx hardhat scenario --workers 1 --sync`
`npx hardhat scenario --workers 4`

## Adding New Scenarios

Expand Down
114 changes: 2 additions & 112 deletions plugins/deployment_manager/ContractMap.ts
Original file line number Diff line number Diff line change
@@ -1,106 +1,9 @@
import { Contract, Signer } from 'ethers';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

import { Contract } from 'ethers';
import { Cache, FileSpec } from './Cache';
import { ABI, Address, Alias, BuildFile } from './Types';
import { Aliases, getAliases } from './Aliases';
import { Proxies, getProxies } from './Proxies';
import { debug, getPrimaryContract, mergeABI } from './Utils';
import { Address, Alias, BuildFile } from './Types';

export type ContractMap = Map<Alias, Contract>;

// TODO: I think we could do away with proxies and these inversions now
// we get everything from the results of running spider, including the contracts map
// Leaving in place for the moment though...

// Gets list of contracts from given aliases
export async function getContractsFromAliases(
cache: Cache,
aliases: Aliases,
proxies: Proxies,
hre: HardhatRuntimeEnvironment,
signer?: Signer
): Promise<ContractMap> {
const contracts: ContractMap = new Map();
const theSigner = signer ?? (await hre.ethers.getSigners())[0];
for (const [alias, address] of aliases.entries()) {
const contract = await getContractByAddressProxy(
cache,
proxies,
address,
hre,
theSigner,
[],
alias,
address
);

if (contract) {
contracts.set(alias, contract);
}
}

return contracts;
}

// Returns an ethers' wrapped contract from a given build file (based on its name and address)
async function getContractByAddressProxy(
cache: Cache,
proxies: Proxies,
address: Address,
hre: HardhatRuntimeEnvironment,
signer: Signer,
accABI: ABI,
accAlias: string,
accAddress: Address
): Promise<Contract | null> {
const contract = await getContractByAddress(cache, accAlias, accAddress, hre, signer);
if (!contract) {
return null; // NB: assume its not a contract
}
const { abi } = contract;
const nextABI = mergeABI(abi, accABI); // duplicate entries (like constructor) defer to accABI
if (proxies.has(accAlias)) {
return await getContractByAddressProxy(
cache,
proxies,
address,
hre,
signer,
nextABI,
`${accAlias}:implementation`,
proxies.get(accAlias)
);
} else {
return new hre.ethers.Contract(address, nextABI, signer);
}
}

// Returns an ethers' wrapped contract from a given build file (based on its name and address)
async function getContractByAddress(
cache: Cache,
alias: Alias,
address: Address,
hre: HardhatRuntimeEnvironment,
signer: Signer,
implBuildFile?: BuildFile
): Promise<{ name: string, contract: Contract, abi: ABI } | null> {
const buildFile = await getBuildFile(cache, address);
if (!buildFile) {
debug(`No build file for ${alias} (${address}), assuming its not a contract`);
return null;
}
const [contractName, metadata] = getPrimaryContract(buildFile);
let abi;
if (implBuildFile) {
const [_implContractName, implMetadata] = getPrimaryContract(implBuildFile);
abi = implMetadata.abi;
} else {
abi = metadata.abi;
}
return { name: contractName, contract: new hre.ethers.Contract(address, abi, signer), abi: abi };
}

function getFileSpec(address: Address): FileSpec {
return { top: ['.contracts', address + '.json'] };
}
Expand All @@ -112,16 +15,3 @@ export async function getBuildFile(cache: Cache, address: Address): Promise<Buil
export async function storeBuildFile(cache: Cache, address: Address, buildFile: BuildFile) {
await cache.storeCache(getFileSpec(address), buildFile);
}

/**
* Gets Etherscan contracts from known cache.
*/
export async function getContracts(
cache: Cache,
hre: HardhatRuntimeEnvironment,
signer?: Signer
): Promise<ContractMap> {
const aliases = await getAliases(cache);
const proxies = await getProxies(cache);
return await getContractsFromAliases(cache, aliases, proxies, hre, signer);
}
10 changes: 2 additions & 8 deletions plugins/deployment_manager/DeploymentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { diff } from 'jest-diff';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { Contract, providers } from 'ethers';
import { Alias, Address, BuildFile } from './Types';
import { Aliases, getAliases, putAlias, storeAliases } from './Aliases';
import { putAlias, storeAliases } from './Aliases';
import { Cache } from './Cache';
import { ContractMap } from './ContractMap';
import { Deployer, DeployOpts, deploy, deployBuild } from './Deploy';
import { fetchAndCacheContract, readContract } from './Import';
import { storeProxies } from './Proxies';
import { getRelationConfig } from './RelationConfig';
import { getRoots, putRoots } from './Roots';
import { Spider, spider } from './Spider';
Expand Down Expand Up @@ -196,7 +195,7 @@ export class DeploymentManager {
const buildFile = await this.import(address);
const contract = getEthersContract<C>(address, buildFile, this.hre);
await this.putAlias(alias, contract);
debug(`Imported ${buildFile.contract} from ${address} as '${alias}'`);
debug(`Loaded ${buildFile.contract} from ${address} as '${alias}'`);
return contract;
}
return maybeExisting;
Expand Down Expand Up @@ -282,7 +281,6 @@ export class DeploymentManager {
);
await putRoots(this.cache, roots);
await storeAliases(this.cache, crawl.aliases);
await storeProxies(this.cache, crawl.proxies); // TODO: I think we can get rid of this?
this.contractsCache = crawl.contracts;
return crawl;
}
Expand All @@ -293,10 +291,6 @@ export class DeploymentManager {
this.contractsCache.set(alias, contract);
}

async getAliases(): Promise<Aliases> {
return getAliases(this.cache);
}

/* Returns a memory-cached map of contracts indexed by alias.
* Note: this map is cached in-memory and updated when aliases change,
* so call this as often as you would like.
Expand Down
23 changes: 0 additions & 23 deletions plugins/deployment_manager/Proxies.ts

This file was deleted.

Loading

0 comments on commit d7ee98f

Please sign in to comment.