Skip to content

Commit 3dee22d

Browse files
authored
Merge branch 'main' into smoldot_read
2 parents 4eee061 + 2169223 commit 3dee22d

File tree

4 files changed

+82
-28
lines changed

4 files changed

+82
-28
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,57 @@ or
246246
Run on the dedicated machine from the root directory:
247247
```
248248
python3 scripts/cmd/cmd.py bench bulletin-polkadot
249+
```
250+
251+
# Troubleshooting
252+
253+
## Build Bulletin Mac OS
254+
255+
### Algorithm file not found error
256+
257+
If you encounter an error similar to:
258+
259+
```
260+
warning: [email protected]: In file included from /Users/ndk/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cxx-1.0.186/src/cxx.cc:1:
261+
warning: [email protected]: /Users/ndk/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cxx-1.0.186/src/../include/cxx.h:2:10: fatal error: 'algorithm' file not found
262+
warning: [email protected]: 2 | #include <algorithm>
263+
warning: [email protected]: | ^~~~~~~~~~~
264+
warning: [email protected]: 1 error generated.
265+
error: failed to run custom build command for `cxx v1.0.186`
266+
```
267+
268+
This typically means your C++ standard library headers can’t be found by the compiler. This is a toolchain setup issue.
269+
270+
To fix:
271+
- Run `xcode-select --install`.
272+
- If it says “already installed”, reinstall them (sometimes they break after OS updates):
273+
274+
```bash
275+
sudo rm -rf /Library/Developer/CommandLineTools
276+
xcode-select --install
277+
```
278+
279+
- Check the Active Developer Path: `xcode-select -p`. It should output one of: `/Applications/Xcode.app/Contents/Developer`, `/Library/Developer/CommandLineTools`
280+
- If it’s empty or incorrect, set it manually: `sudo xcode-select --switch /Library/Developer/CommandLineTools`
281+
- If none of the above helped, see the official Mac OS recommendations for [polkadot-sdk](https://docs.polkadot.com/develop/parachains/install-polkadot-sdk/#macos)
282+
283+
### dyld: Library not loaded: @rpath/libclang.dylib
284+
285+
This means that your build script tried to use `libclang` (from LLVM) but couldn’t find it anywhere on your system or in the `DYLD_LIBRARY_PATH`.
286+
287+
To fix:`brew install llvm` and
288+
```
289+
export LIBCLANG_PATH="$(brew --prefix llvm)/lib"
290+
export LD_LIBRARY_PATH="$LIBCLANG_PATH:$LD_LIBRARY_PATH"
291+
export DYLD_LIBRARY_PATH="$LIBCLANG_PATH:$DYLD_LIBRARY_PATH"
292+
export PATH="$(brew --prefix llvm)/bin:$PATH"
293+
```
294+
295+
Now verify `libclang.dylib` exists:
296+
- `ls "$(brew --prefix llvm)/lib/libclang.dylib"`
297+
298+
If that file exists all good, you can rebuild the project now:
299+
```
300+
cargo clean
301+
cargo build --release
249302
```

examples/authorize_and_store.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { cryptoWaitReady, blake2AsU8a } from '@polkadot/util-crypto';
1212
import { CID } from 'multiformats/cid';
1313
import * as multihash from 'multiformats/hashes/digest';
1414
import { create } from 'ipfs-http-client';
15+
import { waitForNewBlock, cidFromBytes } from './common.js';
1516

1617
async function authorizeAccount(api, pair, who, transactions, bytes) {
1718
const tx = api.tx.transactionStorage.authorizeAccount(who, transactions, bytes);
@@ -22,20 +23,14 @@ async function authorizeAccount(api, pair, who, transactions, bytes) {
2223

2324
async function store(api, pair, data) {
2425
console.log('Storing data:', data);
25-
26-
// 1️⃣ Hash the data using blake2b-256
27-
const hash = blake2AsU8a(data)
28-
// 2️⃣ Wrap the hash as a multihash
29-
const mh = multihash.create(0xb220, hash); // 0xb220 = blake2b-256
30-
// 3️⃣ Generate CID (CIDv1, raw codec)
31-
const cid = CID.createV1(0x55, mh); // 0x55 = raw codec
26+
const cid = cidFromBytes(data);
3227

3328
const tx = api.tx.transactionStorage.store(data);
3429
const result = await tx.signAndSend(pair);
3530
console.log('Transaction store result:', result.toHuman());
36-
return cid
31+
32+
return cid;
3733
}
38-
3934
// Connect to a local IPFS gateway (e.g. Kubo)
4035
const ipfs = create({
4136
url: 'http://127.0.0.1:5001', // Local IPFS API
@@ -44,7 +39,7 @@ const ipfs = create({
4439
async function read_from_ipfs(cid) {
4540
// Fetch the block (downloads via Bitswap if not local)
4641
console.log('Trying to get cid: ', cid);
47-
const block = await ipfs.block.get(cid);
42+
const block = await ipfs.block.get(cid, {timeout: 10000});
4843
console.log('Received block: ', block);
4944
if (block.length !== 0) {
5045
return block
@@ -79,13 +74,13 @@ async function main() {
7974

8075
console.log('Doing authorization...');
8176
await authorizeAccount(api, sudo_pair, who, transactions, bytes);
82-
await new Promise(resolve => setTimeout(resolve, 8000));
77+
await waitForNewBlock();
8378
console.log('Authorized!');
8479

85-
console.log('Storing data...');
80+
console.log('Storing data ...');
8681
let cid = await store(api, who_pair, "Hello, Bulletin remote3 - " + new Date().toString());
8782
console.log('Stored data with CID: ', cid);
88-
await new Promise(resolve => setTimeout(resolve, 5000));
83+
await waitForNewBlock();
8984

9085
console.log('Reading content... cid: ', cid);
9186
let content = await read_from_ipfs(cid);

examples/common.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { blake2AsU8a } from '@polkadot/util-crypto'
2+
import * as multihash from 'multiformats/hashes/digest'
3+
import { CID } from 'multiformats/cid'
4+
5+
export async function waitForNewBlock() {
6+
// TODO: wait for a new block.
7+
console.log('🛰 Waiting for new block...')
8+
return new Promise(resolve => setTimeout(resolve, 7000))
9+
}
10+
11+
/**
12+
* helper: create CID for raw data
13+
*/
14+
export function cidFromBytes(bytes) {
15+
const hash = blake2AsU8a(bytes)
16+
// 0xb2 = the multihash algorithm family for BLAKE2b
17+
// 0x20 = the digest length in bytes (32 bytes = 256 bits)
18+
const mh = multihash.create(0xb220, hash)
19+
return CID.createV1(0x55, mh) // 0x55 = raw
20+
}

examples/store_chunked_data.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as sha256 from 'multiformats/hashes/sha2';
1010
import { UnixFS } from 'ipfs-unixfs'
1111
import { TextDecoder } from 'util'
1212
import assert from "assert";
13+
import { waitForNewBlock, cidFromBytes } from './common.js'
1314

1415
// ---- CONFIG ----
1516
const WS_ENDPOINT = 'ws://127.0.0.1:10000' // Bulletin node
@@ -32,15 +33,6 @@ async function authorizeAccount(api, pair, who, transactions, bytes, nonceMgr) {
3233
console.log('Transaction authorizeAccount result:', result.toHuman());
3334
}
3435

35-
/**
36-
* helper: create CID for raw data
37-
*/
38-
function cidFromBytes(bytes) {
39-
const hash = blake2AsU8a(bytes)
40-
const mh = multihash.create(0xb220, hash)
41-
return CID.createV1(0x55, mh) // 0x55 = raw
42-
}
43-
4436
/**
4537
* Read the file, chunk it, store in Bulletin and return CIDs.
4638
* Returns { chunks }
@@ -293,12 +285,6 @@ async function authorizeStorage(api, sudoPair, pair, nonceMgr) {
293285
await waitForNewBlock();
294286
}
295287

296-
async function waitForNewBlock() {
297-
// TODO: wait for a new block.
298-
console.log('🛰 Waiting for new block...')
299-
return new Promise(resolve => setTimeout(resolve, 7000))
300-
}
301-
302288
async function main() {
303289
await cryptoWaitReady()
304290
if (fs.existsSync(OUT_PATH)) {

0 commit comments

Comments
 (0)