Make HelloWorld deploys idempotent (#1047)

* Make HelloWorld deploys idempotent

* Fix build
pull/1058/head
Nam Chu Hoai 2 years ago committed by GitHub
parent f544a5df03
commit 1f44f4377b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      typescript/infra/scripts/core.ts
  2. 36
      typescript/infra/scripts/helloworld/deploy.ts
  3. 19
      typescript/sdk/src/deploy/AbacusDeployer.ts
  4. 41
      typescript/sdk/src/deploy/router/AbacusRouterDeployer.ts

@ -1,7 +1,4 @@
import {
ChainMap,
Chains,
ContractVerificationInput,
buildContracts,
coreFactories,
serializeContracts,
@ -18,24 +15,6 @@ import {
getEnvironment,
} from './utils';
function mergeVerificationInputs<ChainName extends Chains>(
existingInputsMap: ChainMap<ChainName, ContractVerificationInput[]>,
newInputsMap: ChainMap<ChainName, ContractVerificationInput[]>,
): ChainMap<ChainName, ContractVerificationInput[]> {
const allChains = new Set<ChainName>();
Object.keys(existingInputsMap).forEach((_) => allChains.add(_ as ChainName));
Object.keys(newInputsMap).forEach((_) => allChains.add(_ as ChainName));
// @ts-ignore
const ret: ChainMap<ChainName, ContractVerificationInput[]> = {};
for (const chain of allChains) {
const existingInputs = existingInputsMap[chain] || [];
const newInputs = newInputsMap[chain] || [];
ret[chain] = [...existingInputs, ...newInputs];
}
return ret;
}
async function main() {
const environment = await getEnvironment();
const config = getCoreEnvironmentConfig(environment) as any;
@ -76,10 +55,7 @@ async function main() {
writeJSON(
getCoreVerificationDirectory(environment),
'verification.json',
mergeVerificationInputs(
existingVerificationInputs,
deployer.verificationInputs,
),
deployer.mergeWithExistingVerificationInputs(existingVerificationInputs),
);
deployer.writeRustConfigs(environment, getCoreRustDirectory(environment));

@ -42,30 +42,34 @@ async function main() {
context,
);
let partialContracts: ChainMap<any, HelloWorldContracts>;
let previousContracts: ChainMap<any, HelloWorldContracts> = {};
let existingVerificationInputs = {};
try {
const addresses = readJSON(dir, 'partial_addresses.json');
partialContracts = buildContracts(addresses, helloWorldFactories) as any;
const addresses = readJSON(dir, 'addresses.json');
previousContracts = buildContracts(addresses, helloWorldFactories) as any;
existingVerificationInputs = readJSON(dir, 'verification.json');
} catch (e) {
partialContracts = {};
console.info(`Could not load previous deployment, file may not exist`);
}
try {
const contracts = await deployer.deploy(partialContracts);
writeJSON(dir, 'addresses.json', serializeContracts(contracts));
writeJSON(
dir,
'verification.json',
JSON.stringify(deployer.verificationInputs),
);
await deployer.deploy(previousContracts);
} catch (e) {
console.error(`Encountered error during deploy`);
console.error(e);
writeJSON(
dir,
'partial_addresses.json',
serializeContracts(deployer.deployedContracts as any),
);
}
writeJSON(
dir,
'addresses.json',
// @ts-ignore
serializeContracts(deployer.deployedContracts),
);
writeJSON(
dir,
'verification.json',
deployer.mergeWithExistingVerificationInputs(existingVerificationInputs),
);
}
main()

@ -250,4 +250,23 @@ export abstract class AbacusDeployer<
initArgs,
);
}
mergeWithExistingVerificationInputs(
existingInputsMap: ChainMap<Chain, ContractVerificationInput[]>,
): ChainMap<Chain, ContractVerificationInput[]> {
const allChains = new Set<Chain>();
Object.keys(existingInputsMap).forEach((_) => allChains.add(_ as Chain));
Object.keys(this.verificationInputs).forEach((_) =>
allChains.add(_ as Chain),
);
// @ts-ignore
const ret: ChainMap<Chain, ContractVerificationInput[]> = {};
for (const chain of allChains) {
const existingInputs = existingInputsMap[chain] || [];
const newInputs = this.verificationInputs[chain] || [];
ret[chain] = [...existingInputs, ...newInputs];
}
return ret;
}
}

@ -75,14 +75,27 @@ export abstract class AbacusRouterDeployer<
objMap(contractsMap, async (local, contracts) => {
const chainConnection = this.multiProvider.getChainConnection(local);
for (const remote of this.multiProvider.remoteChains(local)) {
this.logger(`Enroll ${remote}'s router on ${local}`);
await chainConnection.handleTx(
contracts.router.enrollRemoteRouter(
chainMetadata[remote].id,
utils.addressToBytes32(contractsMap[remote].router.address),
chainConnection.overrides,
),
const remoteRouterAddress = utils.addressToBytes32(
contractsMap[remote].router.address,
);
const remoteDomainId = chainMetadata[remote].id;
const enrolledRouterForRemoteDomain = await contracts.router.routers(
remoteDomainId,
);
if (enrolledRouterForRemoteDomain !== remoteRouterAddress) {
await super.runIfOwner(local, contracts.router, async () => {
this.logger(`Enroll router for remote ${remote} on ${local}`);
await chainConnection.handleTx(
contracts.router.enrollRemoteRouter(
remoteDomainId,
remoteRouterAddress,
chainConnection.overrides,
),
);
});
}
}
}),
);
@ -97,9 +110,17 @@ export abstract class AbacusRouterDeployer<
const chainConnection = this.multiProvider.getChainConnection(chain);
const owner = this.configMap[chain].owner;
this.logger(`Transfer ownership of ${chain}'s router to ${owner}`);
await chainConnection.handleTx(
contracts.router.transferOwnership(owner, chainConnection.overrides),
);
const currentOwner = await contracts.router.owner();
if (owner != currentOwner) {
await super.runIfOwner(chain, contracts.router, async () => {
await chainConnection.handleTx(
contracts.router.transferOwnership(
owner,
chainConnection.overrides,
),
);
});
}
}),
);
}

Loading…
Cancel
Save