Skip to content

Commit c16b01b

Browse files
committed
fix: update runtime metadata
1 parent e2cdf24 commit c16b01b

File tree

10 files changed

+159
-34
lines changed

10 files changed

+159
-34
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ jobs:
2626
- name: Install Rust
2727
uses: dtolnay/rust-toolchain@stable
2828
with:
29+
toolchain: 1.83.0
2930
targets: wasm32-unknown-unknown
3031

3132
- name: Install wasm-pack
32-
run: cargo install wasm-pack
33+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
3334

3435
# Need to build the WASM before type-checking
3536
# otherwise we're missing code and tsc will fail
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Deploy Runtime Upgrade to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [paseo-runtime-upgrade]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: "pages-paseo-runtime-upgrade"
15+
cancel-in-progress: true
16+
17+
jobs:
18+
deploy:
19+
environment:
20+
name: github-pages
21+
url: ${{ steps.deployment.outputs.page_url }}
22+
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- name: Set up Node.js 22.x
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: 22.x
31+
32+
- name: Install Rust
33+
uses: dtolnay/rust-toolchain@stable
34+
with:
35+
toolchain: 1.83.0
36+
targets: wasm32-unknown-unknown
37+
38+
- name: Install wasm-pack
39+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
40+
41+
- name: Install pnpm
42+
uses: pnpm/action-setup@v2
43+
with:
44+
version: latest
45+
46+
- name: Install dependencies
47+
run: pnpm install --frozen-lockfile
48+
49+
- name: Build
50+
run: pnpm build
51+
52+
- name: Upload artifact
53+
uses: actions/upload-pages-artifact@v3
54+
with:
55+
path: dist
56+
57+
- name: Deploy to GitHub Pages
58+
id: deployment
59+
uses: actions/deploy-pages@v4

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
- name: Install Rust
3535
uses: dtolnay/rust-toolchain@stable
3636
with:
37+
toolchain: 1.83.0
3738
targets: wasm32-unknown-unknown
3839

3940
- name: Install wasm-pack

.papi/metadata/polkaStorage.scale

0 Bytes
Binary file not shown.

.papi/polkadot-api.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"descriptorPath": ".papi/descriptors",
44
"entries": {
55
"polkaStorage": {
6-
"wsUrl": "ws://localhost:42069",
6+
"wsUrl": "ws:/localhost:8000",
77
"metadata": ".papi/metadata/polkaStorage.scale",
8-
"genesis": "0x4545454545454545454545454545454545454545454545454545454545454545",
9-
"codeHash": "0xb84fe515e735f6a2ca1032f6d1ff7befc5a29c5c48ea56bd90eebb0d509533ee"
8+
"genesis": "0xa6f9a4facafa6157734b6a52503070304d34919a8299f46e6c7bde2ee000ccd6",
9+
"codeHash": "0x164f37eaf7ceb43de9b9a79dd6105105931269478212669e2c99a0801378c92e"
1010
}
1111
}
1212
}

pnpm-lock.yaml

Lines changed: 44 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/conversion.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Multiaddr, NodeAddress } from "@multiformats/multiaddr";
12
import { BLOCK_TIME } from "./consts";
23

