Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
127abe3
added relay chainspec to smoldot while using parachain setup
x3c41a Jan 12, 2026
61b1cfd
added retries
x3c41a Jan 12, 2026
fdf53b5
extracted waitForChainReady to common
x3c41a Jan 12, 2026
7f476bf
changed function signature
x3c41a Jan 12, 2026
52a7003
refactor
x3c41a Jan 12, 2026
c70f80b
refactor
x3c41a Jan 12, 2026
7bbf142
Apply suggestions from code review
bkontur Jan 12, 2026
89b2543
Added WebSocket P2P transport support for smoldot client. Configured …
x3c41a Jan 12, 2026
febf06b
fixed formatting
x3c41a Jan 12, 2026
a9e328b
removed lastRuntimeUpgrade
x3c41a Jan 13, 2026
aa1d499
increased smoldot log level
x3c41a Jan 13, 2026
afb4d05
check runtime constants to verify chain is accessibl
x3c41a Jan 13, 2026
f8b807e
changed test order to speed up time to result
x3c41a Jan 13, 2026
72b6e8f
added transaction timeout
x3c41a Jan 13, 2026
daa9723
added transaction index feature
x3c41a Jan 13, 2026
f331210
refactored waitForTransaction
x3c41a Jan 13, 2026
b898eac
Revert "refactored waitForTransaction"
x3c41a Jan 13, 2026
d79ebf8
Reapply "refactored waitForTransaction"
x3c41a Jan 13, 2026
f16cc74
removed westend-spec
x3c41a Jan 13, 2026
1df17b9
revert
x3c41a Jan 13, 2026
2ce5c2b
GitHub-hosted runners that have pre-installed Microsoft repos which s…
x3c41a Jan 13, 2026
dd9dde8
simplified convertBootNode and readChainSpec, refactored code
x3c41a Jan 13, 2026
eb7aad9
refactor log level
x3c41a Jan 13, 2026
51b6165
Update examples/authorize_and_store_papi_smoldot.js
bkontur Jan 13, 2026
36c297d
reverted order back
x3c41a Jan 14, 2026
acdd70d
removed chainspec
x3c41a Jan 14, 2026
cd23abf
simplified westend chain_spec
x3c41a Jan 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ jobs:
just run-authorize-and-store "bulletin-westend-runtime" "smoldot"
- name: Run store chunked data + DAG-PB (PJS-API, RPC node, Westend parachain)
working-directory: examples
# TODO: tmp
continue-on-error: true
run: |
export TEST_DIR="$(mktemp -d $GITHUB_WORKSPACE/bulletin-tests-run-XXXXX)/test"
echo "TEST_DIR=$TEST_DIR" >> "$GITHUB_ENV"
Expand Down
45 changes: 33 additions & 12 deletions examples/authorize_and_store_papi_smoldot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { createClient } from 'polkadot-api';
import { getSmProvider } from 'polkadot-api/sm-provider';
import { cryptoWaitReady } from '@polkadot/util-crypto';
import { authorizeAccount, fetchCid, store } from './api.js';
import { setupKeyringAndSigners } from './common.js';
import { setupKeyringAndSigners, waitForChainReady } from './common.js';
import { cidFromBytes } from "./cid_dag_metadata.js";
import { bulletin } from './.papi/descriptors/dist/index.mjs';

// Constants
const SYNC_WAIT_SEC = 15;
const SYNC_WAIT_SEC = 30; // Increased for parachain sync (relay chain + parachain)
const SMOLDOT_LOG_LEVEL = 3; // 0=off, 1=error, 2=warn, 3=info, 4=debug, 5=trace
const HTTP_IPFS_API = 'http://127.0.0.1:8080' // Local IPFS HTTP gateway

Expand All @@ -33,34 +33,55 @@ function initSmoldot() {
return sd;
}

