fix: harden upgrade publication and refresh
This commit is contained in:
@@ -23,6 +23,49 @@ remove_local_manifest() {
|
||||
fi
|
||||
}
|
||||
|
||||
remove_local_upgrade_marker() {
|
||||
local path=$1
|
||||
[[ -e "$path" ]] || return 0
|
||||
if node -e '
|
||||
const fs = require("fs");
|
||||
const marker = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
||||
const record = (value) => value && typeof value === "object" && !Array.isArray(value);
|
||||
const exact = (value, keys) => record(value)
|
||||
&& Object.keys(value).sort().join("\0") === [...keys].sort().join("\0");
|
||||
const uint = (value) => Number.isSafeInteger(value) && value >= 0;
|
||||
const address = (value) => typeof value === "string"
|
||||
&& /^0x[0-9a-fA-F]{40}$/.test(value) && !/^0x0{40}$/i.test(value);
|
||||
const same = (first, second) => address(first) && address(second) && first.toLowerCase() === second.toLowerCase();
|
||||
const noop = exact(marker, ["mode", "chainId", "observedBlock", "ownerNonce", "proxy", "implementation"])
|
||||
&& marker.mode === "noop" && marker.chainId === 31337
|
||||
&& uint(marker.observedBlock) && uint(marker.ownerNonce)
|
||||
&& address(marker.proxy) && address(marker.implementation);
|
||||
const upgradeKeys = ["mode", "network", "chainId", "token", "proxy", "previousImplementation", "implementation", "owner", "deploymentBlock", "snapshot"];
|
||||
const snapshotKeys = ["proxy", "implementation", "owner", "asset", "paused", "balances", "liabilities", "reserves", "surplus", "deploymentBlock", "version"];
|
||||
const snapshot = marker?.snapshot;
|
||||
const balances = Array.isArray(snapshot?.balances) && snapshot.balances.length > 0
|
||||
&& snapshot.balances.every((balance) => exact(balance, ["address", "balance"])
|
||||
&& address(balance.address) && uint(balance.balance));
|
||||
const upgrade = exact(marker, upgradeKeys)
|
||||
&& marker.mode === "upgrade" && marker.network === "anvil" && marker.chainId === 31337
|
||||
&& uint(marker.deploymentBlock) && marker.deploymentBlock >= 1
|
||||
&& [marker.token, marker.proxy, marker.previousImplementation, marker.implementation, marker.owner].every(address)
|
||||
&& !same(marker.previousImplementation, marker.implementation)
|
||||
&& exact(snapshot, snapshotKeys) && typeof snapshot.paused === "boolean" && snapshot.version === 1
|
||||
&& same(snapshot.proxy, marker.proxy) && same(snapshot.implementation, marker.previousImplementation)
|
||||
&& same(snapshot.owner, marker.owner) && same(snapshot.asset, marker.token)
|
||||
&& snapshot.deploymentBlock === marker.deploymentBlock && balances
|
||||
&& uint(snapshot.liabilities) && uint(snapshot.reserves) && uint(snapshot.surplus)
|
||||
&& snapshot.reserves >= snapshot.liabilities
|
||||
&& snapshot.reserves - snapshot.liabilities === snapshot.surplus;
|
||||
process.exit(noop || upgrade ? 0 : 1);
|
||||
' "$path" 2>/dev/null; then
|
||||
remove_exact "$path"
|
||||
else
|
||||
printf 'Preserved non-local or invalid upgrade marker %s\n' "${path#"$ROOT/"}"
|
||||
fi
|
||||
}
|
||||
|
||||
demo_stop_recorded "$ROOT" vite
|
||||
demo_stop_recorded "$ROOT" anvil
|
||||
|
||||
@@ -36,6 +79,7 @@ remove_exact "$ROOT/.demo/vite.pgid"
|
||||
remove_exact "$ROOT/.demo/vite.log"
|
||||
|
||||
remove_local_manifest "$ROOT/deployments/pending.json"
|
||||
remove_local_upgrade_marker "$ROOT/deployments/upgrade-pending.json"
|
||||
remove_local_manifest "$ROOT/deployments/anvil.json"
|
||||
remove_local_manifest "$ROOT/deployments/active.json"
|
||||
remove_local_manifest "$ROOT/web/public/deployment.json"
|
||||
|
||||
Reference in New Issue
Block a user