From 381902a871f65e46c654193bc3c4861946705e71 Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 27 Nov 2023 16:01:31 -0800 Subject: [PATCH 1/8] remove some redundant TODOs and change levels for some logger calls --- src/deploy/campaign/deploy-campaign.ts | 9 ++++----- src/deploy/db/mongo-adapter/constants.ts | 1 - src/deploy/db/mongo-adapter/mongo-adapter.ts | 1 - src/deploy/missions/base-deploy-mission.ts | 9 ++++----- src/deploy/zns-campaign.ts | 2 -- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/deploy/campaign/deploy-campaign.ts b/src/deploy/campaign/deploy-campaign.ts index 4fb7d7e1..90750cf0 100644 --- a/src/deploy/campaign/deploy-campaign.ts +++ b/src/deploy/campaign/deploy-campaign.ts @@ -22,7 +22,7 @@ export class DeployCampaign { config : IDeployCampaignConfig; version : string; - // TODO dep: figure out typing here so that methods of each contract type are resolved in Mission classes! + // TODO dep: improve typing here so that methods of each contract type are resolved in Mission classes! // eslint-disable-next-line @typescript-eslint/no-explicit-any [name : string | symbol] : any; @@ -75,13 +75,13 @@ export class DeployCampaign { {} ); - this.logger.debug("Deploy Campaign initialized."); + this.logger.info("Deploy Campaign initialized."); return campaignProxy; } async execute () { - this.logger.debug("Deploy Campaign execution started."); + this.logger.info("Deploy Campaign execution started."); await Object.values(this.state.instances).reduce( async ( @@ -102,12 +102,11 @@ export class DeployCampaign { await this.monitor(); } - this.logger.debug("Deploy Campaign execution finished successfully."); + this.logger.info("Deploy Campaign execution finished successfully."); } updateStateContract (instanceName : string, contractName : string, contract : Contract) { this.state.contracts[instanceName] = contract; - // TODO dep: make better logger and decide which levels to call where this.logger.debug(`Data of deployed contract '${contractName}' is added to Campaign state at '${instanceName}'.`); } diff --git a/src/deploy/db/mongo-adapter/constants.ts b/src/deploy/db/mongo-adapter/constants.ts index 8dc0ca7c..1b0e4ded 100644 --- a/src/deploy/db/mongo-adapter/constants.ts +++ b/src/deploy/db/mongo-adapter/constants.ts @@ -10,6 +10,5 @@ export const VERSION_TYPES = { archived: "ARCHIVED", }; -// TODO dep: move these to default ENV config export const DEFAULT_MONGO_URI = "mongodb://localhost:27018"; export const DEFAULT_MONGO_DB_NAME = "zns-campaign"; diff --git a/src/deploy/db/mongo-adapter/mongo-adapter.ts b/src/deploy/db/mongo-adapter/mongo-adapter.ts index 94071180..c66265e4 100644 --- a/src/deploy/db/mongo-adapter/mongo-adapter.ts +++ b/src/deploy/db/mongo-adapter/mongo-adapter.ts @@ -32,7 +32,6 @@ export class MongoDBAdapter { dbName, clientOpts, } : IMongoDBAdapterArgs) { - // TODO dep: add a way to get these from ENV this.logger = logger; this.client = new MongoClient(dbUri, clientOpts); this.clientOpts = clientOpts; diff --git a/src/deploy/missions/base-deploy-mission.ts b/src/deploy/missions/base-deploy-mission.ts index a4479222..7d78427a 100644 --- a/src/deploy/missions/base-deploy-mission.ts +++ b/src/deploy/missions/base-deploy-mission.ts @@ -57,11 +57,10 @@ export class BaseDeployMission { async needsDeploy () { const dbContract = await this.getFromDB(); - // TODO dep: refine these if (!dbContract) { - this.logger.debug(`${this.contractName} not found in DB, proceeding to deploy...`); + this.logger.info(`${this.contractName} not found in DB, proceeding to deploy...`); } else { - this.logger.debug(`${this.contractName} found in DB at ${dbContract.address}, no deployment needed.`); + this.logger.info(`${this.contractName} found in DB at ${dbContract.address}, no deployment needed.`); const contract = await this.campaign.deployer.getContractObject( this.contractName, @@ -142,7 +141,7 @@ export class BaseDeployMission { } async verify () { - this.logger.info(`Verifying ${this.contractName} on Etherscan...`); + this.logger.debug(`Verifying ${this.contractName} on Etherscan...`); const { address } = await this.campaign[this.instanceName]; const ctorArgs = !this.proxyData.isProxy ? this.deployArgs() : undefined; @@ -152,7 +151,7 @@ export class BaseDeployMission { ctorArgs, }); - this.logger.info(`Etherscan verification for ${this.contractName} finished successfully.`); + this.logger.debug(`Etherscan verification for ${this.contractName} finished successfully.`); } async getMonitoringData () : Promise> { diff --git a/src/deploy/zns-campaign.ts b/src/deploy/zns-campaign.ts index b1bba168..f8faa009 100644 --- a/src/deploy/zns-campaign.ts +++ b/src/deploy/zns-campaign.ts @@ -23,7 +23,6 @@ export const runZnsCampaign = async ({ dbVersion ?: string; deployer ?: HardhatDeployer; }) => { - // TODO dep: figure out the best place to put this at! hre.upgrades.silenceWarnings(); const logger = getLogger(); @@ -53,7 +52,6 @@ export const runZnsCampaign = async ({ await campaign.execute(); - // TODO dep: find the best place to call these ! await dbAdapter.finalizeDeployedVersion(dbVersion); return campaign; From 50bcbde4332f93f40acbc7b0b2389fab576beba4 Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 27 Nov 2023 16:03:37 -0800 Subject: [PATCH 2/8] remove "version" field from buildDbObject() since we get it from mongo-adapter --- src/deploy/db/mongo-adapter/mongo-adapter.ts | 2 +- src/deploy/missions/base-deploy-mission.ts | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/deploy/db/mongo-adapter/mongo-adapter.ts b/src/deploy/db/mongo-adapter/mongo-adapter.ts index c66265e4..788874b3 100644 --- a/src/deploy/db/mongo-adapter/mongo-adapter.ts +++ b/src/deploy/db/mongo-adapter/mongo-adapter.ts @@ -95,7 +95,7 @@ export class MongoDBAdapter { }); } - async writeContract (contractName : string, data : IContractDbData, version ?: string) { + async writeContract (contractName : string, data : Omit, version ?: string) { if (!version) { ({ dbVersion: version } = await this.getCheckLatestVersion()); } diff --git a/src/deploy/missions/base-deploy-mission.ts b/src/deploy/missions/base-deploy-mission.ts index 7d78427a..e3b07b0f 100644 --- a/src/deploy/missions/base-deploy-mission.ts +++ b/src/deploy/missions/base-deploy-mission.ts @@ -83,7 +83,7 @@ export class BaseDeployMission { return this.campaign.deployer.getContractArtifact(this.contractName); } - buildDbObject (hhContract : Contract, implAddress : string | null) : IContractDbData { + buildDbObject (hhContract : Contract, implAddress : string | null) : Omit { const { abi, bytecode } = this.getArtifact(); return { name: this.contractName, @@ -91,9 +91,6 @@ export class BaseDeployMission { abi: JSON.stringify(abi), bytecode, implementation: implAddress, - // TODO dep: this might not be needed here since MongoAdapter will add it - // upon writing to DB - version: this.campaign.version, }; } From 756c28a7b4b75fa0fda76b110338e33fc34f1e45 Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 27 Nov 2023 16:07:44 -0800 Subject: [PATCH 3/8] remove redundant storage and base storage adapters and some TODOs --- src/deploy/db/mongo-adapter/mongo-adapter.ts | 2 - src/deploy/storage/base-storage-adapter.ts | 22 --------- src/deploy/storage/file-storage.ts | 52 -------------------- src/deploy/storage/utils.ts | 9 ---- 4 files changed, 85 deletions(-) delete mode 100644 src/deploy/storage/base-storage-adapter.ts delete mode 100644 src/deploy/storage/file-storage.ts delete mode 100644 src/deploy/storage/utils.ts diff --git a/src/deploy/db/mongo-adapter/mongo-adapter.ts b/src/deploy/db/mongo-adapter/mongo-adapter.ts index 788874b3..06f75ac2 100644 --- a/src/deploy/db/mongo-adapter/mongo-adapter.ts +++ b/src/deploy/db/mongo-adapter/mongo-adapter.ts @@ -114,7 +114,6 @@ export class MongoDBAdapter { } // Versioning methods - // TODO dep: add logging to all versioning stages and methods !! async configureVersioning (version ?: string) { // TODO dep: add archiving logic once determined on how to handle it const tempV = await this.getTempVersion(); @@ -259,7 +258,6 @@ export class MongoDBAdapter { } async clearDBForVersion (version : string) { - // TODO dep: add more collections here when added await this.contracts.deleteMany({ version, }); diff --git a/src/deploy/storage/base-storage-adapter.ts b/src/deploy/storage/base-storage-adapter.ts deleted file mode 100644 index 1f99370e..00000000 --- a/src/deploy/storage/base-storage-adapter.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { TLogger } from "../campaign/types"; -import { IContractDbData, TContractDBDoc } from "../db/types"; - - -// TODO dep: do we need this class at all? remove this if not used -export class BaseStorageAdapter { - logger : TLogger; - - constructor (logger : TLogger) { - this.logger = logger; - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - async writeContract (contractDbName : string, data : IContractDbData) { - throw new Error("This class can NOT be used as storage adapter. It needs to be inherited and implemented."); - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - async getContract (contractDbName : string) : Promise { - throw new Error("This class can NOT be used as storage adapter. It needs to be inherited and implemented."); - } -} diff --git a/src/deploy/storage/file-storage.ts b/src/deploy/storage/file-storage.ts deleted file mode 100644 index 68b394b0..00000000 --- a/src/deploy/storage/file-storage.ts +++ /dev/null @@ -1,52 +0,0 @@ -import fs from "fs"; -import path from "path"; -import { BaseStorageAdapter } from "./base-storage-adapter"; -import { TLogger } from "../campaign/types"; -import { IContractDbData } from "../db/types"; - - -export const fileStoragePath = path.join(process.cwd(), "./db"); - - -export class FileStorageAdapter extends BaseStorageAdapter { - private writeLocal : boolean; - - constructor (logger : TLogger, writeLocal = true) { - super(logger); - - this.writeLocal = writeLocal; - - if (!this.writeLocal) return; - - if (!fs.existsSync(fileStoragePath)) { - this.logger.info("Creating temp db directory."); - fs.mkdirSync(fileStoragePath); - } else { - this.logger.info(`Temp db directory exists and will be used at: ${fileStoragePath}.`); - } - } - - async writeContract (contractDbName : string, data : IContractDbData) { - if (!this.writeLocal) return; - - const filePath = path.join(fileStoragePath, `/${contractDbName}.json`); - const fileData = JSON.stringify(data, null, "\t"); - - fs.writeFileSync(filePath, fileData); - - this.logger.info(`Contract data for ${contractDbName} saved to file: ${filePath}.`); - } - - async getContract (contractDbName : string) : Promise { - const filePath = path.join(fileStoragePath, `/${contractDbName}.json`); - - if (!fs.existsSync(filePath)) { - this.logger.debug(`Contract data for ${contractDbName} not found at: ${filePath}.`); - return null; - } - - const fileData = fs.readFileSync(filePath, "utf8"); - - return JSON.parse(fileData); - } -} diff --git a/src/deploy/storage/utils.ts b/src/deploy/storage/utils.ts deleted file mode 100644 index d0b58b3a..00000000 --- a/src/deploy/storage/utils.ts +++ /dev/null @@ -1,9 +0,0 @@ -import fs from "fs"; -import { fileStoragePath } from "./file-storage"; - - -export const wipeFileStorage = () => { - if (fs.existsSync(fileStoragePath)) { - fs.rmSync(fileStoragePath, { recursive: true, force: true }); - } -}; From f59808a8671f02225d7ef472b7eaf82e7c9f56ee Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 27 Nov 2023 16:14:57 -0800 Subject: [PATCH 4/8] remove/change more redundant TODOs --- src/deploy/logger/create-logger.ts | 2 -- src/deploy/missions/base-deploy-mission.ts | 3 --- src/deploy/missions/contracts/access-controller.ts | 3 +-- test/ZNSRootRegistrar.test.ts | 4 ++-- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/deploy/logger/create-logger.ts b/src/deploy/logger/create-logger.ts index 5f5bf597..bdcbd6ac 100644 --- a/src/deploy/logger/create-logger.ts +++ b/src/deploy/logger/create-logger.ts @@ -4,7 +4,6 @@ import { TLogger } from "../campaign/types"; let logger : TLogger | null = null; -// TODO dep: refine this function and configurability of this logger export const createLogger = (logLevel ?: string, silent ?: boolean) => winston.createLogger({ level: logLevel, format: winston.format.combine( @@ -22,7 +21,6 @@ export const createLogger = (logLevel ?: string, silent ?: boolean) => winston.c silent, }); -// TODO dep: add more ENV vars here so we don't have to pass anything export const getLogger = () : TLogger => { if (logger) return logger; diff --git a/src/deploy/missions/base-deploy-mission.ts b/src/deploy/missions/base-deploy-mission.ts index e3b07b0f..0e6bf0db 100644 --- a/src/deploy/missions/base-deploy-mission.ts +++ b/src/deploy/missions/base-deploy-mission.ts @@ -12,9 +12,6 @@ import { ProxyKinds } from "../constants"; import { ContractByName } from "@tenderly/hardhat-tenderly/dist/tenderly/types"; -// TODO dep: -// 1. add better logging for each step -// 2. add proper error handling export class BaseDeployMission { contractName! : string; instanceName! : string; diff --git a/src/deploy/missions/contracts/access-controller.ts b/src/deploy/missions/contracts/access-controller.ts index a2b95c65..6d4e7471 100644 --- a/src/deploy/missions/contracts/access-controller.ts +++ b/src/deploy/missions/contracts/access-controller.ts @@ -7,8 +7,7 @@ export class ZNSAccessControllerDM extends BaseDeployMission { proxyData = { isProxy: false, }; - // TODO dep: make constants available for both this and tests. - // possibly use ones from the helpers + contractName = znsNames.accessController.contract; instanceName = znsNames.accessController.instance; diff --git a/test/ZNSRootRegistrar.test.ts b/test/ZNSRootRegistrar.test.ts index d89b8f93..d8bbcc9e 100644 --- a/test/ZNSRootRegistrar.test.ts +++ b/test/ZNSRootRegistrar.test.ts @@ -47,8 +47,8 @@ import { getConfig } from "../src/deploy/campaign/environments"; require("@nomicfoundation/hardhat-chai-matchers"); -// TODO dep: this is the only test converted to use the new Campaign -// others need to be converted once the Campaign is ready in full +// This is the only test converted to use the new Campaign, other +// contract specific tests are using `deployZNS()` helper describe("ZNSRootRegistrar", () => { let deployer : SignerWithAddress; let user : SignerWithAddress; From 4efc4f36a51409f8ba2038b30cfdfb6b55d1d30b Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 27 Nov 2023 16:39:08 -0800 Subject: [PATCH 5/8] add proper version read to getMongoAdapter --- src/deploy/db/mongo-adapter/get-adapter.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/deploy/db/mongo-adapter/get-adapter.ts b/src/deploy/db/mongo-adapter/get-adapter.ts index c83cbe8e..c6f215f2 100644 --- a/src/deploy/db/mongo-adapter/get-adapter.ts +++ b/src/deploy/db/mongo-adapter/get-adapter.ts @@ -18,6 +18,9 @@ export const getMongoAdapter = async (logger ?: TLogger) : Promise { if (key === "version") key = "curVersion"; From cb9be5da010cc2d9316a4f187bb5ae2baef406c6 Mon Sep 17 00:00:00 2001 From: Kirill Date: Tue, 28 Nov 2023 12:19:07 -0800 Subject: [PATCH 6/8] remove version checking since it's not needed --- src/deploy/db/mongo-adapter/get-adapter.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/deploy/db/mongo-adapter/get-adapter.ts b/src/deploy/db/mongo-adapter/get-adapter.ts index c6f215f2..f1d4313a 100644 --- a/src/deploy/db/mongo-adapter/get-adapter.ts +++ b/src/deploy/db/mongo-adapter/get-adapter.ts @@ -18,9 +18,6 @@ export const getMongoAdapter = async (logger ?: TLogger) : Promise { if (key === "version") key = "curVersion"; From b37531754627c448b5fba3bf886647d602c8d273 Mon Sep 17 00:00:00 2001 From: Kirill Date: Tue, 28 Nov 2023 12:43:01 -0800 Subject: [PATCH 7/8] add logger file transport for non dev environments --- src/deploy/logger/create-logger.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/deploy/logger/create-logger.ts b/src/deploy/logger/create-logger.ts index bdcbd6ac..1313b4a4 100644 --- a/src/deploy/logger/create-logger.ts +++ b/src/deploy/logger/create-logger.ts @@ -1,5 +1,6 @@ import winston from "winston"; import { TLogger } from "../campaign/types"; +import { includes } from "hardhat/internal/hardhat-network/provider/filter"; let logger : TLogger | null = null; @@ -13,7 +14,6 @@ export const createLogger = (logLevel ?: string, silent ?: boolean) => winston.c winston.format.prettyPrint(), ), transports: [ - // TODO dep: figure out where to transport this in production new winston.transports.Console(), ], // TODO dep: make sure we need this to be set! @@ -29,5 +29,15 @@ export const getLogger = () : TLogger => { process.env.SILENT_LOGGER === "true" ); + const logFileName = `deploy-${Date.now()}.log`; + + if (process.env.ENV_LEVEL?.includes("prod") || process.env.ENV_LEVEL?.includes("test")) { + logger.add( + new winston.transports.File({ filename: logFileName }), + ); + + logger.debug(`The ENV_LEVEL is ${process.env.ENV_LEVEL}, logs will be saved in ${ logFileName } file`); + } + return logger; }; From 3d728786da90b07e3b73823d3a78fb8a1297574f Mon Sep 17 00:00:00 2001 From: Kirill Date: Tue, 28 Nov 2023 14:47:58 -0800 Subject: [PATCH 8/8] remove redundant comments --- src/deploy/logger/create-logger.ts | 3 +-- test/DeployCampaignInt.test.ts | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/deploy/logger/create-logger.ts b/src/deploy/logger/create-logger.ts index 1313b4a4..8a1d7ad2 100644 --- a/src/deploy/logger/create-logger.ts +++ b/src/deploy/logger/create-logger.ts @@ -8,7 +8,6 @@ let logger : TLogger | null = null; export const createLogger = (logLevel ?: string, silent ?: boolean) => winston.createLogger({ level: logLevel, format: winston.format.combine( - // TODO dep: adjust the format to what we need winston.format.json(), winston.format.timestamp(), winston.format.prettyPrint(), @@ -16,7 +15,7 @@ export const createLogger = (logLevel ?: string, silent ?: boolean) => winston.c transports: [ new winston.transports.Console(), ], - // TODO dep: make sure we need this to be set! + // TODO dep: do we need this to be set ? exitOnError: false, silent, }); diff --git a/test/DeployCampaignInt.test.ts b/test/DeployCampaignInt.test.ts index 2c25f17f..881d920d 100644 --- a/test/DeployCampaignInt.test.ts +++ b/test/DeployCampaignInt.test.ts @@ -867,8 +867,6 @@ describe("Deploy Campaign Test", () => { before (async () => { [deployAdmin, admin, zeroVault] = await hre.ethers.getSigners(); - // TODO dep ver: add proper checks for the new config values - // and make sure tenderly and etherscan ENV data is acquired correctly config = { deployAdmin, governorAddresses: [deployAdmin.address],