async function createSmoldotClient(chainspecPath) {
const chainSpec = readChainSpec(chainspecPath);
async function createSmoldotClient(chainSpecPath, parachainSpecPath = null) {
const sd = initSmoldot();
const chain = await sd.addChain({ chainSpec });
const client = createClient(getSmProvider(chain));

const chainSpec = readChainSpec(chainSpecPath);
const mainChain = await sd.addChain({ chainSpec });
console.log(`✅ Added main chain: ${chainSpecPath}`);

if (parachainSpecPath) {
const parachainSpec = readChainSpec(parachainSpecPath);
const parachain = await sd.addChain({
chainSpec: parachainSpec,
potentialRelayChains: [mainChain]
});
console.log(`✅ Added parachain: ${parachainSpecPath}`);
const client = createClient(getSmProvider(parachain));
return { client, sd };
}

const client = createClient(getSmProvider(mainChain));
return { client, sd };
}

async function main() {
await cryptoWaitReady();

// Get chainspec path from command line argument
const chainspecPath = process.argv[2];
if (!chainspecPath) {
console.error('❌ Error: Chainspec path is required as first argument');
console.error('Usage: node authorize_and_store_papi_smoldot.js <chainspec-path>');
// Get chainspec path from command line argument (required - main chain: relay for para, or solo)
const chainSpecPath = process.argv[2];
if (!chainSpecPath) {
console.error('❌ Error: Chain spec path is required as first argument');
console.error('Usage: node authorize_and_store_papi_smoldot.js <chain-spec-path> [parachain-spec-path]');
console.error(' For parachains: <relay-chain-spec-path> <parachain-spec-path>');
console.error(' For solochains: <solo-chain-spec-path>');
process.exit(1);
}

// Optional parachain chainspec path (only needed for parachains)
const parachainSpecPath = process.argv[3] || null;

let sd, client, resultCode;
try {
// Init Smoldot PAPI client and typed api.
({ client, sd } = await createSmoldotClient(chainspecPath));
({ client, sd } = await createSmoldotClient(chainSpecPath, parachainSpecPath));
console.log(`⏭️ Waiting ${SYNC_WAIT_SEC} seconds for smoldot to sync...`);
// TODO: check better way, when smoldot is synced, maybe some RPC/runtime api that checks best vs finalized block?
await new Promise(resolve => setTimeout(resolve, SYNC_WAIT_SEC * 1000));

console.log('🔍 Checking if chain is ready...');
const bulletinAPI = client.getTypedApi(bulletin);
await waitForChainReady(bulletinAPI);

// Signers.
const { sudoSigner, whoSigner, whoAddress } = setupKeyringAndSigners('//Alice', '//Alice');
Expand Down
30 changes: 30 additions & 0 deletions examples/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,33 @@ export class NonceManager {
return current;
}
}

/**
* Wait for a PAPI typed API chain to be ready by checking if we can query chain state.
* Retries until the chain is ready or max retries reached.
*/
export async function waitForChainReady(typedApi, maxRetries = 10, retryDelayMs = 2000) {

for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
// Try multiple queries to ensure chain is fully synced
const [runtimeVersion, blockNumber] = await Promise.all([
typedApi.query.System.LastRuntimeUpgrade(),
typedApi.query.System.Number()
]);

const blockNum = blockNumber ?? 0;
console.log(`✅ Chain is ready! Block #${blockNum}, Runtime: ${runtimeVersion ? 'available' : 'checking...'}`);
return true;
} catch (error) {
if (attempt < maxRetries) {
console.log(`⏳ Chain not ready yet (attempt ${attempt}/${maxRetries}), retrying in ${retryDelayMs/1000}s... Error: ${error.message}`);
await new Promise(resolve => setTimeout(resolve, retryDelayMs));
} else {
console.log(`⚠️ Chain readiness check failed after ${maxRetries} attempts. Proceeding anyway... Error: ${error.message}`);
return false;
}
}
}
return false;
}
9 changes: 6 additions & 3 deletions examples/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,14 @@ run-authorize-and-store runtime mode="ws": npm-install
if [ "{{ mode }}" = "smoldot" ]; then
# Set chainspec path based on runtime
if [ "{{ runtime }}" = "bulletin-westend-runtime" ]; then
CHAINSPEC_PATH="$TEST_DIR/bulletin-westend-collator-1/cfg/westend-local-1006.json"
else # bulletin-polkadot-runtime
# Parachain: relay chain (required) + parachain spec (optional)
RELAY_CHAINSPEC_PATH="$TEST_DIR/bob/cfg/westend-local.json"
PARACHAIN_CHAINSPEC_PATH="$TEST_DIR/bulletin-westend-collator-1/cfg/westend-local-1006.json"
node $SCRIPT_NAME "$RELAY_CHAINSPEC_PATH" "$PARACHAIN_CHAINSPEC_PATH"
else # bulletin-polkadot-runtime (solochain)
CHAINSPEC_PATH="$TEST_DIR/bob/cfg/bulletin-polkadot-local.json"
node $SCRIPT_NAME "$CHAINSPEC_PATH"
fi
node $SCRIPT_NAME "$CHAINSPEC_PATH"
else
node $SCRIPT_NAME
fi
Expand Down
Loading