34
export function blockToTime(
@@ -60,3 +61,26 @@ export function formatDuration(duration: {
6061
}
6162
return `${result.join(", ")}`;
6263
}
64+
65+
export function baseURLFromP2pMultiaddr(nodeAddress: NodeAddress): string {
66+
const { address, port } = nodeAddress;
67+
68+
// address can be an IP or a hostname depending on the multiaddr
69+
// We only rewrite when it's our p2p DNS name.
70+
const uploadHost =
71+
typeof address === "string" && address.startsWith("p2p.")
72+
? address.replace(/^p2p\./, "upload.")
73+
: address;
74+
75+
// If the p2p multiaddr is tcp/443/wss, upload should be https on 443
76+
// If you're on some other port locally, keep it consistent.
77+
const isStandardHttps = port === 443 || port === 0 || port == null;
78+
79+
return isStandardHttps ? `https://${uploadHost}` : `https://${uploadHost}:${port}`;
80+
}
81+
82+
export type ProviderInfo = {
83+
accountId: string;
84+
multiaddr: Multiaddr;
85+
pricePerBlock: number;
86+
};

src/lib/download.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import { type Multiaddr, multiaddr } from "@multiformats/multiaddr";
22
import { fileTypeFromBuffer } from "file-type";
33
import { CID } from "multiformats";
44
import type { PolkaStorageApi } from "../GlobalCtx";
5+
import { baseURLFromP2pMultiaddr } from "./conversion";
56
import type { Deal } from "./deals";
67

78
export async function downloadDeal(api: PolkaStorageApi | null, deal: Deal) {
89
if (!api) throw new Error("API not ready");
910

1011
// look up provider addr
1112
const maddr = await getProviderMultiaddr(api, deal.value.provider);
12-
const { address, port } = maddr.nodeAddress();
13+
const baseUrl = baseURLFromP2pMultiaddr(maddr.nodeAddress());
1314

1415
// fetch the raw piece
1516
const pieceCid = CID.decode(deal.value.piece_cid.asBytes()).toString();
16-
const res = await fetch(`http://${address}:${port}/api/v0/download/${pieceCid}`);
17+
const res = await fetch(`${baseUrl}/api/v0/download/${pieceCid}`);
1718
if (!res.ok) throw new Error(res.statusText);
1819
const blob = await res.blob();
1920

src/lib/fileUpload.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function uploadFile(
1515
body.append("file", file);
1616

1717
const addr = secure_addr ? secure_addr : `http://${address.ip}:${address.port}`;
18-
18+
console.log(`Uploading to: ${addr}`);
1919
return await fetch(`${addr}/api/v0/upload/${dealCid}`, {
2020
method: "PUT",
2121
body,
@@ -32,6 +32,7 @@ export async function proposeDeal(
3232
}
3333

3434
const addr = secure_addr ? secure_addr : `http://${address.ip}:${address.port}`;
35+
console.log(`Proposing to: ${addr}`);
3536
const response = await fetch(`${addr}/api/v0/propose_deal`, {
3637
method: "POST",
3738
headers: { "Content-Type": "application/json" },

src/pages/DealPreparation.tsx

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { Multiaddr } from "@multiformats/multiaddr";
21
import type { InjectedAccountWithMeta } from "@polkadot/extension-inject/types";
32
import type { TypeRegistry } from "@polkadot/types";
43
import { Loader2 } from "lucide-react";
@@ -12,6 +11,7 @@ import {
1211
} from "../components/deal-proposal-form/DealProposalForm";
1312
import type { FormValues } from "../components/deal-proposal-form/types";
1413
import { DEFAULT_MAX_PROVE_COMMIT_DURATION, fetchMaxProveCommitDurationConst } from "../lib/consts";
14+
import { type ProviderInfo, baseURLFromP2pMultiaddr } from "../lib/conversion";
1515
import { createSignedRpc, toRpc } from "../lib/dealProposal";
1616
import { proposeDeal, publishDeal, uploadFile } from "../lib/fileUpload";
1717
import { loadWrapper } from "../lib/loadWrapper";
@@ -28,12 +28,6 @@ type DealInfo = {
2828
endBlock: number;
2929
};
3030

31-
type ProviderInfo = {
32-
accountId: string;
33-
multiaddr: Multiaddr;
34-
pricePerBlock: number;
35-
};
36-
3731
type DealId = number;
3832

3933
async function executeDeal(
@@ -43,6 +37,8 @@ async function executeDeal(
4337
registry: TypeRegistry,
4438
): Promise<DealId> {
4539
const { address, port } = providerInfo.multiaddr.nodeAddress();
40+
const uploadAddress = baseURLFromP2pMultiaddr(providerInfo.multiaddr.nodeAddress());
41+
console.log(uploadAddress);
4642

4743
const clientAccount = accounts.find((v) => v.address === dealInfo.proposal.client);
4844
if (!clientAccount) {
@@ -61,12 +57,18 @@ async function executeDeal(
6157
ip: address,
6258
port: port,
6359
},
60+
uploadAddress,
6461
);
6562

66-
const response = await uploadFile(dealInfo.file, proposeDealResponse, {
67-
ip: address,
68-
port: port,
69-
});
63+
const response = await uploadFile(
64+
dealInfo.file,
65+
proposeDealResponse,
66+
{
67+
ip: address,
68+
port: port,
69+
},
70+
uploadAddress,
71+
);
7072
if (!response.ok) {
7173
throw new Error(response.statusText);
7274
}
@@ -80,10 +82,14 @@ async function executeDeal(
8082
registry,
8183
clientAccount,
8284
);
83-
const dealId = await publishDeal(signedRpc, {
84-
ip: address,
85-
port: port,
86-
});
85+
const dealId = await publishDeal(
86+
signedRpc,
87+
{
88+
ip: address,
89+
port: port,
90+
},
91+
uploadAddress,
92+
);
8793

8894
return dealId;
8995
}

0 commit comments

Comments
 (0)