Skip to content

Commit

Permalink
feat: smarter migrations
Browse files Browse the repository at this point in the history
Libs and core artifacts can be forced updated individually. Core/libs deps attended.
  • Loading branch information
guidiaz committed Feb 13, 2024
1 parent 295b223 commit dfb3155
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions migrations/scripts/2_libs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ module.exports = async function (_, network, [, from]) {
targets.WitnetPriceFeedsLib,
]

const selection = utils.getWitnetArtifactsFromArgs()

const deployer = await WitnetDeployer.deployed()
for (const index in libs) {
const key = libs[index]
const artifact = artifacts.require(key)
if (
utils.isNullAddress(addresses[network][key])
|| (await web3.eth.getCode(addresses[network][key])).length < 3
|| selection.includes(key)
) {
utils.traceHeader(`Deploying '${key}'...`)
const libInitCode = artifact.toJSON().bytecode
Expand Down
6 changes: 5 additions & 1 deletion migrations/scripts/3_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ async function deploy (specs) {

const addresses = await utils.readAddresses()
if (!addresses[network]) addresses[network] = {};

const selection = utils.getWitnetArtifactsFromArgs()

const contract = artifacts.require(key)
if (
utils.isNullAddress(addresses[network][key])
|| (await web3.eth.getCode(addresses[network][key])).length < 3
|| selection.includes(key)
|| (libs && selection.filter(item => libs.includes(item)).length > 0)
) {
utils.traceHeader(`Deploying '${key}'...`)
console.info(" ", "> account: ", from)
Expand All @@ -82,7 +86,7 @@ async function deploy (specs) {
if (immutables?.values) values = [...values, ...immutables.values]
const constructorArgs = web3.eth.abi.encodeParameters(types, values)
if (constructorArgs.length > 2) {
console.info(" ", "> constructor types:", types)
console.info(" ", "> constructor types:", JSON.stringify(types))
console.info(" ", "> constructor args: ", constructorArgs.slice(2))
}
const coreBytecode = link(contract.toJSON().bytecode, libs, targets)
Expand Down
14 changes: 10 additions & 4 deletions migrations/scripts/4_proxies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ const merge = require("lodash.merge")
const settings = require("../../settings")
const utils = require("../../src/utils")

const version = `${
require("../../package").version
}-${
require("child_process").execSync("git rev-parse HEAD").toString().trim().substring(0, 7)
}`

const WitnetDeployer = artifacts.require("WitnetDeployer")
const WitnetProxy = artifacts.require("WitnetProxy")

module.exports = async function (_, network, [, from, reporter]) {
const addresses = await utils.readAddresses(network)

const targets = settings.getArtifacts(network)
const specs = settings.getSpecs(network)
Expand Down Expand Up @@ -94,11 +99,12 @@ async function deploy (target) {
utils.traceHeader(`Upgrading '${key}'...`)
const oldVersion = await oldImpl.version.call({ from })
const newVersion = await newImpl.version.call({ from })
const color = newVersion === version ? `\x1b[1;97m` : `\x1b[93m`
if (
(process.argv.length >= 3 && process.argv[2].includes("--upgrade-all")) || (
["y", "yes"].includes(
(await utils.prompt(` > From v${oldVersion} to ${targets[key]} v${newVersion} ? (y/N) `)).toLowerCase().trim()
)
["y", "yes"].includes((await
utils.prompt(` > Upgrade to ${color}${targets[key]} v${newVersion}\x1b[0m? (y/N) `)
).toLowerCase().trim())
)
) {
const initdata = mutables ? web3.eth.abi.encodeParameters(mutables.types, mutables.values) : "0x"
Expand Down

0 comments on commit dfb3155

Please sign in to comment.