Skip to content

Commit

Permalink
Merge branch 'master' into tomasz-upgrade-test-balance-transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
girazoki authored Feb 7, 2025
2 parents fe4d749 + bdd3830 commit 91754e7
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 31 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/prepare-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
ref: ${{ github.event.inputs.sha }}
- name: Setup Rust toolchain
run: rustup show
- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- name: Build Node
run: cargo build --profile=production --all
- name: Save parachain binary
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/prepare-tanssi-relay-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
ref: ${{ github.event.inputs.sha }}
- name: Setup Rust toolchain
run: rustup show
- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- name: Build Node
run: cargo build --profile=production -p tanssi-relay
- name: Save dancelight binary
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/publish-binary-tannsi-relay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ jobs:
ref: ${{ github.event.inputs.to }}
- name: Setup Rust toolchain
run: rustup show
- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- name: Build Node
run: cargo build --profile=production -p tanssi-relay
- name: Save dancelight binary
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ tmp
# Temporary Moonwall files
**/contracts/out
**/tmp/
**/html/
**/html/
**/downloadPolkadot.ts
4 changes: 4 additions & 0 deletions benchmarking/frame-weight-runtime-template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ use sp_std::marker::PhantomData;

/// Weights for {{pallet}} using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
{{#if (eq pallet "runtime_parachains::assigner_on_demand")}}
impl<T: frame_system::Config> runtime_parachains::on_demand::WeightInfo for SubstrateWeight<T> {
{{else}}
impl<T: frame_system::Config> {{pallet}}::WeightInfo for SubstrateWeight<T> {
{{/if}}
{{#each benchmarks as |benchmark|}}
{{#each benchmark.comments as |comment|}}
/// {{comment}}
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions test/moonwall.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"testFileDir": ["suites/zombie_tanssi"],
"runScripts": [
"build-spec-flashbox.sh",
"download-polkadot.sh",
"downloadPolkadot.ts",
"compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/flashbox-1000.json",
"compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/template-container-2000.json",
"compile-wasm.ts compile -b ../target/release/container-chain-frontier-node -o wasm -c specs/template-container-2001.json"
Expand Down Expand Up @@ -251,7 +251,7 @@
"testFileDir": ["suites/zombie_tanssi"],
"runScripts": [
"build-spec.sh",
"download-polkadot.sh",
"downloadPolkadot.ts",
"compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/tanssi-1000.json",
"compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/template-container-2000.json",
"compile-wasm.ts compile -b ../target/release/container-chain-frontier-node -o wasm -c specs/template-container-2001.json"
Expand Down Expand Up @@ -309,7 +309,7 @@
"testFileDir": ["suites/zombie_tanssi_keep_db"],
"runScripts": [
"build-spec-single-container.sh",
"download-polkadot.sh",
"downloadPolkadot.ts",
"compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/single-container-tanssi-1000.json",
"compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/single-container-template-container-2000.json"
],
Expand Down Expand Up @@ -346,7 +346,7 @@
"testFileDir": ["suites/zombie_tanssi_metrics"],
"runScripts": [
"build-spec-single-container.sh",
"download-polkadot.sh",
"downloadPolkadot.ts",
"compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/single-container-tanssi-1000.json",
"compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/single-container-template-container-2000.json"
],
Expand Down Expand Up @@ -384,7 +384,7 @@
"testFileDir": ["suites/zombie_tanssi_one_node"],
"runScripts": [
"build-spec-one-node.sh",
"download-polkadot.sh",
"downloadPolkadot.ts",
"compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/one-node-tanssi-1000.json"
],
"foundation": {
Expand Down Expand Up @@ -416,7 +416,7 @@
"testFileDir": ["suites/zombie_tanssi_parathreads"],
"runScripts": [
"build-spec-parathreads.sh",
"download-polkadot.sh",
"downloadPolkadot.ts",
"compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/parathreads-tanssi-1000.json",
"compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/parathreads-template-container-2000.json",
"compile-wasm.ts compile -b ../target/release/container-chain-frontier-node -o wasm -c specs/parathreads-template-container-2001.json"
Expand Down Expand Up @@ -469,7 +469,7 @@
"testFileDir": ["suites/zombie_tanssi_rotation"],
"runScripts": [
"build-spec.sh",
"download-polkadot.sh",
"downloadPolkadot.ts",
"compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/tanssi-1000.json",
"compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/template-container-2000.json",
"compile-wasm.ts compile -b ../target/release/container-chain-frontier-node -o wasm -c specs/template-container-2001.json"
Expand Down Expand Up @@ -522,7 +522,7 @@
"testFileDir": ["suites/zombie_tanssi_warp_sync"],
"runScripts": [
"build-spec-single-container.sh",
"download-polkadot.sh",
"downloadPolkadot.ts",
"compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/single-container-tanssi-1000.json",
"compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/single-container-template-container-2000.json"
],
Expand Down Expand Up @@ -557,7 +557,7 @@
{
"name": "zombie_dancebox_upgrade",
"testFileDir": ["suites/zombie_dancebox_upgrade"],
"runScripts": ["download-polkadot.sh"],
"runScripts": ["downloadPolkadot.ts"],
"timeout": 600000,
"foundation": {
"rtUpgradePath": "../target/release/wbuild/dancebox-runtime/dancebox_runtime.compact.compressed.wasm",
Expand All @@ -574,7 +574,7 @@
"runScripts": [
"download-latest-rt-binaries.sh",
"build-spec-single-container.sh tmp container-chain-simple-node flashbox-local",
"download-polkadot.sh",
"downloadPolkadot.ts",
"compile-wasm.ts compile -b tmp/tanssi-node -o wasm -c specs/single-container-tanssi-1000.json",
"compile-wasm.ts compile -b tmp/container-chain-simple-node -o wasm -c specs/single-container-template-container-2000.json"
],
Expand Down Expand Up @@ -638,7 +638,7 @@
"runScripts": [
"download-latest-rt-binaries.sh",
"build-spec-single-container.sh tmp container-chain-simple-node flashbox-local",
"download-polkadot.sh",
"downloadPolkadot.ts",
"download-latest-binaries.sh ../target/release",
"compile-wasm.ts compile -b tmp/tanssi-node -o wasm -c specs/single-container-tanssi-1000.json",
"compile-wasm.ts compile -b tmp/container-chain-simple-node -o wasm -c specs/single-container-template-container-2000.json"
Expand Down Expand Up @@ -710,7 +710,7 @@
"runScripts": [
"download-latest-rt-binaries.sh",
"build-spec-single-container.sh tmp container-chain-frontier-node flashbox-local",
"download-polkadot.sh",
"downloadPolkadot.ts",
"compile-wasm.ts compile -b tmp/tanssi-node -o wasm -c specs/single-container-tanssi-1000.json",
"compile-wasm.ts compile -b tmp/container-chain-frontier-node -o wasm -c specs/single-container-template-container-2000.json"
],
Expand Down Expand Up @@ -750,7 +750,7 @@
"runScripts": [
"download-latest-rt-binaries.sh",
"build-spec-single-container.sh tmp container-chain-frontier-node flashbox-local",
"download-polkadot.sh",
"downloadPolkadot.ts",
"download-latest-binaries.sh ../target/release",
"compile-wasm.ts compile -b tmp/tanssi-node -o wasm -c specs/single-container-tanssi-1000.json",
"compile-wasm.ts compile -b tmp/container-chain-frontier-node -o wasm -c specs/single-container-template-container-2000.json"
Expand Down Expand Up @@ -872,7 +872,7 @@
"testFileDir": ["suites/zombie_data_preservers"],
"runScripts": [
"build-spec-data-preservers.sh",
"download-polkadot.sh",
"downloadPolkadot.ts",
"compile-wasm.ts compile -b ../target/release/tanssi-node -o wasm -c specs/data-preservers-dancebox-1000.json",
"compile-wasm.ts compile -b ../target/release/container-chain-simple-node -o wasm -c specs/data-preservers-container-2000.json",
"compile-wasm.ts compile -b ../target/release/container-chain-frontier-node -o wasm -c specs/data-preservers-container-2001.json"
Expand Down
1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"pnpm": "9.13.0",
"prettier": "2.8.8",
"solc": "0.8.21",
"toml": "^3.0.0",
"tsx": "4.19.2",
"typescript": "5.6.3",
"viem": "2.21.45",
Expand Down
7 changes: 7 additions & 0 deletions test/polkadotReleaseMapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"stable2409": {
"polkadot": "599cb6b8a0f67098717315c6db33e28983873e6c94a4272c9d0a03dd06b70428",
"polkadot-prepare-worker": "4dc5964da9052faee01f0d727fda08ab573989ac6c81f597d21028e76ae22f9c",
"polkadot-execute-worker": "8932f0b07323a497470de2c7d8b9b7583af27de3836518fbf62047a68bc788f9"
}
}
17 changes: 1 addition & 16 deletions test/scripts/download-polkadot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,7 @@ delete_if_not_binary tmp/polkadot-execute-worker
delete_if_not_binary tmp/polkadot-prepare-worker

if [[ -f tmp/polkadot && -f tmp/polkadot-execute-worker && -f tmp/polkadot-prepare-worker ]]; then
POLKADOT_VERSION=$(tmp/polkadot --version)
if [[ $POLKADOT_VERSION == *$polkadot_release* ]]; then
exit 0
else
echo "Updating polkadot binary from $POLKADOT_VERSION to $polkadot_release"

pnpm moonwall download polkadot $polkadot_release tmp
chmod +x tmp/polkadot

pnpm moonwall download polkadot-execute-worker $polkadot_release tmp
chmod +x tmp/polkadot-execute-worker

pnpm moonwall download polkadot-prepare-worker $polkadot_release tmp
chmod +x tmp/polkadot-prepare-worker

fi
echo "Polkadot binary already found, skipping download ..."
else
echo "Polkadot binary not found, downloading $polkadot_release"
pnpm moonwall download polkadot $polkadot_release tmp
Expand Down
146 changes: 146 additions & 0 deletions test/scripts/downloadPolkadot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/* eslint-disable */
import jsonFile from "../polkadotReleaseMapping.json" with {type: "json"};
import fs from "node:fs/promises";
import fsSync from "node:fs"
import assert from "node:assert"
import { parse } from "toml"
import path from "node:path"
import { execSync } from "node:child_process"
import { createHash } from "node:crypto";

const CONFIG = {
FOLDER_NAME: 'tmp',
BINARIES: ['polkadot', 'polkadot-execute-worker', 'polkadot-prepare-worker'] as const,
CARGO_PATH: '../Cargo.toml',
} as const;

async function main() {

const polkadotVersionMappings: PolkadotVersionMapping = jsonFile
const fileContents = await fs.readFile(CONFIG.CARGO_PATH, "utf-8")
const cargoToml = parse(fileContents) as CargoToml;
const stableVersion = findPolkadotStableVersion(cargoToml.workspace.dependencies)
console.log(`🔎 Found polkadot-sdk version: ${stableVersion}`)

for (const binName of CONFIG.BINARIES) {
const pathName = path.join(CONFIG.FOLDER_NAME, binName)
if (fsSync.existsSync(pathName)) {
const existingChecksum = getSha256(pathName)
console.log(`✏️ File already exists: ${mini(existingChecksum)}`);

const savedChecksum = polkadotVersionMappings[stableVersion]?.[binName]

if (!savedChecksum || savedChecksum !== existingChecksum) {
if (!savedChecksum) {
console.log(`⚠️ Saved checksum not found for ${binName}:${stableVersion}`)
} else {
console.log(`⚠️ File mismatch ${mini(existingChecksum)} vs ${mini(savedChecksum)}, downloading...`);
}
execSync(`pnpm moonwall download -d ${binName} ${stableVersion} ${CONFIG.FOLDER_NAME}`, { stdio: "inherit" });
const sha256 = getSha256(pathName)
polkadotVersionMappings[stableVersion] = {
...polkadotVersionMappings[stableVersion],
[binName]: sha256
}
await fs.writeFile("polkadotReleaseMapping.json", JSON.stringify(polkadotVersionMappings, null, 2))
} else {
console.log(`✅ Binary ${pathName} matches saved version`)
}
} else {
// New File flow
console.log("📥️ File does not exist, downloading...");
execSync(`pnpm moonwall download ${binName} ${stableVersion} ${CONFIG.FOLDER_NAME}`, { stdio: "inherit" });
const sha256 = getSha256(pathName)
console.log(`💾 Downloaded file: ${mini(sha256)}`);
polkadotVersionMappings[stableVersion] = {
...polkadotVersionMappings[stableVersion],
[binName]: sha256
}
await fs.writeFile("polkadotReleaseMapping.json", JSON.stringify(polkadotVersionMappings, null, 2))
console.log("✅ Saved to version mapping ")
}
}
}

main()
.then(() => console.log(`🎉 Finished verifying binaries: [${CONFIG.BINARIES.join(", ")}]`))
.catch((err: unknown) => {
console.error("❌ Error:", err);
process.exit(1);
});
/**
* Interfaces
**/

interface PolkadotVersionMapping {
[key: `stable${number}-${number}` | `stable${number}`]: DownloadHashes
}
interface CargoToml {
workspace: {
dependencies: Record<string, { git?: string; branch?: string }>;
};
}

interface DownloadHashes {
polkadot: string;
"polkadot-execute-worker": string;
"polkadot-prepare-worker": string;
}

/**
* Functions
**/
function extractStableVersion(branch: string): string | null {
const match = branch.match(/stable(\d+)/)
return match ? `stable${match[1]}` : null
}

function findPolkadotStableVersion(dependencies: Record<string, any>): string {
const polkadotDeps = Object.entries(dependencies).filter(([_, config]) =>
typeof config === "object" &&
config.git === "https://github.com/moondance-labs/polkadot-sdk"
)

let stableVersions: Array<string> | Set<string> = new Set(
polkadotDeps
.map(([_, config]) => extractStableVersion(config.branch))
.filter((version): version is string => version !== null)
)

if (stableVersions.size === 0) {
throw new Error("No stable version found in polkadot-sdk dependencies")
}

if (stableVersions.size > 1) {
stableVersions = Array.from(stableVersions).sort((a, b) => {
// Extract numbers and compare
const aMatch = a.match(/stable(\d+)(?:-(\d+))?/)
const bMatch = b.match(/stable(\d+)(?:-(\d+))?/)

assert(aMatch, "this is already mapped, this should never happen")
assert(bMatch, "this is already mapped, this should never happen")

const mainVersionDiff = Number.parseInt(bMatch[1]) - Number.parseInt(aMatch[1])
if (mainVersionDiff !== 0) {
return mainVersionDiff
}

const aSubVersion = aMatch[2] ? Number.parseInt(aMatch[2]) : 0
const bSubVersion = bMatch[2] ? Number.parseInt(bMatch[2]) : 0
return bSubVersion - aSubVersion
})
console.error(`⚠️ Multiple stable versions found: ${Array.from(stableVersions).join(", ")}. Choosing: ${stableVersions[0]}`)
}

return Array.from(stableVersions)[0]
}


const getSha256 = (filePath: string) => {
const fileBuffer = fsSync.readFileSync(filePath);
const hashSum = createHash("sha256");
hashSum.update(fileBuffer);
return hashSum.digest("hex");
}

const mini = (hash: string) => `<${hash.slice(0, 4)}...${hash.slice(-4)}>`
6 changes: 6 additions & 0 deletions tools/benchmarking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ function bench {
TEMPLATE_TO_USE="./benchmarking/frame-weight-runtime-template-xcm.hbs"
MODIFIED_PALLET_FILE=${PALLET/::/_}
OUTPUT="${OUTPUT_PATH}/$MODIFIED_PALLET_FILE.rs"
elif [[ "$PALLET" == *"runtime_common"* || "$PALLET" == *"runtime_parachains"* ]]; then
MODIFIED_PALLET_FILE=${PALLET/::/_}
OUTPUT="${OUTPUT_PATH}/$MODIFIED_PALLET_FILE.rs"
fi
touch "$OUTPUT"
WASMTIME_BACKTRACE_DETAILS=1 ${BINARY} benchmark pallet \
Expand All @@ -119,6 +122,9 @@ function bench {
TEMPLATE_TO_USE="./benchmarking/frame-weight-runtime-template-xcm.hbs"
MODIFIED_PALLET_FILE=${1/::/_}
OUTPUT="${OUTPUT_PATH}/$MODIFIED_PALLET_FILE.rs"
elif [[ "${1}" == *"runtime_common"* || "$1" == *"runtime_parachains"* ]]; then
MODIFIED_PALLET_FILE=${1/::/_}
OUTPUT="${OUTPUT_PATH}/$MODIFIED_PALLET_FILE.rs"
fi
touch "$OUTPUT"
WASMTIME_BACKTRACE_DETAILS=1 ${BINARY} benchmark pallet \
Expand Down

0 comments on commit 91754e7

Please sign in to comment.