Skip to content

Commit cb5adad

Browse files
authored
Merge branch 'main' into live_test
2 parents 1fb5f6b + 7ddacd0 commit cb5adad

File tree

3 files changed

+51
-36
lines changed

3 files changed

+51
-36
lines changed
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
Review pull request #$ARGUMENTS
1+
---
2+
name: review
3+
description: Review local changes or a pull request
4+
---
25

3-
Fetch the PR diff and details using `gh pr view` and `gh pr diff`, then analyze for:
6+
If no arguments are passed, review the local changes by looking at the diff between the base branch - main by default - and the current branch.
7+
If arguments are passed, review pull request #$ARGUMENTS by fetching it and seeing its details with `gh pr view` and `gh pr diff`.
8+
9+
When reviewing, analyze for:
410

511
1. **Code Quality**
612
- Rust idioms and Polkadot SDK patterns

.github/workflows/check.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ jobs:
170170
shared-key: "bulletin-cache-benchmarks"
171171
save-if: ${{ github.ref == 'refs/heads/main' }}
172172

173+
- name: Create directory for binary and add to PATH
174+
run: |
175+
mkdir -p $FRAME_OMNI_BENCHER_BIN_DIR
176+
echo "${FRAME_OMNI_BENCHER_BIN_DIR}" >> $GITHUB_PATH
177+
173178
- name: Cache frame-omni-bencher
174179
uses: actions/cache@v5
175180
id: frame-omni-bencher-cache
@@ -180,20 +185,16 @@ jobs:
180185
- name: Download frame-omni-bencher
181186
if: steps.frame-omni-bencher-cache.outputs.cache-hit != 'true'
182187
run: |
183-
mkdir -p $FRAME_OMNI_BENCHER_BIN_DIR
184188
cd $FRAME_OMNI_BENCHER_BIN_DIR
185189
echo "Downloading frame-omni-bencher..."
186190
curl -L -o frame-omni-bencher "https://github.com/paritytech/polkadot-sdk/releases/download/${POLKADOT_SDK_VERSION}/frame-omni-bencher"
187191
chmod +x frame-omni-bencher
188192
./frame-omni-bencher --version
189-
echo "${FRAME_OMNI_BENCHER_BIN_DIR}" >> $GITHUB_PATH
190193
191194
- name: Run benchmarks (Westend parachain)
192195
run: |
193-
echo "Running benchmarks for Westend parachain..."
194196
python3 ./scripts/cmd/cmd.py bench --runtime bulletin-westend --steps 2 --repeat 1
195-
echo "Benchmarks for Westend parachain completed."
196-
197-
echo "Running production check for Westend parachain..."
197+
198+
- name: Run production check for Westend parachain
199+
run: |
198200
cargo check --profile production -p bulletin-westend-runtime
199-
echo "Production check for Westend parachain completed."

