-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bouncer command for submitting runtime upgrades (#4122)
* feat: bouncer command for submitting runtime upgrades * chore: linting
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env -S pnpm tsx | ||
// INSTRUCTIONS | ||
// | ||
// This command takes 1 mandatory argument, and 2 optional arguments. | ||
// Arguments: | ||
// 1. Path to the runtime wasm file | ||
// 2. Optional: A JSON string representing the semver restriction for the upgrade. If not provided, the upgrade will not be restricted by semver. | ||
// 3. Optional: A number representing the percentage of nodes that must be upgraded before the upgrade will be allowed to proceed. If not provided, the upgrade will not be restricted by the number of nodes that have upgraded. | ||
// | ||
// For example: ./commands/submit_runtime_upgrade.ts /path/to/state_chain_runtime.compact.compressed.wasm '{"major": 1, "minor": 2, "patch": 3}' 50 | ||
|
||
import { submitRuntimeUpgrade } from '../shared/submit_runtime_upgrade'; | ||
import { runWithTimeout } from '../shared/utils'; | ||
|
||
async function main() { | ||
const wasmPath = process.argv[2]; | ||
|
||
const arg3 = process.argv[3].trim(); | ||
const semverRestriction = arg3 ? JSON.parse(arg3) : undefined; | ||
|
||
const arg4 = process.argv[4].trim(); | ||
const percentNodesUpgraded = arg4 ? Number(arg4) : undefined; | ||
|
||
await submitRuntimeUpgrade(wasmPath, semverRestriction, percentNodesUpgraded); | ||
process.exit(0); | ||
} | ||
|
||
runWithTimeout(main(), 20000).catch((error) => { | ||
console.error(error); | ||
process.exit(-1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { compactAddLength } from '@polkadot/util'; | ||
import { promises as fs } from 'fs'; | ||
import { submitGovernanceExtrinsic } from './cf_governance'; | ||
import { getChainflipApi } from '../shared/utils'; | ||
|
||
async function readRuntimeWasmFromFile(filePath: string): Promise<Uint8Array> { | ||
return compactAddLength(new Uint8Array(await fs.readFile(filePath))); | ||
} | ||
|
||
// By default we don't want to restrict that any of the nodes need to be upgraded. | ||
export async function submitRuntimeUpgrade( | ||
wasmPath: string, | ||
semverRestriction?: Record<string, number>, | ||
percentNodesUpgraded = 0, | ||
) { | ||
const runtimeWasm = await readRuntimeWasmFromFile(wasmPath); | ||
|
||
console.log('Submitting runtime upgrade.'); | ||
const chainflip = await getChainflipApi(); | ||
|
||
let versionPercentRestriction; | ||
if (semverRestriction && percentNodesUpgraded) { | ||
versionPercentRestriction = [semverRestriction, percentNodesUpgraded]; | ||
} else { | ||
versionPercentRestriction = undefined; | ||
} | ||
|
||
await submitGovernanceExtrinsic( | ||
chainflip.tx.governance.chainflipRuntimeUpgrade(versionPercentRestriction, runtimeWasm), | ||
); | ||
|
||
console.log('Runtime upgrade completed.'); | ||
} |