examples/store_big_data.js

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -155,57 +155,65 @@ async function printStatistics(dataSize, typedApi) {
155155
const avgTxsPerBlock = totalBlocksInRange > 0 ? (numTxs / totalBlocksInRange).toFixed(2) : 'N/A';
156156

157157
// Fetch block timestamps for all blocks in range
158+
// Query at the last known block to ensure all previous blocks are visible
159+
const lastKnownBlockHash = stats.blockHashes[endBlock];
158160
const blockTimestamps = {};
159161
for (let blockNum = startBlock; blockNum <= endBlock; blockNum++) {
160162
try {
161-
// Get block hash - either from our stored hashes or query the chain
163+
// Get block hash - either from stored or query at last known block
162164
let blockHash = stats.blockHashes[blockNum];
163165
if (!blockHash) {
164-
const queriedHash = await typedApi.query.System.BlockHash.getValue(blockNum);
165-
// Handle different hash formats (string, Binary, Uint8Array)
166-
// PAPI Binary objects have asHex() method, fall back to toString()
167-
const hashStr = typeof queriedHash === 'string'
168-
? queriedHash
169-
: (queriedHash?.asHex?.() || queriedHash?.toHex?.() || queriedHash?.toString?.() || '');
170-
// Check if hash is not empty (all zeros means pruned/unavailable)
171-
if (hashStr && !hashStr.match(/^(0x)?0+$/)) {
172-
blockHash = queriedHash;
173-
}
166+
blockHash = await typedApi.query.System.BlockHash.getValue(blockNum, { at: lastKnownBlockHash });
174167
}
175-
if (blockHash) {
176-
const timestamp = await typedApi.query.Timestamp.Now.getValue({ at: blockHash });
177-
blockTimestamps[blockNum] = timestamp;
168+
// Convert Binary/Uint8Array to hex string for PAPI's at parameter
169+
const blockHashHex = typeof blockHash === 'string'
170+
? blockHash
171+
: (blockHash?.asHex?.() || blockHash?.toHex?.() || '0x' + Buffer.from(blockHash).toString('hex'));
172+
// Skip blocks with zero hash (pruned)
173+
if (blockHashHex.match(/^(0x)?0+$/)) {
174+
continue;
178175
}
176+
const timestamp = await typedApi.query.Timestamp.Now.getValue({ at: blockHashHex });
177+
blockTimestamps[blockNum] = timestamp;
179178
} catch (e) {
180179
console.error(`Failed to fetch timestamp for block #${blockNum}:`, e.message);
181180
}
182181
}
183182

184183
console.log('\n');
185-
console.log('════════════════════════════════════════════════════════════════════════════════════════════════════════');
186-
console.log(' 📊 STORAGE STATISTICS ');
187-
console.log('════════════════════════════════════════════════════════════════════════════════════════════════════════');
184+
// Calculate average block time from timestamps
185+
const startTimestamp = blockTimestamps[startBlock];
186+
const endTimestamp = blockTimestamps[endBlock];
187+
const avgBlockTime = (startTimestamp && endTimestamp && blocksElapsed > 0)
188+
? (Number(endTimestamp) - Number(startTimestamp)) / blocksElapsed
189+
: null;
190+
191+
console.log('════════════════════════════════════════════════════════════════════════════════');
192+
console.log('📊 STORAGE STATISTICS');
193+
console.log('════════════════════════════════════════════════════════════════════════════════');
188194
console.log(`│ File size │ ${formatBytes(dataSize).padEnd(25)} │`);
189195
console.log(`│ Chunk/TX size │ ${formatBytes(CHUNK_SIZE).padEnd(25)} │`);
190196
console.log(`│ Number of chunks │ ${numTxs.toString().padEnd(25)} │`);
191-
console.log(`│ Avg txs per block │ ${`${avgTxsPerBlock} (${numTxs}/${totalBlocksInRange})`.padEnd(25)} │`);
197+
console.log(`│ Avg txs per block │ ${`${avgTxsPerBlock} (${numTxs} txs in #${startBlock} → #${endBlock})`.padEnd(25)} │`);
198+
console.log(`│ Avg block time │ ${(avgBlockTime ? formatDuration(avgBlockTime) : 'N/A').padEnd(25)} │`);
192199
console.log(`│ Time elapsed │ ${formatDuration(elapsed).padEnd(25)} │`);
193200
console.log(`│ Blocks elapsed │ ${`${blocksElapsed} (#${startBlock} → #${endBlock})`.padEnd(25)} │`);
194-
console.log(`│ Throughput │ ${formatBytes(dataSize / (elapsed / 1000)).padEnd(22)} /s │`);
195-
console.log('════════════════════════════════════════════════════════════════════════════════════════════════════════');
196-
console.log(' 📦 TRANSACTIONS PER BLOCK ');
197-
console.log('════════════════════════════════════════════════════════════════════════════════════════════════════════');
198-
console.log('│ Block │ Time │ TXs │ Size │ Bar │');
199-
console.log('├─────────────┼─────────────────────────┼─────┼──────────────┼──────────────────────┤');
201+
console.log(`│ Throughput/sec │ ${(formatBytes(dataSize / (elapsed / 1000)) + '/s').padEnd(25)} │`);
202+
console.log(`│ Throughput/block │ ${(formatBytes(dataSize / totalBlocksInRange) + '/block').padEnd(25)} │`);
203+
console.log('════════════════════════════════════════════════════════════════════════════════');
204+
console.log('📦 TRANSACTIONS PER BLOCK');
205+
console.log('════════════════════════════════════════════════════════════════════════════════');
206+
console.log('│ Block │ Time │ TXs │ Size │ Bar │');
207+
console.log('├─────────────┼─────────────────────┼─────┼──────────────┼──────────────────────┤');
200208
for (let blockNum = startBlock; blockNum <= endBlock; blockNum++) {
201209
const count = txsPerBlock[blockNum] || 0;
202210
const size = count > 0 ? formatBytes(count * CHUNK_SIZE) : '-';
203211
const bar = count > 0 ? '█'.repeat(Math.min(count, 20)) : '';
204212
const timestamp = blockTimestamps[blockNum];
205-
const timeStr = timestamp ? new Date(Number(timestamp)).toISOString().replace('T', ' ').replace('Z', '') : '-';
206-
console.log(`│ #${blockNum.toString().padEnd(10)}${timeStr.padEnd(23)}${count.toString().padStart(3)}${size.padEnd(12)}${bar.padEnd(20)} │`);
213+
const timeStr = timestamp ? new Date(Number(timestamp)).toISOString().replace('T', ' ').slice(0, 19) : '-';
214+
console.log(`│ #${blockNum.toString().padEnd(10)}${timeStr.padEnd(19)}${count.toString().padStart(3)}${size.padEnd(12)}${bar.padEnd(20)} │`);
207215
}
208-
console.log('════════════════════════════════════════════════════════════════════════════════════════════════════════');
216+
console.log('════════════════════════════════════════════════════════════════════════════════');
209217
console.log('\n');
210218
}
211219

0 commit comments

Comments
 (0)